python-3.xgithubpygithub

How to check if public git repository is updated?


I would like to know how can one check that public git repository is updated or not (if their are new commits) using python. Help in this regard would be appreciated.


Solution

  • PyGitHub is great for this, you can do something like:

    
    for repo in g.get_organization(ORGANIZATION).get_repos():
            print(f"Processing {repo.full_name}...")
            commit_activity = repo.get_stats_commit_activity()
    
            # We have 52 weeks of commit history to total up
            annual_commits = 0
            for week in commit_activity:
                annual_commits += week.total
    
            print(f"Totalled {annual_commits} commits.")
    

    https://pygithub.readthedocs.io/en/latest/github_objects/Repository.html#github.Repository.Repository.get_stats_commit_activity