From 207238773b04cf74d68ab8bc8902d635b08ed40a Mon Sep 17 00:00:00 2001 From: joseph-sentry Date: Thu, 1 May 2025 14:59:39 -0400 Subject: [PATCH 1/2] fix: handle merge_group github events if we get a branch with gh-readonly-queue, it comes from a merge queue and the actual branch name is located in the middle --- .../helpers/ci_adapters/github_actions.py | 22 +++++++++---------- .../tests/ci_adapters/test_ghactions.py | 6 +++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/codecov-cli/codecov_cli/helpers/ci_adapters/github_actions.py b/codecov-cli/codecov_cli/helpers/ci_adapters/github_actions.py index f12d2105..74f3f009 100644 --- a/codecov-cli/codecov_cli/helpers/ci_adapters/github_actions.py +++ b/codecov-cli/codecov_cli/helpers/ci_adapters/github_actions.py @@ -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//- + if branch.startswith("gh-readonly-queue/"): + return branch.split("/")[1] - branch = match.group(1) return branch or None def _get_service(self): diff --git a/codecov-cli/tests/ci_adapters/test_ghactions.py b/codecov-cli/tests/ci_adapters/test_ghactions.py index 5d7efb44..de9d431b 100644 --- a/codecov-cli/tests/ci_adapters/test_ghactions.py +++ b/codecov-cli/tests/ci_adapters/test_ghactions.py @@ -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): From caae414dbaf8576ffa3852f5319e53a5b757b7e3 Mon Sep 17 00:00:00 2001 From: joseph-sentry Date: Fri, 2 May 2025 10:56:32 -0400 Subject: [PATCH 2/2] fix: match previous logic --- codecov-cli/codecov_cli/helpers/ci_adapters/github_actions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codecov-cli/codecov_cli/helpers/ci_adapters/github_actions.py b/codecov-cli/codecov_cli/helpers/ci_adapters/github_actions.py index 74f3f009..8630c81f 100644 --- a/codecov-cli/codecov_cli/helpers/ci_adapters/github_actions.py +++ b/codecov-cli/codecov_cli/helpers/ci_adapters/github_actions.py @@ -66,10 +66,10 @@ def _get_slug(self): return os.getenv("GITHUB_REPOSITORY") def _get_branch(self): - def remove_prefix(s, prefix): + def remove_prefix(s: str, prefix: str) -> str: if s.startswith(prefix): return s[len(prefix) :] - return s + return "" head_ref = os.getenv("GITHUB_HEAD_REF", "") ref = remove_prefix(os.getenv("GITHUB_REF", ""), "refs/heads/")