From 35992a00561285c882e05b972f5def1227a3765e Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Thu, 14 Dec 2023 13:45:42 -0600 Subject: [PATCH 01/15] feat: adding delete event --- constants/allow_events.go | 1 + database/repo.go | 3 +++ database/repo_test.go | 3 +++ item_test.go | 2 ++ library/actions/delete.go | 9 +++++++++ library/events.go | 1 + library/repo.go | 33 ++++++++++++++++++++++++++++++++- library/repo_test.go | 12 ++++++++++++ library/secret.go | 2 ++ 9 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 library/actions/delete.go diff --git a/constants/allow_events.go b/constants/allow_events.go index 60d6d88c..efc79bb4 100644 --- a/constants/allow_events.go +++ b/constants/allow_events.go @@ -20,4 +20,5 @@ const ( AllowDeployCreate AllowCommentCreate AllowCommentEdit + AllowPushDelete ) diff --git a/database/repo.go b/database/repo.go index 8fde8286..0b3cc7d3 100644 --- a/database/repo.go +++ b/database/repo.go @@ -66,6 +66,7 @@ type Repo struct { AllowDeploy sql.NullBool `sql:"allow_deploy"` AllowTag sql.NullBool `sql:"allow_tag"` AllowComment sql.NullBool `sql:"allow_comment"` + AllowDelete sql.NullBool `sql:"allow_delete"` AllowEvents sql.NullInt64 `sql:"allow_events"` PipelineType sql.NullString `sql:"pipeline_type"` PreviousName sql.NullString `sql:"previous_name"` @@ -240,6 +241,7 @@ func (r *Repo) ToLibrary() *library.Repo { repo.SetAllowDeploy(r.AllowDeploy.Bool) repo.SetAllowTag(r.AllowTag.Bool) repo.SetAllowComment(r.AllowComment.Bool) + repo.SetAllowDelete(r.AllowDelete.Bool) repo.SetAllowEvents(library.NewEventsFromMask(r.AllowEvents.Int64)) repo.SetPipelineType(r.PipelineType.String) repo.SetPreviousName(r.PreviousName.String) @@ -337,6 +339,7 @@ func RepoFromLibrary(r *library.Repo) *Repo { AllowDeploy: sql.NullBool{Bool: r.GetAllowDeploy(), Valid: true}, AllowTag: sql.NullBool{Bool: r.GetAllowTag(), Valid: true}, AllowComment: sql.NullBool{Bool: r.GetAllowComment(), Valid: true}, + AllowDelete: sql.NullBool{Bool: r.GetAllowDelete(), Valid: true}, AllowEvents: sql.NullInt64{Int64: r.GetAllowEvents().ToDatabase(), Valid: true}, PipelineType: sql.NullString{String: r.GetPipelineType(), Valid: true}, PreviousName: sql.NullString{String: r.GetPreviousName(), Valid: true}, diff --git a/database/repo_test.go b/database/repo_test.go index 3aa63fca..c431ec4e 100644 --- a/database/repo_test.go +++ b/database/repo_test.go @@ -180,6 +180,7 @@ func TestDatabase_Repo_ToLibrary(t *testing.T) { want.SetAllowDeploy(false) want.SetAllowTag(false) want.SetAllowComment(false) + want.SetAllowDelete(false) want.SetAllowEvents(e) want.SetPipelineType("yaml") want.SetPreviousName("oldName") @@ -337,6 +338,7 @@ func TestDatabase_RepoFromLibrary(t *testing.T) { r.SetAllowDeploy(false) r.SetAllowTag(false) r.SetAllowComment(false) + r.SetAllowDelete(false) r.SetAllowEvents(e) r.SetPipelineType("yaml") r.SetPreviousName("oldName") @@ -378,6 +380,7 @@ func testRepo() *Repo { AllowDeploy: sql.NullBool{Bool: false, Valid: true}, AllowTag: sql.NullBool{Bool: false, Valid: true}, AllowComment: sql.NullBool{Bool: false, Valid: true}, + AllowDelete: sql.NullBool{Bool: false, Valid: true}, AllowEvents: sql.NullInt64{Int64: 1, Valid: true}, PipelineType: sql.NullString{String: "yaml", Valid: true}, PreviousName: sql.NullString{String: "oldName", Valid: true}, diff --git a/item_test.go b/item_test.go index 8643f3e1..206d5197 100644 --- a/item_test.go +++ b/item_test.go @@ -59,6 +59,7 @@ func TestTypes_ToItem(t *testing.T) { AllowPush: &booL, AllowDeploy: &booL, AllowTag: &booL, + AllowDelete: &booL, AllowEvents: e, } u := &library.User{ @@ -111,6 +112,7 @@ func TestTypes_ToItem(t *testing.T) { AllowPush: &booL, AllowDeploy: &booL, AllowTag: &booL, + AllowDelete: &booL, AllowEvents: e, }, User: &library.User{ diff --git a/library/actions/delete.go b/library/actions/delete.go new file mode 100644 index 00000000..ab7e81e4 --- /dev/null +++ b/library/actions/delete.go @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: Apache-2.0 + +package actions + +// Deploy is the library representation of the various actions associated +// with the deploy event webhook from the SCM. +type Delete struct { + Created *bool `json:"created"` +} diff --git a/library/events.go b/library/events.go index ca84fed3..c1749aef 100644 --- a/library/events.go +++ b/library/events.go @@ -14,6 +14,7 @@ type Events struct { PullRequest *actions.Pull `json:"pull_request"` Deployment *actions.Deploy `json:"deployment"` Comment *actions.Comment `json:"comment"` + Delete *actions.Delete `json:"delete"` } // NewEventsFromMask is an instatiation function for the Events type that diff --git a/library/repo.go b/library/repo.go index b5bd13c1..4993992e 100644 --- a/library/repo.go +++ b/library/repo.go @@ -35,6 +35,7 @@ type Repo struct { AllowDeploy *bool `json:"allow_deploy,omitempty"` AllowTag *bool `json:"allow_tag,omitempty"` AllowComment *bool `json:"allow_comment,omitempty"` + AllowDelete *bool `json:"allow_delete,omitempty"` AllowEvents *Events `json:"allow_events,omitempty"` PipelineType *string `json:"pipeline_type,omitempty"` PreviousName *string `json:"previous_name,omitempty"` @@ -47,6 +48,7 @@ func (r *Repo) Environment() map[string]string { return map[string]string{ "VELA_REPO_ACTIVE": ToString(r.GetActive()), "VELA_REPO_ALLOW_COMMENT": ToString(r.GetAllowComment()), + "VELA_REPO_ALLOW_DELETE": ToString(r.GetAllowDelete()), "VELA_REPO_ALLOW_DEPLOY": ToString(r.GetAllowDeploy()), "VELA_REPO_ALLOW_PULL": ToString(r.GetAllowPull()), "VELA_REPO_ALLOW_PUSH": ToString(r.GetAllowPush()), @@ -70,6 +72,7 @@ func (r *Repo) Environment() map[string]string { // deprecated environment variables "REPOSITORY_ACTIVE": ToString(r.GetActive()), "REPOSITORY_ALLOW_COMMENT": ToString(r.GetAllowComment()), + "REPOSITORY_ALLOW_DELETE": ToString(r.GetAllowDelete()), "REPOSITORY_ALLOW_DEPLOY": ToString(r.GetAllowDeploy()), "REPOSITORY_ALLOW_PULL": ToString(r.GetAllowPull()), "REPOSITORY_ALLOW_PUSH": ToString(r.GetAllowPush()), @@ -366,7 +369,7 @@ func (r *Repo) GetAllowTag() bool { // When the provided Repo type is nil, or the field within // the type is nil, it returns the zero value for the field. func (r *Repo) GetAllowComment() bool { - // return zero value if Repo type or AllowTag field is nil + // return zero value if Repo type or AllowComment field is nil if r == nil || r.AllowComment == nil { return false } @@ -374,6 +377,19 @@ func (r *Repo) GetAllowComment() bool { return *r.AllowComment } +// GetAllowDelete returns the AllowDelete field. +// +// When the provided Repo type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (r *Repo) GetAllowDelete() bool { + // return zero value if Repo type or AllowDelete field is nil + if r == nil || r.AllowDelete == nil { + return false + } + + return *r.AllowDelete +} + // GetAllowEvents returns the AllowEvents field. // // When the provided Repo type is nil, or the field within @@ -712,6 +728,19 @@ func (r *Repo) SetAllowComment(v bool) { r.AllowComment = &v } +// SetAllowDelete sets the AllowDelete field. +// +// When the provided Repo type is nil, it +// will set nothing and immediately return. +func (r *Repo) SetAllowDelete(v bool) { + // return if Repo type is nil + if r == nil { + return + } + + r.AllowDelete = &v +} + // SetAllowEvents sets the AllowEvents field. // // When the provided Repo type is nil, it @@ -801,6 +830,7 @@ func (r *Repo) String() string { return fmt.Sprintf(`{ Active: %t, AllowComment: %t, + AllowDelete: %t, AllowDeploy: %t, AllowPull: %t, AllowPush: %t, @@ -827,6 +857,7 @@ func (r *Repo) String() string { }`, r.GetActive(), r.GetAllowComment(), + r.GetAllowDelete(), r.GetAllowDeploy(), r.GetAllowPull(), r.GetAllowPush(), diff --git a/library/repo_test.go b/library/repo_test.go index 1da2db4a..528de044 100644 --- a/library/repo_test.go +++ b/library/repo_test.go @@ -163,6 +163,10 @@ func TestLibrary_Repo_Getters(t *testing.T) { t.Errorf("GetAllowComment is %v, want %v", test.repo.GetAllowComment(), test.want.GetAllowComment()) } + if test.repo.GetAllowDelete() != test.want.GetAllowDelete() { + t.Errorf("GetAllowDelete is %v, want %v", test.repo.GetAllowDelete(), test.want.GetAllowDelete()) + } + if !reflect.DeepEqual(test.repo.GetAllowEvents(), test.want.GetAllowEvents()) { t.Errorf("GetRepo is %v, want %v", test.repo.GetAllowEvents(), test.want.GetAllowEvents()) } @@ -224,6 +228,7 @@ func TestLibrary_Repo_Setters(t *testing.T) { test.repo.SetAllowDeploy(test.want.GetAllowDeploy()) test.repo.SetAllowTag(test.want.GetAllowTag()) test.repo.SetAllowComment(test.want.GetAllowComment()) + test.repo.SetAllowDelete(test.want.GetAllowDelete()) test.repo.SetAllowEvents(test.want.GetAllowEvents()) test.repo.SetPipelineType(test.want.GetPipelineType()) test.repo.SetPreviousName(test.want.GetPreviousName()) @@ -313,6 +318,10 @@ func TestLibrary_Repo_Setters(t *testing.T) { t.Errorf("SetAllowComment is %v, want %v", test.repo.GetAllowComment(), test.want.GetAllowComment()) } + if test.repo.GetAllowDelete() != test.want.GetAllowDelete() { + t.Errorf("SetAllowDelete is %v, want %v", test.repo.GetAllowDelete(), test.want.GetAllowDelete()) + } + if !reflect.DeepEqual(test.repo.GetAllowEvents(), test.want.GetAllowEvents()) { t.Errorf("GetRepo is %v, want %v", test.repo.GetAllowEvents(), test.want.GetAllowEvents()) } @@ -373,6 +382,7 @@ func TestLibrary_Repo_String(t *testing.T) { want := fmt.Sprintf(`{ Active: %t, AllowComment: %t, + AllowDelete: %t, AllowDeploy: %t, AllowPull: %t, AllowPush: %t, @@ -399,6 +409,7 @@ func TestLibrary_Repo_String(t *testing.T) { }`, r.GetActive(), r.GetAllowComment(), + r.GetAllowDelete(), r.GetAllowDeploy(), r.GetAllowPull(), r.GetAllowPush(), @@ -459,6 +470,7 @@ func testRepo() *Repo { r.SetAllowDeploy(false) r.SetAllowTag(false) r.SetAllowComment(false) + r.SetAllowDelete(false) r.SetAllowEvents(e) r.SetPipelineType("") r.SetPreviousName("") diff --git a/library/secret.go b/library/secret.go index 62dd5e43..42188708 100644 --- a/library/secret.go +++ b/library/secret.go @@ -79,6 +79,8 @@ func (s *Secret) Match(from *pipeline.Container) bool { eACL = checkEvent(events, constants.EventDeploy) case constants.EventComment: eACL = checkEvent(events, constants.EventComment) + case constants.EventDelete: + eACL = checkEvent(events, constants.EventDelete) case constants.EventSchedule: eACL = checkEvent(events, constants.EventSchedule) } From 224ed3bc7291758046ead26ee37cd7e8af8893e6 Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Thu, 28 Dec 2023 16:07:09 -0500 Subject: [PATCH 02/15] creating a delete event in types --- constants/allow_events.go | 3 +- constants/event.go | 3 + library/actions/delete.go | 80 +++++++++++++++++++++++- library/actions/delete_test.go | 108 +++++++++++++++++++++++++++++++++ library/events.go | 36 ++++++++++- library/events_test.go | 14 +++++ library/repo.go | 2 + 7 files changed, 241 insertions(+), 5 deletions(-) create mode 100644 library/actions/delete_test.go diff --git a/constants/allow_events.go b/constants/allow_events.go index efc79bb4..a5118612 100644 --- a/constants/allow_events.go +++ b/constants/allow_events.go @@ -20,5 +20,6 @@ const ( AllowDeployCreate AllowCommentCreate AllowCommentEdit - AllowPushDelete + AllowDeleteBranch + AllowDeleteTag ) diff --git a/constants/event.go b/constants/event.go index cf72a089..9d59f7e5 100644 --- a/constants/event.go +++ b/constants/event.go @@ -7,6 +7,9 @@ const ( // EventComment defines the event type for comments added to a pull request. EventComment = "comment" + // EventDelete defines the event type for build and repo delete events. + EventDelete = "delete" + // EventDeploy defines the event type for build and repo deployment events. EventDeploy = "deployment" diff --git a/library/actions/delete.go b/library/actions/delete.go index ab7e81e4..ff62a04a 100644 --- a/library/actions/delete.go +++ b/library/actions/delete.go @@ -2,8 +2,82 @@ package actions -// Deploy is the library representation of the various actions associated -// with the deploy event webhook from the SCM. +import "github.com/go-vela/types/constants" + +// Pull is the library representation of the various actions associated +// with the delete event webhook from the SCM. type Delete struct { - Created *bool `json:"created"` + Branch *bool `json:"branch"` + Tag *bool `json:"tag"` +} + +// FromMask returns the Delete type resulting from the provided integer mask. +func (a *Delete) FromMask(mask int64) *Delete { + a.SetBranch(mask&constants.AllowDeleteBranch > 0) + a.SetTag(mask&constants.AllowDeleteTag > 0) + + return a +} + +// ToMask returns the integer mask of the values for the Delete set. +func (a *Delete) ToMask() int64 { + mask := int64(0) + + if a.GetBranch() { + mask = mask | constants.AllowDeleteBranch + } + + if a.GetTag() { + mask = mask | constants.AllowDeleteTag + } + + return mask +} + +// GetBranch returns the Branch field from the provided Delete. If the object is nil, +// or the field within the object is nil, it returns the zero value instead. +func (a *Delete) GetBranch() bool { + // return zero value if Delete type or Branch field is nil + if a == nil || a.Branch == nil { + return false + } + + return *a.Branch +} + +// GetTag returns the Tag field from the provided Delete. If the object is nil, +// or the field within the object is nil, it returns the zero value instead. +func (a *Delete) GetTag() bool { + // return zero value if Delete type or Tag field is nil + if a == nil || a.Tag == nil { + return false + } + + return *a.Tag +} + +// SetBranch sets the Delete Branch field. +// +// When the provided Delete type is nil, it +// will set nothing and immediately return. +func (a *Delete) SetBranch(v bool) { + // return if Events type is nil + if a == nil { + return + } + + a.Branch = &v +} + +// SetTag sets the Delete Tag field. +// +// When the provided Delete type is nil, it +// will set nothing and immediately return. +func (a *Delete) SetTag(v bool) { + // return if Events type is nil + if a == nil { + return + } + + a.Tag = &v } diff --git a/library/actions/delete_test.go b/library/actions/delete_test.go new file mode 100644 index 00000000..73a58ceb --- /dev/null +++ b/library/actions/delete_test.go @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: Apache-2.0 + +package actions + +import ( + "reflect" + "testing" + + "github.com/go-vela/types/constants" +) + +func TestLibrary_Delete_Getters(t *testing.T) { + // setup tests + tests := []struct { + actions *Delete + want *Delete + }{ + { + actions: testDelete(), + want: testDelete(), + }, + { + actions: new(Delete), + want: new(Delete), + }, + } + + // run tests + for _, test := range tests { + if test.actions.GetBranch() != test.want.GetBranch() { + t.Errorf("GetBranch is %v, want %v", test.actions.GetBranch(), test.want.GetBranch()) + } + + if test.actions.GetTag() != test.want.GetTag() { + t.Errorf("GetTag is %v, want %v", test.actions.GetTag(), test.want.GetTag()) + } + } +} + +func TestLibrary_Delete_Setters(t *testing.T) { + // setup types + var a *Delete + + // setup tests + tests := []struct { + actions *Delete + want *Delete + }{ + { + actions: testDelete(), + want: testDelete(), + }, + { + actions: a, + want: new(Delete), + }, + } + + // run tests + for _, test := range tests { + test.actions.SetBranch(test.want.GetBranch()) + test.actions.SetTag(test.want.GetTag()) + + if test.actions.GetBranch() != test.want.GetBranch() { + t.Errorf("SetBranch is %v, want %v", test.actions.GetBranch(), test.want.GetBranch()) + } + + if test.actions.GetTag() != test.want.GetTag() { + t.Errorf("SetTag is %v, want %v", test.actions.GetTag(), test.want.GetTag()) + } + } +} + +func TestLibrary_Delete_FromMask(t *testing.T) { + // setup types + mask := testMask() + + want := testDelete() + + // run test + got := new(Delete).FromMask(mask) + + if !reflect.DeepEqual(got, want) { + t.Errorf("FromMask is %v, want %v", got, want) + } +} + +func TestLibrary_Delete_ToMask(t *testing.T) { + // setup types + actions := testDelete() + + want := int64(constants.AllowDeleteBranch | constants.AllowDeleteTag) + + // run test + got := actions.ToMask() + + if want != got { + t.Errorf("ToMask is %v, want %v", got, want) + } +} + +func testDelete() *Delete { + delete := new(Delete) + delete.SetBranch(true) + delete.SetTag(true) + + return delete +} diff --git a/library/events.go b/library/events.go index c1749aef..9622bc74 100644 --- a/library/events.go +++ b/library/events.go @@ -24,6 +24,7 @@ func NewEventsFromMask(mask int64) *Events { pullActions := new(actions.Pull).FromMask(mask) deployActions := new(actions.Deploy).FromMask(mask) commentActions := new(actions.Comment).FromMask(mask) + deleteActions := new(actions.Delete).FromMask(mask) e := new(Events) @@ -31,6 +32,7 @@ func NewEventsFromMask(mask int64) *Events { e.SetPullRequest(pullActions) e.SetDeployment(deployActions) e.SetComment(commentActions) + e.SetDelete(deleteActions) return e } @@ -72,12 +74,20 @@ func (e *Events) List() []string { eventSlice = append(eventSlice, constants.EventComment+":"+constants.ActionEdited) } + if e.GetDelete().GetBranch() { + eventSlice = append(eventSlice, constants.EventDelete) + } + + if e.GetDelete().GetTag() { + eventSlice = append(eventSlice, constants.EventDelete) + } + return eventSlice } // ToDatabase is an Events method that converts a nested Events struct into an integer event mask. func (e *Events) ToDatabase() int64 { - return 0 | e.GetPush().ToMask() | e.GetPullRequest().ToMask() | e.GetComment().ToMask() | e.GetDeployment().ToMask() + return 0 | e.GetPush().ToMask() | e.GetPullRequest().ToMask() | e.GetComment().ToMask() | e.GetDeployment().ToMask() | e.GetDelete().ToMask() } // GetPush returns the Push field from the provided Events. If the object is nil, @@ -124,6 +134,17 @@ func (e *Events) GetComment() *actions.Comment { return e.Comment } +// GetDelete returns the Delete field from the provided Events. If the object is nil, +// or the field within the object is nil, it returns the zero value instead. +func (e *Events) GetDelete() *actions.Delete { + // return zero value if Events type or Comment field is nil + if e == nil || e.Delete == nil { + return new(actions.Delete) + } + + return e.Delete +} + // SetPush sets the Events Push field. // // When the provided Events type is nil, it @@ -175,3 +196,16 @@ func (e *Events) SetComment(v *actions.Comment) { e.Comment = v } + +// SetDelete sets the Events Delete field. +// +// When the provided Events type is nil, it +// will set nothing and immediately return. +func (e *Events) SetDelete(v *actions.Delete) { + // return if Events type is nil + if e == nil { + return + } + + e.Delete = v +} diff --git a/library/events_test.go b/library/events_test.go index 2023c46b..6d303e01 100644 --- a/library/events_test.go +++ b/library/events_test.go @@ -43,6 +43,10 @@ func TestLibrary_Events_Getters(t *testing.T) { if !reflect.DeepEqual(test.events.GetComment(), test.want.GetComment()) { t.Errorf("GetComment is %v, want %v", test.events.GetPush(), test.want.GetPush()) } + + if !reflect.DeepEqual(test.events.GetDelete(), test.want.GetDelete()) { + t.Errorf("GetDelete is %v, want %v", test.events.GetDelete(), test.want.GetDelete()) + } } } @@ -71,6 +75,7 @@ func TestLibrary_Events_Setters(t *testing.T) { test.events.SetPullRequest(test.want.GetPullRequest()) test.events.SetDeployment(test.want.GetDeployment()) test.events.SetComment(test.want.GetComment()) + test.events.SetDelete(test.want.GetDelete()) if !reflect.DeepEqual(test.events.GetPush(), test.want.GetPush()) { t.Errorf("SetPush is %v, want %v", test.events.GetPush(), test.want.GetPush()) @@ -87,6 +92,10 @@ func TestLibrary_Events_Setters(t *testing.T) { if !reflect.DeepEqual(test.events.GetComment(), test.want.GetComment()) { t.Errorf("SetComment is %v, want %v", test.events.GetComment(), test.want.GetComment()) } + + if !reflect.DeepEqual(test.events.GetDelete(), test.want.GetDelete()) { + t.Errorf("SetDelete is %v, want %v", test.events.GetDelete(), test.want.GetDelete()) + } } } @@ -144,10 +153,15 @@ func testEvents() *Events { comment.SetCreated(false) comment.SetEdited(false) + delete := new(actions.Delete) + delete.SetBranch(true) + delete.SetTag(true) + e.SetPush(push) e.SetPullRequest(pr) e.SetDeployment(deploy) e.SetComment(comment) + e.SetDelete(delete) return e } diff --git a/library/repo.go b/library/repo.go index 4993992e..48e6d5a2 100644 --- a/library/repo.go +++ b/library/repo.go @@ -818,6 +818,8 @@ func (r *Repo) EventAllowed(event, action string) (allowed bool) { allowed = r.GetAllowEvents().GetComment().GetEdited() case constants.EventDeploy: allowed = r.GetAllowEvents().GetDeployment().GetCreated() + case constants.EventDelete: + allowed = r.GetAllowEvents().GetDelete().GetBranch() } return From dbdfa96a9a5702398a5b6a13c842db43dd10c20e Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Fri, 29 Dec 2023 16:39:01 -0500 Subject: [PATCH 03/15] final touches, fingers crossed --- constants/action.go | 6 ++++++ library/actions/delete.go | 2 +- library/repo.go | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/constants/action.go b/constants/action.go index bcff84b7..f1e18c6e 100644 --- a/constants/action.go +++ b/constants/action.go @@ -24,4 +24,10 @@ const ( // ActionTransferred defines the action for transferring repository ownership. ActionTransferred = "transferred" + + // ActionBranch defines the action for deleting a branch. + ActionBranch = "branch" + + // ActionTag defines the action for deleting a tag. + ActionTag = "tag" ) diff --git a/library/actions/delete.go b/library/actions/delete.go index ff62a04a..c0692ab1 100644 --- a/library/actions/delete.go +++ b/library/actions/delete.go @@ -4,7 +4,7 @@ package actions import "github.com/go-vela/types/constants" -// Pull is the library representation of the various actions associated +// Delete is the library representation of the various actions associated // with the delete event webhook from the SCM. type Delete struct { Branch *bool `json:"branch"` diff --git a/library/repo.go b/library/repo.go index 48e6d5a2..5a5206a8 100644 --- a/library/repo.go +++ b/library/repo.go @@ -818,8 +818,10 @@ func (r *Repo) EventAllowed(event, action string) (allowed bool) { allowed = r.GetAllowEvents().GetComment().GetEdited() case constants.EventDeploy: allowed = r.GetAllowEvents().GetDeployment().GetCreated() - case constants.EventDelete: + case constants.EventDelete + ":" + constants.ActionBranch: allowed = r.GetAllowEvents().GetDelete().GetBranch() + case constants.EventDelete + ":" + constants.ActionTag: + allowed = r.GetAllowEvents().GetDelete().GetTag() } return From 55b5ef3be6cc50fbcd46ae70a5049e10dd3dde1a Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Fri, 29 Dec 2023 16:52:17 -0500 Subject: [PATCH 04/15] fixing tests --- library/actions/push_test.go | 4 +++- library/events.go | 4 ++-- library/events_test.go | 6 ++++-- library/repo_test.go | 6 ++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/library/actions/push_test.go b/library/actions/push_test.go index 181d0112..5cdc05d5 100644 --- a/library/actions/push_test.go +++ b/library/actions/push_test.go @@ -115,6 +115,8 @@ func testMask() int64 { constants.AllowPullSync | constants.AllowPullReopen | constants.AllowDeployCreate | - constants.AllowCommentCreate, + constants.AllowCommentCreate | + constants.AllowDeleteBranch | + constants.AllowDeleteTag, ) } diff --git a/library/events.go b/library/events.go index 9622bc74..b824dd61 100644 --- a/library/events.go +++ b/library/events.go @@ -75,11 +75,11 @@ func (e *Events) List() []string { } if e.GetDelete().GetBranch() { - eventSlice = append(eventSlice, constants.EventDelete) + eventSlice = append(eventSlice, constants.EventDelete+":"+constants.ActionBranch) } if e.GetDelete().GetTag() { - eventSlice = append(eventSlice, constants.EventDelete) + eventSlice = append(eventSlice, constants.EventDelete+":"+constants.ActionTag) } return eventSlice diff --git a/library/events_test.go b/library/events_test.go index 6d303e01..a96ef986 100644 --- a/library/events_test.go +++ b/library/events_test.go @@ -103,7 +103,7 @@ func TestLibrary_Events_List(t *testing.T) { // setup types e := testEvents() - want := []string{"push", "pull_request:opened", "pull_request:synchronize", "tag"} + want := []string{"push", "pull_request:opened", "pull_request:synchronize", "tag", "delete:branch", "delete:tag"} // run test got := e.List() @@ -120,7 +120,9 @@ func TestLibrary_Events_NewEventsFromMask(t *testing.T) { constants.AllowPushTag | constants.AllowPullOpen | constants.AllowPullSync | - constants.AllowPullReopen, + constants.AllowPullReopen | + constants.AllowDeleteBranch | + constants.AllowDeleteTag, ) want := testEvents() diff --git a/library/repo_test.go b/library/repo_test.go index 528de044..e77dda49 100644 --- a/library/repo_test.go +++ b/library/repo_test.go @@ -15,11 +15,12 @@ func TestLibrary_Repo_Environment(t *testing.T) { want := map[string]string{ "VELA_REPO_ACTIVE": "true", "VELA_REPO_ALLOW_COMMENT": "false", + "VELA_REPO_ALLOW_DELETE": "false", "VELA_REPO_ALLOW_DEPLOY": "false", "VELA_REPO_ALLOW_PULL": "false", "VELA_REPO_ALLOW_PUSH": "true", "VELA_REPO_ALLOW_TAG": "false", - "VELA_REPO_ALLOW_EVENTS": "push,pull_request:opened,pull_request:synchronize,tag", + "VELA_REPO_ALLOW_EVENTS": "push,pull_request:opened,pull_request:synchronize,tag,delete:branch,delete:tag", "VELA_REPO_BRANCH": "main", "VELA_REPO_TOPICS": "cloud,security", "VELA_REPO_BUILD_LIMIT": "10", @@ -36,11 +37,12 @@ func TestLibrary_Repo_Environment(t *testing.T) { "VELA_REPO_APPROVE_BUILD": "never", "REPOSITORY_ACTIVE": "true", "REPOSITORY_ALLOW_COMMENT": "false", + "REPOSITORY_ALLOW_DELETE": "false", "REPOSITORY_ALLOW_DEPLOY": "false", "REPOSITORY_ALLOW_PULL": "false", "REPOSITORY_ALLOW_PUSH": "true", "REPOSITORY_ALLOW_TAG": "false", - "REPOSITORY_ALLOW_EVENTS": "push,pull_request:opened,pull_request:synchronize,tag", + "REPOSITORY_ALLOW_EVENTS": "push,pull_request:opened,pull_request:synchronize,tag,delete:branch,delete:tag", "REPOSITORY_BRANCH": "main", "REPOSITORY_CLONE": "https://github.com/github/octocat.git", "REPOSITORY_FULL_NAME": "github/octocat", From fb0cc5ffd4ed02792e92ccb01e6dc6d9b1a78cc1 Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Tue, 2 Jan 2024 11:05:42 -0600 Subject: [PATCH 05/15] fixing final lint errors --- library/actions/delete.go | 3 ++- library/actions/delete_test.go | 8 ++++---- library/events_test.go | 8 ++++---- library/repo.go | 2 ++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/library/actions/delete.go b/library/actions/delete.go index c0692ab1..fa88046d 100644 --- a/library/actions/delete.go +++ b/library/actions/delete.go @@ -1,5 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 - +// +//nolint:dupl // similar code to push.go package actions import "github.com/go-vela/types/constants" diff --git a/library/actions/delete_test.go b/library/actions/delete_test.go index 73a58ceb..3c7cd539 100644 --- a/library/actions/delete_test.go +++ b/library/actions/delete_test.go @@ -100,9 +100,9 @@ func TestLibrary_Delete_ToMask(t *testing.T) { } func testDelete() *Delete { - delete := new(Delete) - delete.SetBranch(true) - delete.SetTag(true) + deletion := new(Delete) + deletion.SetBranch(true) + deletion.SetTag(true) - return delete + return deletion } diff --git a/library/events_test.go b/library/events_test.go index a96ef986..cf394594 100644 --- a/library/events_test.go +++ b/library/events_test.go @@ -155,15 +155,15 @@ func testEvents() *Events { comment.SetCreated(false) comment.SetEdited(false) - delete := new(actions.Delete) - delete.SetBranch(true) - delete.SetTag(true) + deletion := new(actions.Delete) + deletion.SetBranch(true) + deletion.SetTag(true) e.SetPush(push) e.SetPullRequest(pr) e.SetDeployment(deploy) e.SetComment(comment) - e.SetDelete(delete) + e.SetDelete(deletion) return e } diff --git a/library/repo.go b/library/repo.go index 5a5206a8..cf98e369 100644 --- a/library/repo.go +++ b/library/repo.go @@ -794,6 +794,8 @@ func (r *Repo) SetApproveBuild(v string) { } // EventAllowed determines whether or not an event is allowed based on the repository settings. +// +//nolint:nakedret // not necessary to watch for here func (r *Repo) EventAllowed(event, action string) (allowed bool) { allowed = false From 968406b1f68154914515fb5597a6b773544d2865 Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Tue, 2 Jan 2024 15:30:01 -0600 Subject: [PATCH 06/15] fix: removing old AllowDelete work and removing a naked return --- database/repo.go | 3 --- database/repo_test.go | 1 - item_test.go | 2 -- library/repo.go | 35 +---------------------------------- library/repo_test.go | 12 ------------ 5 files changed, 1 insertion(+), 52 deletions(-) diff --git a/database/repo.go b/database/repo.go index 0b3cc7d3..8fde8286 100644 --- a/database/repo.go +++ b/database/repo.go @@ -66,7 +66,6 @@ type Repo struct { AllowDeploy sql.NullBool `sql:"allow_deploy"` AllowTag sql.NullBool `sql:"allow_tag"` AllowComment sql.NullBool `sql:"allow_comment"` - AllowDelete sql.NullBool `sql:"allow_delete"` AllowEvents sql.NullInt64 `sql:"allow_events"` PipelineType sql.NullString `sql:"pipeline_type"` PreviousName sql.NullString `sql:"previous_name"` @@ -241,7 +240,6 @@ func (r *Repo) ToLibrary() *library.Repo { repo.SetAllowDeploy(r.AllowDeploy.Bool) repo.SetAllowTag(r.AllowTag.Bool) repo.SetAllowComment(r.AllowComment.Bool) - repo.SetAllowDelete(r.AllowDelete.Bool) repo.SetAllowEvents(library.NewEventsFromMask(r.AllowEvents.Int64)) repo.SetPipelineType(r.PipelineType.String) repo.SetPreviousName(r.PreviousName.String) @@ -339,7 +337,6 @@ func RepoFromLibrary(r *library.Repo) *Repo { AllowDeploy: sql.NullBool{Bool: r.GetAllowDeploy(), Valid: true}, AllowTag: sql.NullBool{Bool: r.GetAllowTag(), Valid: true}, AllowComment: sql.NullBool{Bool: r.GetAllowComment(), Valid: true}, - AllowDelete: sql.NullBool{Bool: r.GetAllowDelete(), Valid: true}, AllowEvents: sql.NullInt64{Int64: r.GetAllowEvents().ToDatabase(), Valid: true}, PipelineType: sql.NullString{String: r.GetPipelineType(), Valid: true}, PreviousName: sql.NullString{String: r.GetPreviousName(), Valid: true}, diff --git a/database/repo_test.go b/database/repo_test.go index c431ec4e..47ad921e 100644 --- a/database/repo_test.go +++ b/database/repo_test.go @@ -380,7 +380,6 @@ func testRepo() *Repo { AllowDeploy: sql.NullBool{Bool: false, Valid: true}, AllowTag: sql.NullBool{Bool: false, Valid: true}, AllowComment: sql.NullBool{Bool: false, Valid: true}, - AllowDelete: sql.NullBool{Bool: false, Valid: true}, AllowEvents: sql.NullInt64{Int64: 1, Valid: true}, PipelineType: sql.NullString{String: "yaml", Valid: true}, PreviousName: sql.NullString{String: "oldName", Valid: true}, diff --git a/item_test.go b/item_test.go index 206d5197..8643f3e1 100644 --- a/item_test.go +++ b/item_test.go @@ -59,7 +59,6 @@ func TestTypes_ToItem(t *testing.T) { AllowPush: &booL, AllowDeploy: &booL, AllowTag: &booL, - AllowDelete: &booL, AllowEvents: e, } u := &library.User{ @@ -112,7 +111,6 @@ func TestTypes_ToItem(t *testing.T) { AllowPush: &booL, AllowDeploy: &booL, AllowTag: &booL, - AllowDelete: &booL, AllowEvents: e, }, User: &library.User{ diff --git a/library/repo.go b/library/repo.go index cf98e369..44c9bd58 100644 --- a/library/repo.go +++ b/library/repo.go @@ -35,7 +35,6 @@ type Repo struct { AllowDeploy *bool `json:"allow_deploy,omitempty"` AllowTag *bool `json:"allow_tag,omitempty"` AllowComment *bool `json:"allow_comment,omitempty"` - AllowDelete *bool `json:"allow_delete,omitempty"` AllowEvents *Events `json:"allow_events,omitempty"` PipelineType *string `json:"pipeline_type,omitempty"` PreviousName *string `json:"previous_name,omitempty"` @@ -48,7 +47,6 @@ func (r *Repo) Environment() map[string]string { return map[string]string{ "VELA_REPO_ACTIVE": ToString(r.GetActive()), "VELA_REPO_ALLOW_COMMENT": ToString(r.GetAllowComment()), - "VELA_REPO_ALLOW_DELETE": ToString(r.GetAllowDelete()), "VELA_REPO_ALLOW_DEPLOY": ToString(r.GetAllowDeploy()), "VELA_REPO_ALLOW_PULL": ToString(r.GetAllowPull()), "VELA_REPO_ALLOW_PUSH": ToString(r.GetAllowPush()), @@ -72,7 +70,6 @@ func (r *Repo) Environment() map[string]string { // deprecated environment variables "REPOSITORY_ACTIVE": ToString(r.GetActive()), "REPOSITORY_ALLOW_COMMENT": ToString(r.GetAllowComment()), - "REPOSITORY_ALLOW_DELETE": ToString(r.GetAllowDelete()), "REPOSITORY_ALLOW_DEPLOY": ToString(r.GetAllowDeploy()), "REPOSITORY_ALLOW_PULL": ToString(r.GetAllowPull()), "REPOSITORY_ALLOW_PUSH": ToString(r.GetAllowPush()), @@ -377,19 +374,6 @@ func (r *Repo) GetAllowComment() bool { return *r.AllowComment } -// GetAllowDelete returns the AllowDelete field. -// -// When the provided Repo type is nil, or the field within -// the type is nil, it returns the zero value for the field. -func (r *Repo) GetAllowDelete() bool { - // return zero value if Repo type or AllowDelete field is nil - if r == nil || r.AllowDelete == nil { - return false - } - - return *r.AllowDelete -} - // GetAllowEvents returns the AllowEvents field. // // When the provided Repo type is nil, or the field within @@ -728,19 +712,6 @@ func (r *Repo) SetAllowComment(v bool) { r.AllowComment = &v } -// SetAllowDelete sets the AllowDelete field. -// -// When the provided Repo type is nil, it -// will set nothing and immediately return. -func (r *Repo) SetAllowDelete(v bool) { - // return if Repo type is nil - if r == nil { - return - } - - r.AllowDelete = &v -} - // SetAllowEvents sets the AllowEvents field. // // When the provided Repo type is nil, it @@ -794,8 +765,6 @@ func (r *Repo) SetApproveBuild(v string) { } // EventAllowed determines whether or not an event is allowed based on the repository settings. -// -//nolint:nakedret // not necessary to watch for here func (r *Repo) EventAllowed(event, action string) (allowed bool) { allowed = false @@ -826,7 +795,7 @@ func (r *Repo) EventAllowed(event, action string) (allowed bool) { allowed = r.GetAllowEvents().GetDelete().GetTag() } - return + return allowed } // String implements the Stringer interface for the Repo type. @@ -836,7 +805,6 @@ func (r *Repo) String() string { return fmt.Sprintf(`{ Active: %t, AllowComment: %t, - AllowDelete: %t, AllowDeploy: %t, AllowPull: %t, AllowPush: %t, @@ -863,7 +831,6 @@ func (r *Repo) String() string { }`, r.GetActive(), r.GetAllowComment(), - r.GetAllowDelete(), r.GetAllowDeploy(), r.GetAllowPull(), r.GetAllowPush(), diff --git a/library/repo_test.go b/library/repo_test.go index e77dda49..7c1e82da 100644 --- a/library/repo_test.go +++ b/library/repo_test.go @@ -165,10 +165,6 @@ func TestLibrary_Repo_Getters(t *testing.T) { t.Errorf("GetAllowComment is %v, want %v", test.repo.GetAllowComment(), test.want.GetAllowComment()) } - if test.repo.GetAllowDelete() != test.want.GetAllowDelete() { - t.Errorf("GetAllowDelete is %v, want %v", test.repo.GetAllowDelete(), test.want.GetAllowDelete()) - } - if !reflect.DeepEqual(test.repo.GetAllowEvents(), test.want.GetAllowEvents()) { t.Errorf("GetRepo is %v, want %v", test.repo.GetAllowEvents(), test.want.GetAllowEvents()) } @@ -230,7 +226,6 @@ func TestLibrary_Repo_Setters(t *testing.T) { test.repo.SetAllowDeploy(test.want.GetAllowDeploy()) test.repo.SetAllowTag(test.want.GetAllowTag()) test.repo.SetAllowComment(test.want.GetAllowComment()) - test.repo.SetAllowDelete(test.want.GetAllowDelete()) test.repo.SetAllowEvents(test.want.GetAllowEvents()) test.repo.SetPipelineType(test.want.GetPipelineType()) test.repo.SetPreviousName(test.want.GetPreviousName()) @@ -320,10 +315,6 @@ func TestLibrary_Repo_Setters(t *testing.T) { t.Errorf("SetAllowComment is %v, want %v", test.repo.GetAllowComment(), test.want.GetAllowComment()) } - if test.repo.GetAllowDelete() != test.want.GetAllowDelete() { - t.Errorf("SetAllowDelete is %v, want %v", test.repo.GetAllowDelete(), test.want.GetAllowDelete()) - } - if !reflect.DeepEqual(test.repo.GetAllowEvents(), test.want.GetAllowEvents()) { t.Errorf("GetRepo is %v, want %v", test.repo.GetAllowEvents(), test.want.GetAllowEvents()) } @@ -384,7 +375,6 @@ func TestLibrary_Repo_String(t *testing.T) { want := fmt.Sprintf(`{ Active: %t, AllowComment: %t, - AllowDelete: %t, AllowDeploy: %t, AllowPull: %t, AllowPush: %t, @@ -411,7 +401,6 @@ func TestLibrary_Repo_String(t *testing.T) { }`, r.GetActive(), r.GetAllowComment(), - r.GetAllowDelete(), r.GetAllowDeploy(), r.GetAllowPull(), r.GetAllowPush(), @@ -472,7 +461,6 @@ func testRepo() *Repo { r.SetAllowDeploy(false) r.SetAllowTag(false) r.SetAllowComment(false) - r.SetAllowDelete(false) r.SetAllowEvents(e) r.SetPipelineType("") r.SetPreviousName("") From 4b41e7e1ac1326eb3d54dbd6cbd04705046e1eeb Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Tue, 2 Jan 2024 15:34:12 -0600 Subject: [PATCH 07/15] fix: removing leftover allowDelete items from tests --- database/repo_test.go | 2 -- library/repo_test.go | 2 -- 2 files changed, 4 deletions(-) diff --git a/database/repo_test.go b/database/repo_test.go index 47ad921e..3aa63fca 100644 --- a/database/repo_test.go +++ b/database/repo_test.go @@ -180,7 +180,6 @@ func TestDatabase_Repo_ToLibrary(t *testing.T) { want.SetAllowDeploy(false) want.SetAllowTag(false) want.SetAllowComment(false) - want.SetAllowDelete(false) want.SetAllowEvents(e) want.SetPipelineType("yaml") want.SetPreviousName("oldName") @@ -338,7 +337,6 @@ func TestDatabase_RepoFromLibrary(t *testing.T) { r.SetAllowDeploy(false) r.SetAllowTag(false) r.SetAllowComment(false) - r.SetAllowDelete(false) r.SetAllowEvents(e) r.SetPipelineType("yaml") r.SetPreviousName("oldName") diff --git a/library/repo_test.go b/library/repo_test.go index 7c1e82da..f89cb376 100644 --- a/library/repo_test.go +++ b/library/repo_test.go @@ -15,7 +15,6 @@ func TestLibrary_Repo_Environment(t *testing.T) { want := map[string]string{ "VELA_REPO_ACTIVE": "true", "VELA_REPO_ALLOW_COMMENT": "false", - "VELA_REPO_ALLOW_DELETE": "false", "VELA_REPO_ALLOW_DEPLOY": "false", "VELA_REPO_ALLOW_PULL": "false", "VELA_REPO_ALLOW_PUSH": "true", @@ -37,7 +36,6 @@ func TestLibrary_Repo_Environment(t *testing.T) { "VELA_REPO_APPROVE_BUILD": "never", "REPOSITORY_ACTIVE": "true", "REPOSITORY_ALLOW_COMMENT": "false", - "REPOSITORY_ALLOW_DELETE": "false", "REPOSITORY_ALLOW_DEPLOY": "false", "REPOSITORY_ALLOW_PULL": "false", "REPOSITORY_ALLOW_PUSH": "true", From ae2f796da097a11afe313e6ac4764c2897d2756b Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Tue, 2 Jan 2024 15:42:46 -0600 Subject: [PATCH 08/15] fix: changing library/secret.go to reflect library/repo.go when it comes to allowedEvents --- library/secret.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/library/secret.go b/library/secret.go index 42188708..adfb348c 100644 --- a/library/secret.go +++ b/library/secret.go @@ -71,16 +71,24 @@ func (s *Secret) Match(from *pipeline.Container) bool { switch from.Environment["VELA_BUILD_EVENT"] { case constants.EventPush: eACL = checkEvent(events, constants.EventPush) - case constants.EventPull: - eACL = checkEvent(events, constants.EventPull) + case constants.EventPull + ":" + constants.ActionOpened: + eACL = checkEvent(events, constants.EventPull+":"+constants.ActionOpened) + case constants.EventPull + ":" + constants.ActionSynchronize: + eACL = checkEvent(events, constants.EventPull+":"+constants.ActionSynchronize) + case constants.EventPull + ":" + constants.ActionEdited: + eACL = checkEvent(events, constants.EventPull+":"+constants.ActionEdited) case constants.EventTag: eACL = checkEvent(events, constants.EventTag) case constants.EventDeploy: eACL = checkEvent(events, constants.EventDeploy) - case constants.EventComment: - eACL = checkEvent(events, constants.EventComment) - case constants.EventDelete: - eACL = checkEvent(events, constants.EventDelete) + case constants.EventComment + ":" + constants.ActionCreated: + eACL = checkEvent(events, constants.EventComment+":"+constants.ActionCreated) + case constants.EventComment + ":" + constants.ActionEdited: + eACL = checkEvent(events, constants.EventComment+":"+constants.ActionEdited) + case constants.EventDelete + ":" + constants.ActionBranch: + eACL = checkEvent(events, constants.EventDelete+":"+constants.ActionBranch) + case constants.EventDelete + ":" + constants.ActionTag: + eACL = checkEvent(events, constants.EventDelete+":"+constants.ActionTag) case constants.EventSchedule: eACL = checkEvent(events, constants.EventSchedule) } From a4aa422eb3ba1f00d15896bace09bfc521a45f5a Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Tue, 2 Jan 2024 15:47:00 -0600 Subject: [PATCH 09/15] fix: modifying library/secret_test.go to reflect new secret.go changes --- library/secret_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/secret_test.go b/library/secret_test.go index 4fe2986f..b0e120a8 100644 --- a/library/secret_test.go +++ b/library/secret_test.go @@ -49,9 +49,9 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request:opened"}, }, - sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"pull_request"}}, + sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"pull_request:opened"}}, want: true, }, { @@ -73,9 +73,9 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"VELA_BUILD_EVENT": "comment"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "comment:created"}, }, - sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"comment"}}, + sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"comment:created"}}, want: true, }, { @@ -163,9 +163,9 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request:opened"}, }, - sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine:latest"}, Events: &[]string{"push"}}, + sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine:latest"}, Events: &[]string{"push:opened"}}, want: false, }, { From fe133927b8f529ca27a7a0b9a88236d27fe68903 Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Wed, 3 Jan 2024 14:25:16 -0600 Subject: [PATCH 10/15] fix: removing fix so that it can be included in another PR --- library/secret.go | 20 ++++++-------------- library/secret_test.go | 12 ++++++------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/library/secret.go b/library/secret.go index adfb348c..42188708 100644 --- a/library/secret.go +++ b/library/secret.go @@ -71,24 +71,16 @@ func (s *Secret) Match(from *pipeline.Container) bool { switch from.Environment["VELA_BUILD_EVENT"] { case constants.EventPush: eACL = checkEvent(events, constants.EventPush) - case constants.EventPull + ":" + constants.ActionOpened: - eACL = checkEvent(events, constants.EventPull+":"+constants.ActionOpened) - case constants.EventPull + ":" + constants.ActionSynchronize: - eACL = checkEvent(events, constants.EventPull+":"+constants.ActionSynchronize) - case constants.EventPull + ":" + constants.ActionEdited: - eACL = checkEvent(events, constants.EventPull+":"+constants.ActionEdited) + case constants.EventPull: + eACL = checkEvent(events, constants.EventPull) case constants.EventTag: eACL = checkEvent(events, constants.EventTag) case constants.EventDeploy: eACL = checkEvent(events, constants.EventDeploy) - case constants.EventComment + ":" + constants.ActionCreated: - eACL = checkEvent(events, constants.EventComment+":"+constants.ActionCreated) - case constants.EventComment + ":" + constants.ActionEdited: - eACL = checkEvent(events, constants.EventComment+":"+constants.ActionEdited) - case constants.EventDelete + ":" + constants.ActionBranch: - eACL = checkEvent(events, constants.EventDelete+":"+constants.ActionBranch) - case constants.EventDelete + ":" + constants.ActionTag: - eACL = checkEvent(events, constants.EventDelete+":"+constants.ActionTag) + case constants.EventComment: + eACL = checkEvent(events, constants.EventComment) + case constants.EventDelete: + eACL = checkEvent(events, constants.EventDelete) case constants.EventSchedule: eACL = checkEvent(events, constants.EventSchedule) } diff --git a/library/secret_test.go b/library/secret_test.go index b0e120a8..4fe2986f 100644 --- a/library/secret_test.go +++ b/library/secret_test.go @@ -49,9 +49,9 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request:opened"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request"}, }, - sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"pull_request:opened"}}, + sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"pull_request"}}, want: true, }, { @@ -73,9 +73,9 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"VELA_BUILD_EVENT": "comment:created"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "comment"}, }, - sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"comment:created"}}, + sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"comment"}}, want: true, }, { @@ -163,9 +163,9 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request:opened"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request"}, }, - sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine:latest"}, Events: &[]string{"push:opened"}}, + sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine:latest"}, Events: &[]string{"push"}}, want: false, }, { From de1a14f0a4d867da97dbf1ce1c2c6b7a0fe10540 Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Fri, 5 Jan 2024 13:58:05 -0600 Subject: [PATCH 11/15] fix: small error when fixing merge conflicts --- library/events.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/library/events.go b/library/events.go index 3f018428..82eeba08 100644 --- a/library/events.go +++ b/library/events.go @@ -10,12 +10,12 @@ import ( // Events is the library representation of the various events that generate a // webhook from the SCM. type Events struct { - Push *actions.Push `json:"push"` - PullRequest *actions.Pull `json:"pull_request"` - Deployment *actions.Deploy `json:"deployment"` - Comment *actions.Comment `json:"comment"` + Push *actions.Push `json:"push"` + PullRequest *actions.Pull `json:"pull_request"` + Deployment *actions.Deploy `json:"deployment"` + Comment *actions.Comment `json:"comment"` Schedule *actions.Schedule `json:"schedule"` - Delete *actions.Delete `json:"delete"` + Delete *actions.Delete `json:"delete"` } // NewEventsFromMask is an instatiation function for the Events type that @@ -119,6 +119,7 @@ func (e *Events) List() []string { if e.GetDelete().GetTag() { eventSlice = append(eventSlice, constants.EventDelete+":"+constants.ActionTag) + } return eventSlice } @@ -270,4 +271,4 @@ func (e *Events) SetDelete(v *actions.Delete) { } e.Delete = v -} \ No newline at end of file +} From 395c6085a93f914105b93ecb68448c89296514b9 Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Fri, 5 Jan 2024 14:02:30 -0600 Subject: [PATCH 12/15] fix: making the linter happy --- library/actions/comment.go | 3 ++- library/actions/push.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/actions/comment.go b/library/actions/comment.go index 499cfed6..c0e04298 100644 --- a/library/actions/comment.go +++ b/library/actions/comment.go @@ -1,5 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 - +// +//nolint:dupl // similar code to delete.go package actions import "github.com/go-vela/types/constants" diff --git a/library/actions/push.go b/library/actions/push.go index 5472af94..9853f454 100644 --- a/library/actions/push.go +++ b/library/actions/push.go @@ -1,5 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 - +// +//nolint:dupl // similar code to comment.go package actions import "github.com/go-vela/types/constants" From 7ccf80276e5bd0a2a0fba6f6341ccfd1ccd48059 Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Fri, 5 Jan 2024 14:07:16 -0600 Subject: [PATCH 13/15] fix: changing ruleset.go to go with David May's comment --- yaml/ruleset.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/yaml/ruleset.go b/yaml/ruleset.go index 7b8fc615..59fdad6a 100644 --- a/yaml/ruleset.go +++ b/yaml/ruleset.go @@ -149,6 +149,7 @@ func (r *Rules) UnmarshalYAML(unmarshal func(interface{}) error) error { // backwards compatibility // pull_request = pull_request:opened + pull_request:synchronize + pull_request:reopened // comment = comment:created + comment:edited + // delete = delete:branch + delete:tag case constants.EventPull: events = append(events, constants.EventPull+":"+constants.ActionOpened, @@ -158,6 +159,10 @@ func (r *Rules) UnmarshalYAML(unmarshal func(interface{}) error) error { events = append(events, constants.EventComment+":"+constants.ActionCreated, constants.EventComment+":"+constants.ActionEdited) + case constants.EventDelete: + events = append(events, + constants.EventDelete+":"+constants.ActionBranch, + constants.EventDelete+":"+constants.ActionTag) default: events = append(events, e) } From 846d41d74ee4a6e2a75c09466e9488dce4354eae Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Mon, 8 Jan 2024 10:36:58 -0600 Subject: [PATCH 14/15] rolling back last change --- yaml/ruleset.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/yaml/ruleset.go b/yaml/ruleset.go index 59fdad6a..afc4246c 100644 --- a/yaml/ruleset.go +++ b/yaml/ruleset.go @@ -159,10 +159,6 @@ func (r *Rules) UnmarshalYAML(unmarshal func(interface{}) error) error { events = append(events, constants.EventComment+":"+constants.ActionCreated, constants.EventComment+":"+constants.ActionEdited) - case constants.EventDelete: - events = append(events, - constants.EventDelete+":"+constants.ActionBranch, - constants.EventDelete+":"+constants.ActionTag) default: events = append(events, e) } From 5198a27b3556ab7f3d7232e03d964f3199a71fdf Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Mon, 8 Jan 2024 10:42:45 -0600 Subject: [PATCH 15/15] rolling back last change --- yaml/ruleset.go | 1 - 1 file changed, 1 deletion(-) diff --git a/yaml/ruleset.go b/yaml/ruleset.go index afc4246c..7b8fc615 100644 --- a/yaml/ruleset.go +++ b/yaml/ruleset.go @@ -149,7 +149,6 @@ func (r *Rules) UnmarshalYAML(unmarshal func(interface{}) error) error { // backwards compatibility // pull_request = pull_request:opened + pull_request:synchronize + pull_request:reopened // comment = comment:created + comment:edited - // delete = delete:branch + delete:tag case constants.EventPull: events = append(events, constants.EventPull+":"+constants.ActionOpened,