diff --git a/coverage_comment/settings.py b/coverage_comment/settings.py index ed0c27c1..5d4360b7 100644 --- a/coverage_comment/settings.py +++ b/coverage_comment/settings.py @@ -125,14 +125,14 @@ def clean_github_output(cls, value: str) -> pathlib.Path: @property def GITHUB_PR_NUMBER(self) -> int | None: # "refs/pull/2/merge" - if "pull" in self.GITHUB_REF: + if self.GITHUB_REF.startswith("refs/pull"): return int(self.GITHUB_REF.split("/")[2]) return None @property def GITHUB_BRANCH_NAME(self) -> str | None: # "refs/heads/my_branch_name" - if "heads" in self.GITHUB_REF: + if self.GITHUB_REF.startswith("refs/heads"): return self.GITHUB_REF.split("/", 2)[2] return None diff --git a/tests/unit/test_settings.py b/tests/unit/test_settings.py index a335827f..b283d991 100644 --- a/tests/unit/test_settings.py +++ b/tests/unit/test_settings.py @@ -127,6 +127,8 @@ def _(**kwargs): "github_ref, github_pr_number", [ ("foo", None), + ("refs/heads/branch-with-pull", None), + ("refs/tags/tag-with-pull", None), ("refs/pull/2/merge", 2), ], ) @@ -138,6 +140,8 @@ def test_config__GITHUB_PR_NUMBER(config, github_ref, github_pr_number): "github_ref, github_branch_name", [ ("refs/pull/2/merge", None), + ("refs/pull/2/head", None), + ("refs/tags/tag-with-heads", None), ("refs/heads/a/b", "a/b"), ], )