From 2824e454d35b91aea4a9b4411c20f4186081a071 Mon Sep 17 00:00:00 2001 From: davidvader Date: Tue, 19 Mar 2024 17:27:36 -0500 Subject: [PATCH 1/6] fix: check for deployment created event action --- library/events.go | 2 ++ library/events_test.go | 1 + 2 files changed, 3 insertions(+) diff --git a/library/events.go b/library/events.go index 88074d80..ff082ad8 100644 --- a/library/events.go +++ b/library/events.go @@ -66,6 +66,8 @@ func (e *Events) Allowed(event, action string) bool { allowed = e.GetComment().GetEdited() case constants.EventDeploy: allowed = e.GetDeployment().GetCreated() + case constants.EventDeploy + ":" + constants.ActionCreated: + allowed = e.GetDeployment().GetCreated() case constants.EventSchedule: allowed = e.GetSchedule().GetRun() case constants.EventDelete + ":" + constants.ActionBranch: diff --git a/library/events_test.go b/library/events_test.go index a26cc4dc..9e2d4d60 100644 --- a/library/events_test.go +++ b/library/events_test.go @@ -211,6 +211,7 @@ func TestLibrary_Events_Allowed(t *testing.T) { {event: "pull_request", action: "edited", want: false}, {event: "pull_request", action: "reopened", want: true}, {event: "deployment", want: false}, + {event: "deployment", action: "created", want: false}, {event: "comment", action: "created", want: true}, {event: "comment", action: "edited", want: false}, {event: "schedule", want: true}, From 0372e23053a34e6f6d5d53746fbd0629bd848579 Mon Sep 17 00:00:00 2001 From: davidvader Date: Tue, 19 Mar 2024 17:33:36 -0500 Subject: [PATCH 2/6] chore: comment --- constants/action.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constants/action.go b/constants/action.go index f1e18c6e..59ae7cde 100644 --- a/constants/action.go +++ b/constants/action.go @@ -7,7 +7,7 @@ const ( // ActionOpened defines the action for opening pull requests. ActionOpened = "opened" - // ActionCreated defines the action for creating issue comments. + // ActionCreated defines the action for creating deployments or issue comments. ActionCreated = "created" // ActionEdited defines the action for the editing of pull requests or issue comments. From 169d39be443ac3256db375e3553aaeeb38d11006 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 20 Mar 2024 09:33:50 -0500 Subject: [PATCH 3/6] fix: apply generic mapping to deployments --- yaml/ruleset.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/yaml/ruleset.go b/yaml/ruleset.go index 7b8fc615..57928278 100644 --- a/yaml/ruleset.go +++ b/yaml/ruleset.go @@ -154,6 +154,9 @@ func (r *Rules) UnmarshalYAML(unmarshal func(interface{}) error) error { constants.EventPull+":"+constants.ActionOpened, constants.EventPull+":"+constants.ActionSynchronize, constants.EventPull+":"+constants.ActionReopened) + case constants.EventDeploy: + events = append(events, + constants.EventDeploy+":"+constants.ActionCreated) case constants.EventComment: events = append(events, constants.EventComment+":"+constants.ActionCreated, From 470d5daf2af14a47b387d7036aad7ddddd54f3d2 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 20 Mar 2024 09:55:40 -0500 Subject: [PATCH 4/6] fix: apply created to test struct --- yaml/ruleset_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yaml/ruleset_test.go b/yaml/ruleset_test.go index 762bb904..8bf59790 100644 --- a/yaml/ruleset_test.go +++ b/yaml/ruleset_test.go @@ -114,7 +114,7 @@ func TestYaml_Ruleset_UnmarshalYAML(t *testing.T) { Tag: []string{"^refs/tags/(\\d+\\.)+\\d+$"}, }, Unless: Rules{ - Event: []string{"deployment", "pull_request:opened", "pull_request:synchronize", "pull_request:reopened", "comment:created", "comment:edited", "schedule"}, + Event: []string{"deployment:created", "pull_request:opened", "pull_request:synchronize", "pull_request:reopened", "comment:created", "comment:edited", "schedule"}, Path: []string{"foo.txt", "/foo/bar.txt"}, }, Matcher: "regexp", From cfcfee0ede5d88dc159606b1a3d35b9b57e3d2af Mon Sep 17 00:00:00 2001 From: dave vader <48764154+plyr4@users.noreply.github.com> Date: Wed, 20 Mar 2024 10:41:58 -0500 Subject: [PATCH 5/6] fix: remove redundant case Co-authored-by: Easton Crupper <65553218+ecrupper@users.noreply.github.com> --- library/events.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/events.go b/library/events.go index ff082ad8..e208bd96 100644 --- a/library/events.go +++ b/library/events.go @@ -64,8 +64,6 @@ func (e *Events) Allowed(event, action string) bool { allowed = e.GetComment().GetCreated() case constants.EventComment + ":" + constants.ActionEdited: allowed = e.GetComment().GetEdited() - case constants.EventDeploy: - allowed = e.GetDeployment().GetCreated() case constants.EventDeploy + ":" + constants.ActionCreated: allowed = e.GetDeployment().GetCreated() case constants.EventSchedule: From 24346df42d479d0a7dee0bfb0e758da0132c0f09 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 20 Mar 2024 10:57:01 -0500 Subject: [PATCH 6/6] fix: deployment tests --- library/events_test.go | 1 - library/secret_test.go | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/library/events_test.go b/library/events_test.go index 9e2d4d60..d331e0bc 100644 --- a/library/events_test.go +++ b/library/events_test.go @@ -210,7 +210,6 @@ func TestLibrary_Events_Allowed(t *testing.T) { {event: "pull_request", action: "synchronize", want: true}, {event: "pull_request", action: "edited", want: false}, {event: "pull_request", action: "reopened", want: true}, - {event: "deployment", want: false}, {event: "deployment", action: "created", want: false}, {event: "comment", action: "created", want: true}, {event: "comment", action: "edited", want: false}, diff --git a/library/secret_test.go b/library/secret_test.go index ebe14549..8860a46b 100644 --- a/library/secret_test.go +++ b/library/secret_test.go @@ -112,8 +112,11 @@ func TestLibrary_Secret_Match(t *testing.T) { { name: "deployment", step: &pipeline.Container{ - Image: "alpine:latest", - Environment: map[string]string{"VELA_BUILD_EVENT": "deployment"}, + Image: "alpine:latest", + Environment: map[string]string{ + "VELA_BUILD_EVENT": "deployment", + "VELA_BUILD_EVENT_ACTION": "created", + }, }, sec: &Secret{ Name: &v,