Skip to content

Commit 7360b94

Browse files
committed
Fixed an unhandled exception that showed up in very large repositories; special thanks to Fearcito for reporting it.
1 parent 0f852f1 commit 7360b94

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/gitxray/include/gh_api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os, requests, base64, re, time, urllib
2-
from . import gx_definitions, gx_output
32

43
# GitHub API URL
54
GITHUB_API_BASE_URL = "https://api.github.com"
@@ -83,7 +82,7 @@ def github_request_json(url, params=None, limit_results=None):
8382
message = f"GitHub Rate limit reached. Sleeping for {hours} hours, {minutes} minutes, and {seconds} seconds. You may go and make coffee.."
8483
print(f"\r\n\033[33m{message}\033[0m", flush=True)
8584
if GITHUB_TOKEN == None:
86-
message = f"You should try using a Github Access Token, improves the experience significantly and it's easy!"
85+
message = f"You should try using a GitHub Access Token, improves the experience significantly and it's easy!"
8786
print(f"\033[33m{message}\033[0m", flush=True)
8887
print("For information on how to create a GitHub API Access Token refer to: ")
8988
print("https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens")
@@ -218,7 +217,14 @@ def fetch_repository_branches(repo):
218217
return github_request_json(f"{GITHUB_API_BASE_URL}/repos/{repo.get('full_name')}/branches")
219218

220219
def fetch_repository_contributors(repo):
221-
return github_request_json(repo.get('contributors_url'), {'anon':1})
220+
data = github_request_json(repo.get('contributors_url'), {'anon':1})
221+
# Disregarding if anon is set to 1/True or not, in extremely large repositories, GH returns a 403 status with:
222+
# "The history or contributor list is too large to list contributors for this repository via the API."
223+
if isinstance(data, dict) and data.get("status", "0") == "403":
224+
print(f"\r\n\033[33mGitHub's REST API declined returning the list of Contributors with a message:\033[0m", flush=True)
225+
print(f"\033[33m{data.get('message','')}\033[0m", flush=True)
226+
return {}
227+
return data
222228

223229
def fetch_repository_deployments(repo):
224230
return github_request_json(repo.get('deployments_url'))

0 commit comments

Comments
 (0)