Skip to content

CI/WEB: Use Github token to authenticate API calls #50388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/docbuild-and-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
env:
ENV_FILE: environment.yml
PANDAS_CI: 1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

permissions:
contents: read
Expand Down
18 changes: 15 additions & 3 deletions web/pandas_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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:
"""
Expand Down Expand Up @@ -166,7 +172,9 @@ def maintainers_add_info(context):
for kind in ("active", "inactive"):
context["maintainers"][f"{kind}_with_github_info"] = []
for user in context["maintainers"][kind]:
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 context["ignore_io_errors"] and resp.status_code == 403:
return context
resp.raise_for_status()
Expand All @@ -178,7 +186,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 context["ignore_io_errors"] and resp.status_code == 403:
return context
resp.raise_for_status()
Expand Down Expand Up @@ -245,7 +256,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 context["ignore_io_errors"] and resp.status_code == 403:
return context
Expand Down