-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: adding delete event * creating a delete event in types * final touches, fingers crossed * fixing tests * fixing final lint errors * fix: removing old AllowDelete work and removing a naked return * fix: removing leftover allowDelete items from tests * fix: changing library/secret.go to reflect library/repo.go when it comes to allowedEvents * fix: modifying library/secret_test.go to reflect new secret.go changes * fix: removing fix so that it can be included in another PR * fix: small error when fixing merge conflicts * fix: making the linter happy * fix: changing ruleset.go to go with David May's comment * rolling back last change * rolling back last change --------- Co-authored-by: Claire.Nicholas <[email protected]> Co-authored-by: Easton Crupper <[email protected]>
- Loading branch information
1 parent
a91bd54
commit 0d0e223
Showing
12 changed files
with
303 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,6 @@ const ( | |
AllowCommentCreate | ||
AllowCommentEdit | ||
AllowSchedule | ||
AllowDeleteBranch | ||
AllowDeleteTag | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//nolint:dupl // similar code to push.go | ||
package actions | ||
|
||
import "github.com/go-vela/types/constants" | ||
|
||
// 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"` | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
deletion := new(Delete) | ||
deletion.SetBranch(true) | ||
deletion.SetTag(true) | ||
|
||
return deletion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.