Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deployments): check for deployment created event action #365

Merged
merged 8 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion constants/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion library/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,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()
Expand Down
2 changes: 1 addition & 1 deletion library/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
7 changes: 5 additions & 2 deletions library/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions yaml/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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: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",
Expand Down
Loading