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 4 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: 2 additions & 0 deletions library/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func (e *Events) Allowed(event, action string) bool {
allowed = e.GetComment().GetEdited()
case constants.EventDeploy:
allowed = e.GetDeployment().GetCreated()
plyr4 marked this conversation as resolved.
Show resolved Hide resolved
case constants.EventDeploy + ":" + constants.ActionCreated:
allowed = e.GetDeployment().GetCreated()
case constants.EventSchedule:
allowed = e.GetSchedule().GetRun()
case constants.EventDelete + ":" + constants.ActionBranch:
Expand Down
1 change: 1 addition & 0 deletions library/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
3 changes: 3 additions & 0 deletions yaml/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion yaml/ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading