INNER CODE UNIT · Python
_request
RockxyApp/Rockxy · .github/tools/cla_gate.py:48
def _request(self, method: str, path: str, payload: dict | None = None) -> tuple[int, dict | list | None]:
url = path if path.startswith("http") else f"{self._api_url}{path}"
data = json.dumps(payload).encode("utf-8") if payload is not None else None
request = urllib.request.Request(url, data=data, method=method)
request.add_header("Authorization", f"Bearer {self._token}")
request.add_header("Accept", "application/vnd.github+json")
request.add_header("X-GitHub-Api-Version", "2022-11-28")
request.add_header("User-Agent", "rockxy-cla-gate")
if data is not None:
request.add_header("Content-Type", "application/json")
try:
with urllib.request.urlopen(request) as response:
body = response.read()
parsed = json.loads(body) if body else None
return response.status, parsed
except urllib.error.HTTPError as error:
body = error.read()
try: