(url: str, user_agent: str)
| 8 | |
| 9 | |
| 10 | def github_request(url: str, user_agent: str) -> bytes: |
| 11 | headers = {"User-Agent": user_agent} |
| 12 | token = os.environ.get("GITHUB_TOKEN") or os.environ.get("GH_TOKEN") |
| 13 | if token: |
| 14 | headers["Authorization"] = f"token {token}" |
| 15 | req = urllib.request.Request(url, headers=headers) |
| 16 | with urllib.request.urlopen(req) as resp: |
| 17 | return resp.read() |
| 18 | |
| 19 | |
| 20 | def github_api_contents_url(repo: str, path: str, ref: str) -> str: |