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 all commits
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
23 changes: 11 additions & 12 deletions codecov_cli/helpers/ci_adapters/github_actions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import re
import subprocess

from codecov_cli.helpers.ci_adapters.base import CIAdapterBase


Expand Down Expand Up @@ -66,21 +65,21 @@ def _get_slug(self):
return os.getenv("GITHUB_REPOSITORY")

def _get_branch(self):
branch = os.getenv("GITHUB_HEAD_REF")
if branch:
return branch

branch_ref = os.getenv("GITHUB_REF")
def remove_prefix(s: str, prefix: str) -> str:
if s.startswith(prefix):
return s[len(prefix) :]
return ""

if not branch_ref:
return None
head_ref = os.getenv("GITHUB_HEAD_REF", "")
ref = remove_prefix(os.getenv("GITHUB_REF", ""), "refs/heads/")

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