Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Finding commits by SHA-1 hash on Github repos forked from a given root repo.
""" Finding commits by SHA-1 hash on Github. This is a simple
brute-force search for a specific usecase: you assume that the commit is
within all repos forked from a certain root repo within the past n days.
This may result in many calls to the GitHub API, which in turn may result
in GitHub's rate limiter kicking in and forcing you to take a break. You
have been warned.
Built with Python 3.4 and 0.9.4.
from datetime import *
from github3 import login
# your personal GitHub access token (needs no special scopes, just reading
# public stuff here), see
access_token = "INSERT_TOKEN_HERE"
sha_hash = "b90b16efe674be681c20f9bca76f82680299db66"
root_repo_owner = "rdpeng"
root_repo_name = "ProgrammingAssignment2"
age_days = 10
created_after = - timedelta(days=age_days)
gh = login(token = access_token)
root_repo = gh.repository(root_repo_owner, root_repo_name)
print("searching repos and commits younger than", created_after)
count = 0
for fork in root_repo.iter_forks():
count = count + 1
if fork.created_at > created_after:
for commit in fork.iter_commits(since=created_after):
if commit.sha == sha_hash:
print("found " + commit.sha + " in " + fork.html_url)
print(count, "repos searched")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.