Skip to content

Commit 999bd2a

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 999bd2a

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

codecov_cli/helpers/ci_adapters/github_actions.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,21 @@ def _get_slug(self):
6767

6868
def _get_branch(self):
6969
branch = os.getenv("GITHUB_HEAD_REF")
70-
if branch:
71-
return branch
7270

73-
branch_ref = os.getenv("GITHUB_REF")
71+
if branch is None:
72+
branch = os.getenv("GITHUB_REF")
7473

75-
if not branch_ref:
76-
return None
74+
if branch is None:
75+
return None
7776

78-
match = re.search(r"refs/heads/(.*)", branch_ref)
77+
match = re.search(r"refs/heads/(.*)", branch)
78+
if match is None:
79+
return None
80+
branch = match.group(1)
7981

80-
if match is None:
81-
return None
82+
if branch and branch.startswith("gh-readonly-queue/"):
83+
return branch.split("/")[1]
8284

83-
branch = match.group(1)
8485
return branch or None
8586

8687
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)