Skip to content

Commit db39587

Browse files
committed
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
1 parent 1c24461 commit db39587

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

codecov_cli/helpers/ci_adapters/github_actions.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,21 @@ def _get_slug(self):
6666
return os.getenv("GITHUB_REPOSITORY")
6767

6868
def _get_branch(self):
69-
branch = os.getenv("GITHUB_HEAD_REF")
70-
if branch:
71-
return branch
69+
def remove_prefix(s, prefix):
70+
if s.startswith(prefix):
71+
return s[len(prefix) :]
72+
return s
7273

73-
branch_ref = os.getenv("GITHUB_REF")
74+
head_ref = os.getenv("GITHUB_HEAD_REF", "")
75+
ref = remove_prefix(os.getenv("GITHUB_REF", ""), "refs/heads/")
7476

75-
if not branch_ref:
76-
return None
77-
78-
match = re.search(r"refs/heads/(.*)", branch_ref)
77+
branch = head_ref or ref
7978

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

83-
branch = match.group(1)
8484
return branch or None
8585

8686
def _get_service(self):

tests/ci_adapters/test_ghactions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ def test_slug(self, env_dict, expected, mocker):
207207
({GithubActionsEnvEnum.GITHUB_REF: r"doesn't_match"}, None),
208208
({GithubActionsEnvEnum.GITHUB_REF: r"refs/heads/"}, None),
209209
({GithubActionsEnvEnum.GITHUB_REF: r"refs/heads/abc"}, "abc"),
210+
(
211+
{
212+
GithubActionsEnvEnum.GITHUB_REF: r"refs/heads/gh-readonly-queue/abc/pr-name-number"
213+
},
214+
"abc",
215+
),
210216
],
211217
)
212218
def test_branch(self, env_dict, expected, mocker):

0 commit comments

Comments
 (0)