From 6ffcafb77eb00cc7e598509f76ac07e08202a223 Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Wed, 7 Aug 2024 12:56:03 +0200 Subject: [PATCH] Harmonize containing branch matcher for tags Perform a `re.match()` instead of `re.fullmatch()` for the containing branches for tag triggered items. Requiring a full match is unexpected for users. Change-Id: Icd8c258b0dfc36df8c94d9cb5edb3125804b9bc4 --- tests/unit/test_change_matcher.py | 7 +++++++ ...rmonize-containing-branch-matcher-d0ba4ee8881cd3c1.yaml | 6 ++++++ zuul/change_matcher.py | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tools/releasenotes/notes/harmonize-containing-branch-matcher-d0ba4ee8881cd3c1.yaml diff --git a/tests/unit/test_change_matcher.py b/tests/unit/test_change_matcher.py index 3133935769..b41da14231 100644 --- a/tests/unit/test_change_matcher.py +++ b/tests/unit/test_change_matcher.py @@ -71,6 +71,13 @@ class TestBranchMatcher(BaseTestMatcher): self.change.ref = 'baz' self.assertFalse(self.matcher.matches(self.change)) + def test_containing_branch_partial_match(self): + self.change = model.Tag(self.project) + self.change.ref = 'refs/tags/1.0' + self.matcher = cm.BranchMatcher(ZuulRegex('^release-')) + self.change.containing_branches = ["release-1.0", "master"] + self.assertTrue(self.matcher.matches(self.change)) + class TestAbstractMatcherCollection(BaseTestMatcher): diff --git a/tools/releasenotes/notes/harmonize-containing-branch-matcher-d0ba4ee8881cd3c1.yaml b/tools/releasenotes/notes/harmonize-containing-branch-matcher-d0ba4ee8881cd3c1.yaml new file mode 100644 index 0000000000..52ab73aa14 --- /dev/null +++ b/tools/releasenotes/notes/harmonize-containing-branch-matcher-d0ba4ee8881cd3c1.yaml @@ -0,0 +1,6 @@ +--- +upgrade: + - | + The branch matcher for containing branches of a tag will now perform a + normal regex match instead of requiring a full-match. This was done to + harmonize the matching behavior between the different change-types. diff --git a/zuul/change_matcher.py b/zuul/change_matcher.py index fd9ccb3a48..1246ef7b9d 100644 --- a/zuul/change_matcher.py +++ b/zuul/change_matcher.py @@ -88,7 +88,7 @@ class BranchMatcher(AbstractChangeMatcher): if self._regex == branch: return True else: - if self.regex.fullmatch(branch): + if self.regex.match(branch): return True return False