Make an authenticated GitHub API request.
(method, path, token, repo, data=None, params=None)
| 87 | |
| 88 | |
| 89 | def github_request(method, path, token, repo, data=None, params=None): |
| 90 | """Make an authenticated GitHub API request.""" |
| 91 | url = f"https://api.github.com/repos/{repo}{path}" |
| 92 | if params: |
| 93 | encoded_params = urllib.parse.urlencode(params) |
| 94 | url = f"{url}?{encoded_params}" |
| 95 | headers = { |
| 96 | "Authorization": f"Bearer {token}", |
| 97 | "Accept": "application/vnd.github+json", |
| 98 | "X-GitHub-Api-Version": "2022-11-28", |
| 99 | } |
| 100 | body = None |
| 101 | if data is not None: |
| 102 | body = json.dumps(data).encode() |
| 103 | headers["Content-Type"] = "application/json" |
| 104 | req = urllib.request.Request(url, data=body, headers=headers, method=method) |
| 105 | with urllib.request.urlopen(req, timeout=URLOPEN_TIMEOUT_SECONDS) as response: |
| 106 | if response.status != HTTPStatus.NO_CONTENT: |
| 107 | return json.loads(response.read()) |
| 108 | |
| 109 | |
| 110 | def get_recent_commit_count(pr_author, repo, token, since_days, max_count): |
no test coverage detected