Skip to content

Commit

Permalink
fix(yaml/ruleset): fix unmarshal PR event to use synchronize, not syn…
Browse files Browse the repository at this point in the history
…chronized (#257)

* fix(constants): change synchronized to synchronize to support legacy pr unmarshal

* fix tests

* change variable name too
  • Loading branch information
ecrupper committed Jun 9, 2022
1 parent ccad28d commit c5c7726
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions constants/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ const (
// ActionRenamed defines the action for renaming a repository.
ActionRenamed = "renamed"

// ActionSynchronized defines the action for the synchronizing of pull requests.
ActionSynchronized = "synchronized"
// ActionSynchronize defines the action for the synchronizing of pull requests.
ActionSynchronize = "synchronize"
)
22 changes: 11 additions & 11 deletions yaml/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Name: "install",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized", "pull_request:edited"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize", "pull_request:edited"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Image: "openjdk:latest",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Image: "openjdk:latest",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Image: "plugins/docker:18.09",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down Expand Up @@ -346,7 +346,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Name: "install",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Image: "openjdk:latest",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down Expand Up @@ -416,7 +416,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Image: "openjdk:latest",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down Expand Up @@ -460,7 +460,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Name: "install",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down Expand Up @@ -489,7 +489,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Image: "openjdk:latest",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Image: "openjdk:latest",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down Expand Up @@ -566,7 +566,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Name: "install",
Pull: "always",
Ruleset: Ruleset{
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronized"}},
If: Rules{Event: []string{"push", "pull_request:opened", "pull_request:synchronize"}},
Matcher: "filepath",
Operator: "and",
},
Expand Down
4 changes: 2 additions & 2 deletions yaml/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ func (r *Rules) UnmarshalYAML(unmarshal func(interface{}) error) error {

for _, e := range rules.Event {
switch e {
// backwards compatibility - pull_request = pull_request:opened + pull_request:synchronized
// backwards compatibility - pull_request = pull_request:opened + pull_request:synchronize
// comment = comment:created + comment:edited
case constants.EventPull:
events = append(events,
constants.EventPull+":"+constants.ActionOpened,
constants.EventPull+":"+constants.ActionSynchronized)
constants.EventPull+":"+constants.ActionSynchronize)
case constants.EventComment:
events = append(events,
constants.EventComment+":"+constants.ActionCreated,
Expand Down
2 changes: 1 addition & 1 deletion yaml/ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestYaml_Ruleset_UnmarshalYAML(t *testing.T) {
Tag: []string{"^refs/tags/(\\d+\\.)+\\d+$"},
},
Unless: Rules{
Event: []string{"deployment", "pull_request:opened", "pull_request:synchronized", "comment:created", "comment:edited"},
Event: []string{"deployment", "pull_request:opened", "pull_request:synchronize", "comment:created", "comment:edited"},
Path: []string{"foo.txt", "/foo/bar.txt"},
},
Matcher: "regexp",
Expand Down
2 changes: 1 addition & 1 deletion yaml/testdata/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ steps:
image: openjdk:latest
pull: true
ruleset:
event: [ push, pull_request:opened, pull_request:synchronized, pull_request:edited ]
event: [ push, pull_request:opened, pull_request:synchronize, pull_request:edited ]
volumes: [ /foo:/bar:ro ]
ulimits: [ foo=1024:2048 ]

Expand Down

0 comments on commit c5c7726

Please sign in to comment.