From 71ad1f1d1dab318ffbd4396ee56d7280153e9d9b Mon Sep 17 00:00:00 2001 From: Kyle Weaver Date: Mon, 26 Nov 2018 20:46:58 -0800 Subject: [PATCH] RegexpChangeMatcher: improved naming and comments --- prow/config/branch_protection_test.go | 4 ++-- prow/config/config.go | 10 +++++----- prow/config/jobs.go | 13 +++++++------ prow/config/jobs_test.go | 2 +- prow/jenkins/controller_test.go | 2 +- prow/plank/controller_test.go | 2 +- prow/plugins/skip/skip_test.go | 6 +++--- prow/plugins/trigger/generic-comment_test.go | 18 +++++++++--------- prow/plugins/trigger/push_test.go | 2 +- prow/tide/tide_test.go | 12 ++++++------ 10 files changed, 36 insertions(+), 35 deletions(-) diff --git a/prow/config/branch_protection_test.go b/prow/config/branch_protection_test.go index 3a7fa419eb20..72429d30fe2e 100644 --- a/prow/config/branch_protection_test.go +++ b/prow/config/branch_protection_test.go @@ -308,7 +308,7 @@ func TestJobRequirements(t *testing.T) { }, { Context: "run-if-changed", - ChangeMatcher: ChangeMatcher{ + RegexpChangeMatcher: RegexpChangeMatcher{ RunIfChanged: "foo", }, AlwaysRun: false, @@ -354,7 +354,7 @@ func TestJobRequirements(t *testing.T) { }, { Context: "run-if-changed", - ChangeMatcher: ChangeMatcher{ + RegexpChangeMatcher: RegexpChangeMatcher{ RunIfChanged: "foo", }, SkipReport: true, diff --git a/prow/config/config.go b/prow/config/config.go index 403973c83639..a00aedc326ad 100644 --- a/prow/config/config.go +++ b/prow/config/config.go @@ -1175,11 +1175,11 @@ func SetPresubmitRegexes(js []Presubmit) error { } js[i].Brancher = b - c, err := setChangeRegexes(j.ChangeMatcher) + c, err := setChangeRegexes(j.RegexpChangeMatcher) if err != nil { return fmt.Errorf("could not set change regexes for %s: %v", j.Name, err) } - js[i].ChangeMatcher = c + js[i].RegexpChangeMatcher = c if err := SetPresubmitRegexes(j.RunAfterSuccess); err != nil { return err @@ -1208,7 +1208,7 @@ func setBrancherRegexes(br Brancher) (Brancher, error) { return br, nil } -func setChangeRegexes(cm ChangeMatcher) (ChangeMatcher, error) { +func setChangeRegexes(cm RegexpChangeMatcher) (RegexpChangeMatcher, error) { if cm.RunIfChanged != "" { re, err := regexp.Compile(cm.RunIfChanged) if err != nil { @@ -1228,11 +1228,11 @@ func SetPostsubmitRegexes(ps []Postsubmit) error { return fmt.Errorf("could not set branch regexes for %s: %v", j.Name, err) } ps[i].Brancher = b - c, err := setChangeRegexes(j.ChangeMatcher) + c, err := setChangeRegexes(j.RegexpChangeMatcher) if err != nil { return fmt.Errorf("could not set change regexes for %s: %v", j.Name, err) } - ps[i].ChangeMatcher = c + ps[i].RegexpChangeMatcher = c if err := SetPostsubmitRegexes(j.RunAfterSuccess); err != nil { return err } diff --git a/prow/config/jobs.go b/prow/config/jobs.go index bd9bd929c213..2babb06854a8 100644 --- a/prow/config/jobs.go +++ b/prow/config/jobs.go @@ -134,7 +134,7 @@ type Presubmit struct { Brancher - ChangeMatcher + RegexpChangeMatcher // We'll set these when we load it. re *regexp.Regexp // from Trigger. @@ -144,7 +144,7 @@ type Presubmit struct { type Postsubmit struct { JobBase - ChangeMatcher + RegexpChangeMatcher Brancher @@ -191,9 +191,10 @@ type Brancher struct { reSkip *regexp.Regexp } -// ChangeMatcher is for code shared between jobs that run only when certain files are changed. -type ChangeMatcher struct { - // RunIfChanged automatically run if the PR modifies a file that matches this regex. +// RegexpChangeMatcher is for code shared between jobs that run only when certain files are changed. +type RegexpChangeMatcher struct { + // RunIfChanged defines a regex used to select which subset of file changes should trigger this job. + // If any file in the changeset matches this regex, the job will be triggered RunIfChanged string `json:"run_if_changed,omitempty"` reChanges *regexp.Regexp // from RunIfChanged } @@ -246,7 +247,7 @@ func (br Brancher) Intersects(other Brancher) bool { } // RunsAgainstChanges returns true if any of the changed input paths match the run_if_changed regex. -func (cm ChangeMatcher) RunsAgainstChanges(changes []string) bool { +func (cm RegexpChangeMatcher) RunsAgainstChanges(changes []string) bool { if cm.RunIfChanged == "" { return true } diff --git a/prow/config/jobs_test.go b/prow/config/jobs_test.go index 910ac94a7cab..d7b8b1493668 100644 --- a/prow/config/jobs_test.go +++ b/prow/config/jobs_test.go @@ -370,7 +370,7 @@ func TestConditionalPresubmits(t *testing.T) { JobBase: JobBase{ Name: "cross build", }, - ChangeMatcher: ChangeMatcher{ + RegexpChangeMatcher: RegexpChangeMatcher{ RunIfChanged: `(Makefile|\.sh|_(windows|linux|osx|unknown)(_test)?\.go)$`, }, }, diff --git a/prow/jenkins/controller_test.go b/prow/jenkins/controller_test.go index 0fa2307abc15..7b3e41abcf91 100644 --- a/prow/jenkins/controller_test.go +++ b/prow/jenkins/controller_test.go @@ -51,7 +51,7 @@ func newFakeConfigAgent(t *testing.T, maxConcurrency int, operators []config.Jen JobBase: config.JobBase{ Name: "test-kubeadm-cloud", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "^(cmd/kubeadm|build/debs).*$", }, }, diff --git a/prow/plank/controller_test.go b/prow/plank/controller_test.go index f912a276600e..57849bc09543 100644 --- a/prow/plank/controller_test.go +++ b/prow/plank/controller_test.go @@ -56,7 +56,7 @@ func newFakeConfigAgent(t *testing.T, maxConcurrency int) *fca { JobBase: config.JobBase{ Name: "test-kubeadm-cloud", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "^(cmd/kubeadm|build/debs).*$", }, }, diff --git a/prow/plugins/skip/skip_test.go b/prow/plugins/skip/skip_test.go index 178d3b617731..c545d32da9c2 100644 --- a/prow/plugins/skip/skip_test.go +++ b/prow/plugins/skip/skip_test.go @@ -110,7 +110,7 @@ func TestSkipStatus(t *testing.T) { Context: "extended-tests", }, { - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "^(test/integration)", }, Context: "integration-tests", @@ -171,7 +171,7 @@ func TestSkipStatus(t *testing.T) { presubmits: []config.Presubmit{ { - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "^(test/integration)", }, Context: "integration-tests", @@ -217,7 +217,7 @@ func TestSkipStatus(t *testing.T) { presubmits: []config.Presubmit{ { SkipReport: true, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "^(test/integration)", }, Context: "integration-tests", diff --git a/prow/plugins/trigger/generic-comment_test.go b/prow/plugins/trigger/generic-comment_test.go index 478a455adfdb..b7642836cacd 100644 --- a/prow/plugins/trigger/generic-comment_test.go +++ b/prow/plugins/trigger/generic-comment_test.go @@ -295,7 +295,7 @@ func TestHandleGenericComment(t *testing.T) { JobBase: config.JobBase{ Name: "jab", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "CHANGED", }, SkipReport: true, @@ -320,7 +320,7 @@ func TestHandleGenericComment(t *testing.T) { JobBase: config.JobBase{ Name: "jib", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "CHANGED", }, Context: "pull-jib", @@ -344,7 +344,7 @@ func TestHandleGenericComment(t *testing.T) { JobBase: config.JobBase{ Name: "jub", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "CHANGED", }, Context: "pull-jub", @@ -368,7 +368,7 @@ func TestHandleGenericComment(t *testing.T) { JobBase: config.JobBase{ Name: "jib", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "CHANGED2", }, Context: "pull-jib", @@ -391,7 +391,7 @@ func TestHandleGenericComment(t *testing.T) { JobBase: config.JobBase{ Name: "jab", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "CHANGED", }, Context: "pull-jab", @@ -481,7 +481,7 @@ func TestHandleGenericComment(t *testing.T) { JobBase: config.JobBase{ Name: "jeb", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "CHANGED2", }, Context: "pull-jeb", @@ -505,7 +505,7 @@ func TestHandleGenericComment(t *testing.T) { JobBase: config.JobBase{ Name: "jeb", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "CHANGED2", }, Context: "pull-jib", @@ -528,7 +528,7 @@ func TestHandleGenericComment(t *testing.T) { JobBase: config.JobBase{ Name: "jub", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "CHANGED", }, Context: "pull-jub", @@ -552,7 +552,7 @@ func TestHandleGenericComment(t *testing.T) { JobBase: config.JobBase{ Name: "jub", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "CHANGED2", }, Context: "pull-jub", diff --git a/prow/plugins/trigger/push_test.go b/prow/plugins/trigger/push_test.go index 7bf469c0bbce..ed503bf40151 100644 --- a/prow/plugins/trigger/push_test.go +++ b/prow/plugins/trigger/push_test.go @@ -40,7 +40,7 @@ func TestHandlePE(t *testing.T) { JobBase: config.JobBase{ Name: "pass-butter", }, - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "\\.sh$", }, }, diff --git a/prow/tide/tide_test.go b/prow/tide/tide_test.go index ab0f71c4f08d..eb323fa2c5ca 100644 --- a/prow/tide/tide_test.go +++ b/prow/tide/tide_test.go @@ -959,7 +959,7 @@ func TestTakeAction(t *testing.T) { Context: "if-changed", Trigger: "/test if-changed", RerunCommand: "/test if-changed", - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "CHANGED", }, }, @@ -1799,7 +1799,7 @@ func TestPresubmitsByPull(t *testing.T) { presubmits: []config.Presubmit{ { Context: "always", - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "foo", }, }, @@ -1830,7 +1830,7 @@ func TestPresubmitsByPull(t *testing.T) { presubmits: []config.Presubmit{ { Context: "always", - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "foo", }, }, @@ -1896,7 +1896,7 @@ func TestPresubmitsByPull(t *testing.T) { presubmits: []config.Presubmit{ { Context: "presubmit", - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "^CHANGE.$", }, }, @@ -1916,7 +1916,7 @@ func TestPresubmitsByPull(t *testing.T) { presubmits: []config.Presubmit{ { Context: "presubmit", - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "^FIL.$", }, }, @@ -1937,7 +1937,7 @@ func TestPresubmitsByPull(t *testing.T) { presubmits: []config.Presubmit{ { Context: "presubmit", - ChangeMatcher: config.ChangeMatcher{ + RegexpChangeMatcher: config.RegexpChangeMatcher{ RunIfChanged: "^CHANGE.$", }, },