Skip to content

Commit

Permalink
RegexpChangeMatcher: improved naming and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ibzib committed Nov 27, 2018
1 parent ef031ae commit 71ad1f1
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 35 deletions.
4 changes: 2 additions & 2 deletions prow/config/branch_protection_test.go
Expand Up @@ -308,7 +308,7 @@ func TestJobRequirements(t *testing.T) {
},
{
Context: "run-if-changed",
ChangeMatcher: ChangeMatcher{
RegexpChangeMatcher: RegexpChangeMatcher{
RunIfChanged: "foo",
},
AlwaysRun: false,
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestJobRequirements(t *testing.T) {
},
{
Context: "run-if-changed",
ChangeMatcher: ChangeMatcher{
RegexpChangeMatcher: RegexpChangeMatcher{
RunIfChanged: "foo",
},
SkipReport: true,
Expand Down
10 changes: 5 additions & 5 deletions prow/config/config.go
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
13 changes: 7 additions & 6 deletions prow/config/jobs.go
Expand Up @@ -134,7 +134,7 @@ type Presubmit struct {

Brancher

ChangeMatcher
RegexpChangeMatcher

// We'll set these when we load it.
re *regexp.Regexp // from Trigger.
Expand All @@ -144,7 +144,7 @@ type Presubmit struct {
type Postsubmit struct {
JobBase

ChangeMatcher
RegexpChangeMatcher

Brancher

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion prow/config/jobs_test.go
Expand Up @@ -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)$`,
},
},
Expand Down
2 changes: 1 addition & 1 deletion prow/jenkins/controller_test.go
Expand Up @@ -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).*$",
},
},
Expand Down
2 changes: 1 addition & 1 deletion prow/plank/controller_test.go
Expand Up @@ -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).*$",
},
},
Expand Down
6 changes: 3 additions & 3 deletions prow/plugins/skip/skip_test.go
Expand Up @@ -110,7 +110,7 @@ func TestSkipStatus(t *testing.T) {
Context: "extended-tests",
},
{
ChangeMatcher: config.ChangeMatcher{
RegexpChangeMatcher: config.RegexpChangeMatcher{
RunIfChanged: "^(test/integration)",
},
Context: "integration-tests",
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestSkipStatus(t *testing.T) {

presubmits: []config.Presubmit{
{
ChangeMatcher: config.ChangeMatcher{
RegexpChangeMatcher: config.RegexpChangeMatcher{
RunIfChanged: "^(test/integration)",
},
Context: "integration-tests",
Expand Down Expand Up @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions prow/plugins/trigger/generic-comment_test.go
Expand Up @@ -295,7 +295,7 @@ func TestHandleGenericComment(t *testing.T) {
JobBase: config.JobBase{
Name: "jab",
},
ChangeMatcher: config.ChangeMatcher{
RegexpChangeMatcher: config.RegexpChangeMatcher{
RunIfChanged: "CHANGED",
},
SkipReport: true,
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion prow/plugins/trigger/push_test.go
Expand Up @@ -40,7 +40,7 @@ func TestHandlePE(t *testing.T) {
JobBase: config.JobBase{
Name: "pass-butter",
},
ChangeMatcher: config.ChangeMatcher{
RegexpChangeMatcher: config.RegexpChangeMatcher{
RunIfChanged: "\\.sh$",
},
},
Expand Down
12 changes: 6 additions & 6 deletions prow/tide/tide_test.go
Expand Up @@ -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",
},
},
Expand Down Expand Up @@ -1799,7 +1799,7 @@ func TestPresubmitsByPull(t *testing.T) {
presubmits: []config.Presubmit{
{
Context: "always",
ChangeMatcher: config.ChangeMatcher{
RegexpChangeMatcher: config.RegexpChangeMatcher{
RunIfChanged: "foo",
},
},
Expand Down Expand Up @@ -1830,7 +1830,7 @@ func TestPresubmitsByPull(t *testing.T) {
presubmits: []config.Presubmit{
{
Context: "always",
ChangeMatcher: config.ChangeMatcher{
RegexpChangeMatcher: config.RegexpChangeMatcher{
RunIfChanged: "foo",
},
},
Expand Down Expand Up @@ -1896,7 +1896,7 @@ func TestPresubmitsByPull(t *testing.T) {
presubmits: []config.Presubmit{
{
Context: "presubmit",
ChangeMatcher: config.ChangeMatcher{
RegexpChangeMatcher: config.RegexpChangeMatcher{
RunIfChanged: "^CHANGE.$",
},
},
Expand All @@ -1916,7 +1916,7 @@ func TestPresubmitsByPull(t *testing.T) {
presubmits: []config.Presubmit{
{
Context: "presubmit",
ChangeMatcher: config.ChangeMatcher{
RegexpChangeMatcher: config.RegexpChangeMatcher{
RunIfChanged: "^FIL.$",
},
},
Expand All @@ -1937,7 +1937,7 @@ func TestPresubmitsByPull(t *testing.T) {
presubmits: []config.Presubmit{
{
Context: "presubmit",
ChangeMatcher: config.ChangeMatcher{
RegexpChangeMatcher: config.RegexpChangeMatcher{
RunIfChanged: "^CHANGE.$",
},
},
Expand Down

0 comments on commit 71ad1f1

Please sign in to comment.