Skip to content

Instantly share code, notes, and snippets.

@tmr232
Created February 23, 2024 14:26
Show Gist options
  • Save tmr232/98c03dde8821facf3989365a98e18c1c to your computer and use it in GitHub Desktop.
Save tmr232/98c03dde8821facf3989365a98e18c1c to your computer and use it in GitHub Desktop.
Check which of your GH fork repos have no changes compared to the source repos
import github.GithubException
import keyring
from github import Github
from github import Repository
from github import Auth
import rich
GITHUB_TOKEN = keyring.get_password("github.com", "repo-diff")
def has_private_changes(fork:Repository):
source = fork.source
if source is None:
raise RuntimeError()
for branch in fork.get_branches():
default_branch = source.default_branch
head_branch = f"{fork.owner.login}:{branch.name}"
diff = source.compare(default_branch, head_branch)
if diff.ahead_by > 0:
return True
return False
def main():
auth = Auth.Token(GITHUB_TOKEN)
g = Github(auth=auth)
user = g.get_user("tmr232")
forked_repos = user.get_repos(type="forks")
for repo in forked_repos:
if not repo.fork:
continue
try:
if has_private_changes(repo):
continue
except github.GithubException:
print("Comparison failed for", repo.html_url)
rich.print(repo.html_url,repo.last_modified, repo.description, )
# break
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment