-
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.
Merge branch 'main' into feat/deploymentTable
- Loading branch information
Showing
17 changed files
with
1,308 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package constants | ||
|
||
// Allowed repo events. NOTE: these can NOT change order. New events must be added at the end. | ||
const ( | ||
AllowPushBranch = 1 << iota // 00000001 = 1 | ||
AllowPushTag // 00000010 = 2 | ||
AllowPullOpen // 00000100 = 4 | ||
AllowPullEdit // ... | ||
AllowPullSync | ||
_ // AllowPullAssigned - Not Implemented | ||
_ // AllowPullMilestoned - Not Implemented | ||
_ // AllowPullLabel - Not Implemented | ||
_ // AllowPullLocked - Not Implemented | ||
_ // AllowPullReady - Not Implemented | ||
AllowPullReopen | ||
_ // AllowPullReviewRequest - Not Implemented | ||
_ // AllowPullClosed - Not Implemented | ||
AllowDeployCreate | ||
AllowCommentCreate | ||
AllowCommentEdit | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//nolint:dupl // ignore dup code | ||
package actions | ||
|
||
import "github.com/go-vela/types/constants" | ||
|
||
// Comment is the library representation of the various actions associated | ||
// with the comment event webhook from the SCM. | ||
type Comment struct { | ||
Created *bool `json:"created"` | ||
Edited *bool `json:"edited"` | ||
} | ||
|
||
// FromMask returns the Comment type resulting from the provided integer mask. | ||
func (a *Comment) FromMask(mask int64) *Comment { | ||
a.SetCreated(mask&constants.AllowCommentCreate > 0) | ||
a.SetEdited(mask&constants.AllowCommentEdit > 0) | ||
|
||
return a | ||
} | ||
|
||
// ToMask returns the integer mask of the values for the Comment set. | ||
func (a *Comment) ToMask() int64 { | ||
mask := int64(0) | ||
|
||
if a.GetCreated() { | ||
mask = mask | constants.AllowCommentCreate | ||
} | ||
|
||
if a.GetEdited() { | ||
mask = mask | constants.AllowCommentEdit | ||
} | ||
|
||
return mask | ||
} | ||
|
||
// GetCreated returns the Created field from the provided Comment. If the object is nil, | ||
// or the field within the object is nil, it returns the zero value instead. | ||
func (a *Comment) GetCreated() bool { | ||
// return zero value if Events type or Created field is nil | ||
if a == nil || a.Created == nil { | ||
return false | ||
} | ||
|
||
return *a.Created | ||
} | ||
|
||
// GetEdited returns the Edited field from the provided Comment. If the object is nil, | ||
// or the field within the object is nil, it returns the zero value instead. | ||
func (a *Comment) GetEdited() bool { | ||
// return zero value if Events type or Edited field is nil | ||
if a == nil || a.Edited == nil { | ||
return false | ||
} | ||
|
||
return *a.Edited | ||
} | ||
|
||
// SetCreated sets the Comment Created field. | ||
// | ||
// When the provided Events type is nil, it | ||
// will set nothing and immediately return. | ||
func (a *Comment) SetCreated(v bool) { | ||
// return if Events type is nil | ||
if a == nil { | ||
return | ||
} | ||
|
||
a.Created = &v | ||
} | ||
|
||
// SetEdited sets the Comment Edited field. | ||
// | ||
// When the provided Events type is nil, it | ||
// will set nothing and immediately return. | ||
func (a *Comment) SetEdited(v bool) { | ||
// return if Events type is nil | ||
if a == nil { | ||
return | ||
} | ||
|
||
a.Edited = &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_Comment_Getters(t *testing.T) { | ||
// setup tests | ||
tests := []struct { | ||
actions *Comment | ||
want *Comment | ||
}{ | ||
{ | ||
actions: testComment(), | ||
want: testComment(), | ||
}, | ||
{ | ||
actions: new(Comment), | ||
want: new(Comment), | ||
}, | ||
} | ||
|
||
// run tests | ||
for _, test := range tests { | ||
if test.actions.GetCreated() != test.want.GetCreated() { | ||
t.Errorf("GetCreated is %v, want %v", test.actions.GetCreated(), test.want.GetCreated()) | ||
} | ||
|
||
if test.actions.GetEdited() != test.want.GetEdited() { | ||
t.Errorf("GetEdited is %v, want %v", test.actions.GetEdited(), test.want.GetEdited()) | ||
} | ||
} | ||
} | ||
|
||
func TestLibrary_Comment_Setters(t *testing.T) { | ||
// setup types | ||
var a *Comment | ||
|
||
// setup tests | ||
tests := []struct { | ||
actions *Comment | ||
want *Comment | ||
}{ | ||
{ | ||
actions: testComment(), | ||
want: testComment(), | ||
}, | ||
{ | ||
actions: a, | ||
want: new(Comment), | ||
}, | ||
} | ||
|
||
// run tests | ||
for _, test := range tests { | ||
test.actions.SetCreated(test.want.GetCreated()) | ||
test.actions.SetEdited(test.want.GetEdited()) | ||
|
||
if test.actions.GetCreated() != test.want.GetCreated() { | ||
t.Errorf("SetCreated is %v, want %v", test.actions.GetCreated(), test.want.GetCreated()) | ||
} | ||
|
||
if test.actions.GetEdited() != test.want.GetEdited() { | ||
t.Errorf("SetEdited is %v, want %v", test.actions.GetEdited(), test.want.GetEdited()) | ||
} | ||
} | ||
} | ||
|
||
func TestLibrary_Comment_FromMask(t *testing.T) { | ||
// setup types | ||
mask := testMask() | ||
|
||
want := testComment() | ||
|
||
// run test | ||
got := new(Comment).FromMask(mask) | ||
|
||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("FromMask is %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func TestLibrary_Comment_ToMask(t *testing.T) { | ||
// setup types | ||
actions := testComment() | ||
|
||
want := int64(constants.AllowCommentCreate) | ||
|
||
// run test | ||
got := actions.ToMask() | ||
|
||
if want != got { | ||
t.Errorf("ToMask is %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func testComment() *Comment { | ||
comment := new(Comment) | ||
comment.SetCreated(true) | ||
comment.SetEdited(false) | ||
|
||
return comment | ||
} |
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,53 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package actions | ||
|
||
import "github.com/go-vela/types/constants" | ||
|
||
// Deploy is the library representation of the various actions associated | ||
// with the deploy event webhook from the SCM. | ||
type Deploy struct { | ||
Created *bool `json:"created"` | ||
} | ||
|
||
// FromMask returns the Deploy type resulting from the provided integer mask. | ||
func (a *Deploy) FromMask(mask int64) *Deploy { | ||
a.SetCreated(mask&constants.AllowDeployCreate > 0) | ||
|
||
return a | ||
} | ||
|
||
// ToMask returns the integer mask of the values for the Deploy set. | ||
func (a *Deploy) ToMask() int64 { | ||
mask := int64(0) | ||
|
||
if a.GetCreated() { | ||
mask = mask | constants.AllowDeployCreate | ||
} | ||
|
||
return mask | ||
} | ||
|
||
// GetCreated returns the Created field from the provided Deploy. If the object is nil, | ||
// or the field within the object is nil, it returns the zero value instead. | ||
func (a *Deploy) GetCreated() bool { | ||
// return zero value if Deploy type or Created field is nil | ||
if a == nil || a.Created == nil { | ||
return false | ||
} | ||
|
||
return *a.Created | ||
} | ||
|
||
// SetCreated sets the Deploy Created field. | ||
// | ||
// When the provided Deploy type is nil, it | ||
// will set nothing and immediately return. | ||
func (a *Deploy) SetCreated(v bool) { | ||
// return if Deploy type is nil | ||
if a == nil { | ||
return | ||
} | ||
|
||
a.Created = &v | ||
} |
Oops, something went wrong.