Skip to content

Commit

Permalink
Mkerge branch 'main' of https://github.com/codecov/shared into 1256-m…
Browse files Browse the repository at this point in the history
…ove-api-models-to-shared
  • Loading branch information
adrian-codecov committed Apr 5, 2024
2 parents c607c86 + db61cbc commit 23e9a9a
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions shared/torngit/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ async def api(self, *args, token=None, **kwargs):
"""
token_to_use = token or self.token

log.info(
"Making Github API call",
extra=dict(
has_token=bool(token),
has_self_token=bool(self.token),
is_same_token=(token == self.token),
),
)

if not token_to_use:
raise TorngitMisconfiguredCredentials()
response = await self.make_http_call(*args, token_to_use=token_to_use, **kwargs)
Expand Down Expand Up @@ -301,9 +310,9 @@ async def make_http_call(
current_retry=current_retry,
time_taken=timer.ms,
body=logged_body,
rlx=res.headers.get("X-RateLimit-Remaining"),
rly=res.headers.get("X-RateLimit-Limit"),
rlr=res.headers.get("X-RateLimit-Reset"),
rl_remaining=res.headers.get("X-RateLimit-Remaining"),
rl_limit=res.headers.get("X-RateLimit-Limit"),
rl_reset_time=res.headers.get("X-RateLimit-Reset"),
retry_after=res.headers.get("Retry-After"),
**log_dict,
),
Expand Down Expand Up @@ -641,7 +650,18 @@ async def _fetch_page_of_repos_using_installation(
headers={"Accept": "application/vnd.github.machine-man-preview+json"},
)

return self._process_repository_page(res.get("repositories", []))
repos = res.get("repositories", [])

log.info(
"Fetched page of repos using installation",
extra=dict(
page_size=page_size,
page=page,
repo_names=[repo["name"] for repo in repos] if len(repos) > 0 else [],
),
)

return self._process_repository_page(repos)

async def _fetch_page_of_repos(
self, client, username, token, page_size=100, page=0
Expand All @@ -662,6 +682,16 @@ async def _fetch_page_of_repos(
token=token,
)

log.info(
"Fetched page of repos",
extra=dict(
page_size=page_size,
page=page,
repo_names=[repo["name"] for repo in repos] if len(repos) > 0 else [],
username=username,
),
)

return self._process_repository_page(repos)

async def _fetch_number_of_repos(self, client, token):
Expand Down Expand Up @@ -732,9 +762,9 @@ async def get_repos_from_nodeids_generator(
primary_language.get("name") if primary_language else None
),
"private": raw_repo_data["isPrivate"],
"branch": default_branch.get("name")
if default_branch
else None,
"branch": (
default_branch.get("name") if default_branch else None
),
"owner": {
"node_id": raw_repo_data["owner"]["id"],
"username": raw_repo_data["owner"]["login"],
Expand Down Expand Up @@ -1239,11 +1269,11 @@ async def get_compare(
% (
f.get("previous_filename") or f.get("filename"),
f.get("filename"),
"\ndeleted file mode 100644"
if f["status"] == "removed"
else "\nnew file mode 100644"
if f["status"] == "added"
else "",
(
"\ndeleted file mode 100644"
if f["status"] == "removed"
else "\nnew file mode 100644" if f["status"] == "added" else ""
),
"--- "
+ (
"/dev/null"
Expand Down Expand Up @@ -1359,9 +1389,11 @@ def _pull(self, pull):
commitid=pull["head"]["sha"],
# Through empiric test data it seems that the "repo" key in "head" is set to None
# If the PR is from the same repo (e.g. not from a fork)
slug=pull["head"]["repo"]["full_name"]
if pull["head"]["repo"]
else pull["base"]["repo"]["full_name"],
slug=(
pull["head"]["repo"]["full_name"]
if pull["head"]["repo"]
else pull["base"]["repo"]["full_name"]
),
),
state="merged" if pull["merged"] else pull["state"],
title=pull["title"],
Expand Down

0 comments on commit 23e9a9a

Please sign in to comment.