Skip to content

Instantly share code, notes, and snippets.

@elemongw
Last active July 22, 2025 06:19
Show Gist options
  • Select an option

  • Save elemongw/fea09b94b2395b15970b3ed2095c38b3 to your computer and use it in GitHub Desktop.

Select an option

Save elemongw/fea09b94b2395b15970b3ed2095c38b3 to your computer and use it in GitHub Desktop.
Find most active forks of a project in GitHub. Sorts by most recently pushed
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Collect all forks of a github project and return the most recently pushed.
Any alternatives I could find searched only the most recent forks of a project,
which does not return accurate results for projects with many forks.
Note that the GitHub API has a rate limit of 60 requests per hour for unauthenticated requests.
You can create a personal access token in order to circumvent this, which will raise the limit
to 5000 requests per hour. This will be enough even for the biggest projects on GitHub.
This code is licensed under the Public Domain
"""
import requests
from sys import argv, exit
BASE_API_URI = "https://api.github.com"
def collect_pages(repo):
parameters = {"per_page": 100}
response = requests.get(
"/".join((BASE_API_URI, "repos", repo, "forks")), parameters
)
response.raise_for_status()
data = response.json()
while "next" in response.links:
response = requests.get(response.links["next"]["url"])
response.raise_for_status()
data.extend(response.json())
return data
def recently_pushed(data):
forks = {}
for fork in data:
forks[fork["pushed_at"]] = fork["html_url"]
return forks
if __name__ == "__main__":
if not len(argv) == 2:
exit("Usage: find_active_fork.py username/repo")
forks = recently_pushed(collect_pages(argv[1]))
for fork in sorted(forks):
date = fork.replace("T", " (").replace("Z", " UTC)")
print(f"{date}: {forks[fork]}")
@QGB
Copy link

QGB commented Dec 17, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment