Skip to content

Commit

Permalink
taking decoding slug out of is_fork_pr, cause it doesn't feel right t…
Browse files Browse the repository at this point in the history
…o be there
  • Loading branch information
dana-yaish committed Nov 8, 2023
1 parent 85d7c67 commit 0dfd717
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
7 changes: 5 additions & 2 deletions codecov_cli/helpers/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ def parse_git_service(remote_repo_url: str):


def is_fork_pr(pr_num, slug, service):
decoded_slug = decode_slug(slug)
"""
takes in pull request number, slug in the owner/repo format, and the git service e.g. github, gitlab etc.
returns true if PR is made in a fork context, false if not.
"""
git_service = get_git_service(service)
if git_service:
pull_dict = git_service.get_pull_request(decoded_slug, pr_num)
pull_dict = git_service.get_pull_request(slug, pr_num)
if pull_dict and pull_dict["head"]["slug"] != pull_dict["base"]["slug"]:
return True
return False
5 changes: 3 additions & 2 deletions codecov_cli/services/commit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid

from codecov_cli.helpers.config import CODECOV_API_URL
from codecov_cli.helpers.encoder import encode_slug
from codecov_cli.helpers.encoder import decode_slug, encode_slug
from codecov_cli.helpers.git import is_fork_pr
from codecov_cli.helpers.request import (
get_token_header_or_fail,
Expand Down Expand Up @@ -50,9 +50,10 @@ def send_commit_data(
"pullid": pr,
"branch": branch,
}
decoded_slug = decode_slug(slug)
headers = (
{}
if not token and is_fork_pr(pr, slug, service)
if not token and is_fork_pr(pr, decoded_slug, service)
else get_token_header_or_fail(token)
)
upload_url = enterprise_url or CODECOV_API_URL
Expand Down
7 changes: 6 additions & 1 deletion codecov_cli/services/upload/upload_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from codecov_cli import __version__ as codecov_cli_version
from codecov_cli.helpers.config import CODECOV_API_URL
from codecov_cli.helpers.encoder import encode_slug
from codecov_cli.helpers.git import is_fork_pr
from codecov_cli.helpers.request import (
get_token_header_or_fail,
send_post_request,
Expand Down Expand Up @@ -53,7 +54,11 @@ def send_upload_data(
}

# Data to upload to Codecov
headers = get_token_header_or_fail(token)
headers = (
{}
if not token and is_fork_pr(pull_request_number, slug, git_service)
else get_token_header_or_fail(token)
)
encoded_slug = encode_slug(slug)
upload_url = enterprise_url or CODECOV_API_URL
url = f"{upload_url}/upload/{git_service}/{encoded_slug}/commits/{commit_sha}/reports/{report_code}/uploads"
Expand Down
4 changes: 2 additions & 2 deletions tests/services/commit/test_commit_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_commit_sender_200(mocker):
)
token = uuid.uuid4()
res = send_commit_data(
"commit_sha", "parent_sha", "pr", "branch", "slug", token, "service", None
"commit_sha", "parent_sha", "pr", "branch", "owner::::repo", token, "service", None
)
assert res.error is None
assert res.warnings == []
Expand All @@ -117,7 +117,7 @@ def test_commit_sender_403(mocker):
)
token = uuid.uuid4()
res = send_commit_data(
"commit_sha", "parent_sha", "pr", "branch", "slug", token, "service", None
"commit_sha", "parent_sha", "pr", "branch", "owner::::repo", token, "service", None
)
assert res.error == RequestError(
code="HTTP Error 403",
Expand Down

0 comments on commit 0dfd717

Please sign in to comment.