From da0f4cd100ef87a7e9e96fcbc6d0d0fedf5fe0fe Mon Sep 17 00:00:00 2001 From: Michael Sauter Date: Fri, 17 Nov 2023 15:30:07 +0100 Subject: [PATCH] Special case single star branch/tag constraint If the constraint is e.g. `branches: ["*"]`, then all branch names are matched, even ones containing slashes. Before this change, e.g. `feature/foo` would not have matched. --- internal/manager/receive.go | 6 ++++++ internal/manager/receive_test.go | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/internal/manager/receive.go b/internal/manager/receive.go index 287af286..7135cd9b 100644 --- a/internal/manager/receive.go +++ b/internal/manager/receive.go @@ -223,6 +223,12 @@ func anyPatternMatches(s string, patterns []string) bool { return true } + // Treat a single star as a special case, matching everything. + // See https://github.com/opendevstack/ods-pipeline/issues/691 + if patterns[0] == "*" { + return true + } + for _, pattern := range patterns { if matched, err := path.Match(pattern, s); matched && err == nil { return true diff --git a/internal/manager/receive_test.go b/internal/manager/receive_test.go index 1b161dd8..1ab1410a 100644 --- a/internal/manager/receive_test.go +++ b/internal/manager/receive_test.go @@ -450,6 +450,18 @@ func TestIdentifyPipelineConfig(t *testing.T) { wantPipelineIndex: 0, wantTriggerIndex: 0, }, + "branch push - pipeline with one trigger with * constraint": { + pInfo: PipelineInfo{ChangeRefType: "BRANCH", GitRef: "feature/foo"}, + odsConfig: config.ODS{ + Pipelines: []config.Pipeline{ + {Triggers: []config.Trigger{ + {Branches: []string{"*"}}, + }}, + }, + }, + wantPipelineIndex: 0, + wantTriggerIndex: 0, + }, "branch push - pipeline with one trigger with matching branch constraint upper case": { pInfo: PipelineInfo{ChangeRefType: "BRANCH", GitRef: "feature/FOO-123-hello-world"}, odsConfig: config.ODS{