Skip to content

Commit

Permalink
fix(deployments): check for deployment created event action (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 authored Apr 10, 2024
1 parent f24f795 commit cabbb61
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
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

0 comments on commit cabbb61

Please sign in to comment.