diff --git a/constants/action.go b/constants/action.go index da0a4449..67e4e835 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. diff --git a/library/events.go b/library/events.go index c216b199..48351517 100644 --- a/library/events.go +++ b/library/events.go @@ -155,7 +155,7 @@ func (e *Events) Allowed(event, action string) bool { allowed = e.GetComment().GetCreated() case constants.EventComment + ":" + constants.ActionEdited: allowed = e.GetComment().GetEdited() - case constants.EventDeploy: + case constants.EventDeploy + ":" + constants.ActionCreated: allowed = e.GetDeployment().GetCreated() case constants.EventSchedule: allowed = e.GetSchedule().GetRun() diff --git a/library/events_test.go b/library/events_test.go index 7356025c..86771ea1 100644 --- a/library/events_test.go +++ b/library/events_test.go @@ -339,7 +339,7 @@ func TestLibrary_Events_Allowed(t *testing.T) { {event: "pull_request", action: "reopened", want: true}, {event: "pull_request", action: "labeled", want: false}, {event: "pull_request", action: "unlabeled", 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}, diff --git a/library/secret_test.go b/library/secret_test.go index ba0e3047..5074831f 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, diff --git a/yaml/ruleset.go b/yaml/ruleset.go index 2fe23e16..4a6d87f7 100644 --- a/yaml/ruleset.go +++ b/yaml/ruleset.go @@ -159,6 +159,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, diff --git a/yaml/ruleset_test.go b/yaml/ruleset_test.go index 559395ba..05a67ce1 100644 --- a/yaml/ruleset_test.go +++ b/yaml/ruleset_test.go @@ -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: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",