Skip to content

Instantly share code, notes, and snippets.

@iandesj
Created October 1, 2019 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iandesj/675cf3c13dce6471ffdde09b61039c52 to your computer and use it in GitHub Desktop.
Save iandesj/675cf3c13dce6471ffdde09b61039c52 to your computer and use it in GitHub Desktop.
Just get all branches pushed to all remote repos with me as the committer.
import datetime
from github import Github
g = Github('token')
me = g.get_user()
repos = me.get_repos()
def is_a_repo_contributor(repo):
contributors = repo.get_contributors()
return me.id in map(lambda con: con.id, contributors)
repos_with_me = filter(is_a_repo_contributor, repos)
def is_my_branch(branch):
try:
return me.id == branch.commit.committer.id
except:
return False
class RepoBranches:
def __init__(self, repo, branches):
self.repo = repo
self.branches = branches
my_repo_branch_mappings = []
for repo in repos_with_me:
branches = repo.get_branches()
my_branches = filter(is_my_branch, branches)
my_repo_branch_mappings.append(RepoBranches(repo, my_branches))
class BranchDate:
def __init__(self, branch, last_modified):
self.branch = branch
self.last_modified = last_modified
branch_date_mappings = []
for repo_branch_mapping in my_repo_branch_mappings:
for branch in repo_branch_mapping.branches:
branch_last_modified = datetime.datetime.strptime(branch.commit.last_modified, '%a, %d %b %Y %H:%M:%S %Z')
branch_date_mappings.append(BranchDate(branch, branch_last_modified))
sorted_branch_date_mappings = sorted(branch_date_mappings, key=lambda x: x.last_modified)
for item in sorted_branch_date_mappings[-10:]:
print(item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment