Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions codecov_cli/helpers/ci_adapters/github_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ def _get_slug(self):
return os.getenv("GITHUB_REPOSITORY")

def _get_branch(self):
branch = os.getenv("GITHUB_HEAD_REF")
if branch:
return branch
def remove_prefix(s, prefix):
if s.startswith(prefix):
return s[len(prefix) :]
return s

branch_ref = os.getenv("GITHUB_REF")
head_ref = os.getenv("GITHUB_HEAD_REF", "")
ref = remove_prefix(os.getenv("GITHUB_REF", ""), "refs/heads/")

if not branch_ref:
return None

match = re.search(r"refs/heads/(.*)", branch_ref)
branch = head_ref or ref

if match is None:
return None
# branch format for merge queue CI runs:
# gh-readonly-queue/<branch-name>/<pr-number>-<pr-name>
if branch.startswith("gh-readonly-queue/"):
return branch.split("/")[1]

branch = match.group(1)
return branch or None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my worry here is if we depend on None to be meaningful versus ''. Previous logic doesn't account for empty string


def _get_service(self):
Expand Down
6 changes: 6 additions & 0 deletions tests/ci_adapters/test_ghactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ def test_slug(self, env_dict, expected, mocker):
({GithubActionsEnvEnum.GITHUB_REF: r"doesn't_match"}, None),
({GithubActionsEnvEnum.GITHUB_REF: r"refs/heads/"}, None),
({GithubActionsEnvEnum.GITHUB_REF: r"refs/heads/abc"}, "abc"),
(
{
GithubActionsEnvEnum.GITHUB_REF: r"refs/heads/gh-readonly-queue/abc/pr-name-number"
},
"abc",
),
],
)
def test_branch(self, env_dict, expected, mocker):
Expand Down
Loading