From e75b53a51902da0eda956016abec49de2b828c9f Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 18 Jan 2023 10:45:58 -0800 Subject: [PATCH] WEB/CI: Use GITHUB_TOKEN when making Github API calls --- web/pandas_web.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/web/pandas_web.py b/web/pandas_web.py index e4568136edece..8c508a15f9a2b 100755 --- a/web/pandas_web.py +++ b/web/pandas_web.py @@ -43,6 +43,12 @@ import requests import yaml +api_token = os.environ.get("GITHUB_TOKEN") +if api_token is not None: + GITHUB_API_HEADERS = {"Authorization": f"Bearer {api_token}"} +else: + GITHUB_API_HEADERS = {} + class Preprocessors: """ @@ -168,7 +174,9 @@ def maintainers_add_info(context): for user in ( context["maintainers"]["active"] + context["maintainers"]["inactive"] ): - resp = requests.get(f"https://api.github.com/users/{user}") + resp = requests.get( + f"https://api.github.com/users/{user}", headers=GITHUB_API_HEADERS + ) if resp.status_code == 403: sys.stderr.write( "WARN: GitHub API quota exceeded when fetching maintainers\n" @@ -199,7 +207,10 @@ def home_add_releases(context): context["releases"] = [] github_repo_url = context["main"]["github_repo_url"] - resp = requests.get(f"https://api.github.com/repos/{github_repo_url}/releases") + resp = requests.get( + f"https://api.github.com/repos/{github_repo_url}/releases", + headers=GITHUB_API_HEADERS, + ) if resp.status_code == 403: sys.stderr.write("WARN: GitHub API quota exceeded when fetching releases\n") resp_bkp = requests.get(context["main"]["production_url"] + "releases.json") @@ -275,7 +286,8 @@ def roadmap_pdeps(context): github_repo_url = context["main"]["github_repo_url"] resp = requests.get( "https://api.github.com/search/issues?" - f"q=is:pr is:open label:PDEP repo:{github_repo_url}" + f"q=is:pr is:open label:PDEP repo:{github_repo_url}", + headers=GITHUB_API_HEADERS, ) if resp.status_code == 403: sys.stderr.write("WARN: GitHub API quota exceeded when fetching pdeps\n")