From 593cbd0b7f0dd1c8fb317c8ee402e64d6d63964d Mon Sep 17 00:00:00 2001 From: Olla Gabriele Date: Thu, 6 Jun 2024 12:53:27 +0200 Subject: [PATCH 1/3] improves github ref check Signed-off-by: Olla Gabriele --- coverage_comment/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From a5d1c8e88ba860a34ae75dfc04c753fb3aae37ed Mon Sep 17 00:00:00 2001 From: Olla Gabriele Date: Thu, 6 Jun 2024 20:24:41 +0200 Subject: [PATCH 2/3] adds non-regression tests Signed-off-by: Olla Gabriele --- tests/unit/test_settings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_settings.py b/tests/unit/test_settings.py index a335827f..f8c4ff66 100644 --- a/tests/unit/test_settings.py +++ b/tests/unit/test_settings.py @@ -4,7 +4,6 @@ import pathlib import pytest - from coverage_comment import settings @@ -127,6 +126,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 +139,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"), ], ) From 49b1a75902ebedcb30f7034a4f90077c3c6d80b6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Jun 2024 18:25:11 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/test_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_settings.py b/tests/unit/test_settings.py index f8c4ff66..b283d991 100644 --- a/tests/unit/test_settings.py +++ b/tests/unit/test_settings.py @@ -4,6 +4,7 @@ import pathlib import pytest + from coverage_comment import settings