Skip to content

Commit ddde1dd

Browse files
authored
CI/WEB: Use Github token to authenticate API calls (#50388)
1 parent af9b72a commit ddde1dd

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.github/workflows/docbuild-and-upload.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515
env:
1616
ENV_FILE: environment.yml
1717
PANDAS_CI: 1
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1819

1920
permissions:
2021
contents: read

web/pandas_web.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
import requests
4343
import yaml
4444

45+
api_token = os.environ.get("GITHUB_TOKEN")
46+
if api_token is not None:
47+
GITHUB_API_HEADERS = {"Authorization": f"Bearer {api_token}"}
48+
else:
49+
GITHUB_API_HEADERS = {}
50+
4551

4652
class Preprocessors:
4753
"""
@@ -166,7 +172,9 @@ def maintainers_add_info(context):
166172
for kind in ("active", "inactive"):
167173
context["maintainers"][f"{kind}_with_github_info"] = []
168174
for user in context["maintainers"][kind]:
169-
resp = requests.get(f"https://api.github.com/users/{user}")
175+
resp = requests.get(
176+
f"https://api.github.com/users/{user}", headers=GITHUB_API_HEADERS
177+
)
170178
if context["ignore_io_errors"] and resp.status_code == 403:
171179
return context
172180
resp.raise_for_status()
@@ -178,7 +186,10 @@ def home_add_releases(context):
178186
context["releases"] = []
179187

180188
github_repo_url = context["main"]["github_repo_url"]
181-
resp = requests.get(f"https://api.github.com/repos/{github_repo_url}/releases")
189+
resp = requests.get(
190+
f"https://api.github.com/repos/{github_repo_url}/releases",
191+
headers=GITHUB_API_HEADERS,
192+
)
182193
if context["ignore_io_errors"] and resp.status_code == 403:
183194
return context
184195
resp.raise_for_status()
@@ -245,7 +256,8 @@ def roadmap_pdeps(context):
245256
github_repo_url = context["main"]["github_repo_url"]
246257
resp = requests.get(
247258
"https://api.github.com/search/issues?"
248-
f"q=is:pr is:open label:PDEP repo:{github_repo_url}"
259+
f"q=is:pr is:open label:PDEP repo:{github_repo_url}",
260+
headers=GITHUB_API_HEADERS,
249261
)
250262
if context["ignore_io_errors"] and resp.status_code == 403:
251263
return context

0 commit comments

Comments
 (0)