Skip to content

Commit

Permalink
update code for >100 contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
kandersolar committed Oct 27, 2023
1 parent 3f85bb8 commit 897e930
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions sphinx/source/project/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def _fetch_gh_api(repo, page=None):
url = f'https://api.github.com/repos/{repo}/stargazers'
if page is not None:
url += f"?page={page}"
#print(url)
# necessary to get starred_at data:
headers = {'Accept': 'application/vnd.github.v3.star+json'}
response = requests.get(url, headers=headers, auth=auth)
Expand Down Expand Up @@ -108,14 +107,21 @@ def plot_github_stars_timeseries(gh):


def get_github_contributors(repo):
url = f"https://api.github.com/repos/{repo}/contributors?per_page=100"
headers = {'Accept': 'application/vnd.github+json'}
auth = (user, token)
response = requests.get(url, headers=headers, auth=auth)
contributor_data = response.json()
page_number = 1
contributor_data = []

while True:
url = f"https://api.github.com/repos/{repo}/contributors?per_page=100&page={page_number}"
response = requests.get(url, headers=headers, auth=auth)
chunk = response.json()
contributor_data.extend(chunk)

if len(chunk) < 100:
break

if len(contributor_data) == 100:
raise ValueError("You need to generalize this code to handle multiple pages")
page_number += 1

return contributor_data

Expand Down

0 comments on commit 897e930

Please sign in to comment.