MCPcopy
hub / github.com/django/django / github_request

Function github_request

scripts/pr_quality/check_pr.py:89–107  ·  view source on GitHub ↗

Make an authenticated GitHub API request.

(method, path, token, repo, data=None, params=None)

Source from the content-addressed store, hash-verified

87
88
89def 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
110def get_recent_commit_count(pr_author, repo, token, since_days, max_count):

Callers 4

get_recent_commit_countFunction · 0.85
get_pr_total_changesFunction · 0.85
mainFunction · 0.85

Calls 6

urlencodeMethod · 0.80
encodeMethod · 0.45
dumpsMethod · 0.45
urlopenMethod · 0.45
loadsMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected