Skip to content

Commit

Permalink
fix: exception if PR is from same repo
Browse files Browse the repository at this point in the history
If a PR exists and base and head are from the same repo it seems that
the response["head"]["repo"] is set to None, causing exception when
the code runs.

This fixes that bug so that the CLI can fail gracefully (if a token
is not provided)
  • Loading branch information
giovanni-guidini committed Dec 15, 2023
1 parent 8fbd52e commit f4b31f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion codecov_cli/helpers/git_services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def get_pull_request(self, slug, pr_number) -> PullDict:
"sha": res["head"]["sha"],
"label": res["head"]["label"],
"ref": res["head"]["ref"],
"slug": res["head"]["repo"]["full_name"],
# 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": res["head"]["repo"]["full_name"]
if res["head"]["repo"]
else res["base"]["repo"]["full_name"],
},
"base": {
"sha": res["base"]["sha"],
Expand Down
2 changes: 1 addition & 1 deletion codecov_cli/services/commit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from codecov_cli.helpers.config import CODECOV_API_URL
from codecov_cli.helpers.encoder import decode_slug, encode_slug
from codecov_cli.helpers.git import get_git_service, get_pull, is_fork_pr
from codecov_cli.helpers.git import get_pull, is_fork_pr
from codecov_cli.helpers.request import (
get_token_header_or_fail,
log_warnings_and_errors_if_any,
Expand Down

0 comments on commit f4b31f1

Please sign in to comment.