Skip to content

Commit

Permalink
add more PR actions and bring back legacy fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Nov 14, 2023
1 parent 394e61f commit 3be6442
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 40 deletions.
7 changes: 6 additions & 1 deletion constants/allow_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

package constants

// Allowed repo events. NOTE: these can NOT change order.
// 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 // 00000010 = 4
AllowPullEdit // ...
AllowPullSync
_ // AllowPullAssigned - Not Implemented
_ // AllowPullMilestoned - Not Implemented
_ // AllowPullLabel - Not Implemented
_ // AllowPullLocked - Not Implemented
_ // AllowPullReady - Not Implemented
_ // AllowPullReopen - Not Implemented
_ // AllowPullReviewRequest - Not Implemented
_ // AllowPullClosed - Not Implemented
AllowDeployCreate
Expand Down
15 changes: 15 additions & 0 deletions database/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ type Repo struct {
Private sql.NullBool `sql:"private"`
Trusted sql.NullBool `sql:"trusted"`
Active sql.NullBool `sql:"active"`
AllowPull sql.NullBool `sql:"allow_pull"`
AllowPush sql.NullBool `sql:"allow_push"`
AllowDeploy sql.NullBool `sql:"allow_deploy"`
AllowTag sql.NullBool `sql:"allow_tag"`
AllowComment sql.NullBool `sql:"allow_comment"`
AllowEvents sql.NullInt64 `sql:"allow_events"`
PipelineType sql.NullString `sql:"pipeline_type"`
PreviousName sql.NullString `sql:"previous_name"`
Expand Down Expand Up @@ -224,6 +229,11 @@ func (r *Repo) ToLibrary() *library.Repo {
repo.SetPrivate(r.Private.Bool)
repo.SetTrusted(r.Trusted.Bool)
repo.SetActive(r.Active.Bool)
repo.SetAllowPull(r.AllowPull.Bool)
repo.SetAllowPush(r.AllowPush.Bool)
repo.SetAllowDeploy(r.AllowDeploy.Bool)
repo.SetAllowTag(r.AllowTag.Bool)
repo.SetAllowComment(r.AllowComment.Bool)
repo.SetAllowEvents(library.NewEventsFromMask(r.AllowEvents.Int64))
repo.SetPipelineType(r.PipelineType.String)
repo.SetPreviousName(r.PreviousName.String)
Expand Down Expand Up @@ -315,6 +325,11 @@ func RepoFromLibrary(r *library.Repo) *Repo {
Private: sql.NullBool{Bool: r.GetPrivate(), Valid: true},
Trusted: sql.NullBool{Bool: r.GetTrusted(), Valid: true},
Active: sql.NullBool{Bool: r.GetActive(), Valid: true},
AllowPull: sql.NullBool{Bool: r.GetAllowPull(), Valid: true},
AllowPush: sql.NullBool{Bool: r.GetAllowPush(), Valid: true},
AllowDeploy: sql.NullBool{Bool: r.GetAllowDeploy(), Valid: true},
AllowTag: sql.NullBool{Bool: r.GetAllowTag(), Valid: true},
AllowComment: sql.NullBool{Bool: r.GetAllowComment(), 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},
Expand Down
15 changes: 15 additions & 0 deletions database/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func TestDatabase_Repo_ToLibrary(t *testing.T) {
want.SetPrivate(false)
want.SetTrusted(false)
want.SetActive(true)
want.SetAllowPull(false)
want.SetAllowPush(true)
want.SetAllowDeploy(false)
want.SetAllowTag(false)
want.SetAllowComment(false)
want.SetAllowEvents(e)
want.SetPipelineType("yaml")
want.SetPreviousName("oldName")
Expand Down Expand Up @@ -324,6 +329,11 @@ func TestDatabase_RepoFromLibrary(t *testing.T) {
r.SetPrivate(false)
r.SetTrusted(false)
r.SetActive(true)
r.SetAllowPull(false)
r.SetAllowPush(true)
r.SetAllowDeploy(false)
r.SetAllowTag(false)
r.SetAllowComment(false)
r.SetAllowEvents(e)
r.SetPipelineType("yaml")
r.SetPreviousName("oldName")
Expand Down Expand Up @@ -359,6 +369,11 @@ func testRepo() *Repo {
Private: sql.NullBool{Bool: false, Valid: true},
Trusted: sql.NullBool{Bool: false, Valid: true},
Active: sql.NullBool{Bool: true, Valid: true},
AllowPull: sql.NullBool{Bool: false, Valid: true},
AllowPush: sql.NullBool{Bool: true, Valid: true},
AllowDeploy: sql.NullBool{Bool: false, Valid: true},
AllowTag: sql.NullBool{Bool: false, Valid: true},
AllowComment: 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},
Expand Down
8 changes: 8 additions & 0 deletions item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func TestTypes_ToItem(t *testing.T) {
Private: &booL,
Trusted: &booL,
Active: &booL,
AllowPull: &booL,
AllowPush: &booL,
AllowDeploy: &booL,
AllowTag: &booL,
AllowEvents: e,
}
u := &library.User{
Expand Down Expand Up @@ -103,6 +107,10 @@ func TestTypes_ToItem(t *testing.T) {
Private: &booL,
Trusted: &booL,
Active: &booL,
AllowPull: &booL,
AllowPush: &booL,
AllowDeploy: &booL,
AllowTag: &booL,
AllowEvents: e,
},
User: &library.User{
Expand Down
179 changes: 167 additions & 12 deletions library/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ type Repo struct {
Private *bool `json:"private,omitempty"`
Trusted *bool `json:"trusted,omitempty"`
Active *bool `json:"active,omitempty"`
AllowPull *bool `json:"allow_pull,omitempty"`
AllowPush *bool `json:"allow_push,omitempty"`
AllowDeploy *bool `json:"allow_deploy,omitempty"`
AllowTag *bool `json:"allow_tag,omitempty"`
AllowComment *bool `json:"allow_comment,omitempty"`
AllowEvents *Events `json:"allow_events,omitempty"`
PipelineType *string `json:"pipeline_type,omitempty"`
PreviousName *string `json:"previous_name,omitempty"`
Expand All @@ -40,6 +45,11 @@ type Repo struct {
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_DEPLOY": ToString(r.GetAllowDeploy()),
"VELA_REPO_ALLOW_PULL": ToString(r.GetAllowPull()),
"VELA_REPO_ALLOW_PUSH": ToString(r.GetAllowPush()),
"VELA_REPO_ALLOW_TAG": ToString(r.GetAllowTag()),
"VELA_REPO_ALLOW_EVENTS": strings.Join(r.GetAllowEvents().List()[:], ","),
"VELA_REPO_BRANCH": ToString(r.GetBranch()),
"VELA_REPO_TOPICS": strings.Join(r.GetTopics()[:], ","),
Expand All @@ -56,18 +66,23 @@ func (r *Repo) Environment() map[string]string {
"VELA_REPO_PIPELINE_TYPE": ToString(r.GetPipelineType()),

// deprecated environment variables
"REPOSITORY_ACTIVE": ToString(r.GetActive()),
"REPOSITORY_ALLOW_EVENTS": strings.Join(r.GetAllowEvents().List()[:], ","),
"REPOSITORY_BRANCH": ToString(r.GetBranch()),
"REPOSITORY_CLONE": ToString(r.GetClone()),
"REPOSITORY_FULL_NAME": ToString(r.GetFullName()),
"REPOSITORY_LINK": ToString(r.GetLink()),
"REPOSITORY_NAME": ToString(r.GetName()),
"REPOSITORY_ORG": ToString(r.GetOrg()),
"REPOSITORY_PRIVATE": ToString(r.GetPrivate()),
"REPOSITORY_TIMEOUT": ToString(r.GetTimeout()),
"REPOSITORY_TRUSTED": ToString(r.GetTrusted()),
"REPOSITORY_VISIBILITY": ToString(r.GetVisibility()),
"REPOSITORY_ACTIVE": ToString(r.GetActive()),
"REPOSITORY_ALLOW_COMMENT": ToString(r.GetAllowComment()),
"REPOSITORY_ALLOW_DEPLOY": ToString(r.GetAllowDeploy()),
"REPOSITORY_ALLOW_PULL": ToString(r.GetAllowPull()),
"REPOSITORY_ALLOW_PUSH": ToString(r.GetAllowPush()),
"REPOSITORY_ALLOW_TAG": ToString(r.GetAllowTag()),
"REPOSITORY_ALLOW_EVENTS": strings.Join(r.GetAllowEvents().List()[:], ","),
"REPOSITORY_BRANCH": ToString(r.GetBranch()),
"REPOSITORY_CLONE": ToString(r.GetClone()),
"REPOSITORY_FULL_NAME": ToString(r.GetFullName()),
"REPOSITORY_LINK": ToString(r.GetLink()),
"REPOSITORY_NAME": ToString(r.GetName()),
"REPOSITORY_ORG": ToString(r.GetOrg()),
"REPOSITORY_PRIVATE": ToString(r.GetPrivate()),
"REPOSITORY_TIMEOUT": ToString(r.GetTimeout()),
"REPOSITORY_TRUSTED": ToString(r.GetTrusted()),
"REPOSITORY_VISIBILITY": ToString(r.GetVisibility()),
}
}

Expand Down Expand Up @@ -292,6 +307,71 @@ func (r *Repo) GetActive() bool {
return *r.Active
}

// GetAllowPull returns the AllowPull 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) GetAllowPull() bool {
// return zero value if Repo type or AllowPull field is nil
if r == nil || r.AllowPull == nil {
return false
}

return *r.AllowPull
}

// GetAllowPush returns the AllowPush 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) GetAllowPush() bool {
// return zero value if Repo type or AllowPush field is nil
if r == nil || r.AllowPush == nil {
return false
}

return *r.AllowPush
}

// GetAllowDeploy returns the AllowDeploy 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) GetAllowDeploy() bool {
// return zero value if Repo type or AllowDeploy field is nil
if r == nil || r.AllowDeploy == nil {
return false
}

return *r.AllowDeploy
}

// GetAllowTag returns the AllowTag 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) GetAllowTag() bool {
// return zero value if Repo type or AllowTag field is nil
if r == nil || r.AllowTag == nil {
return false
}

return *r.AllowTag
}

// GetAllowComment returns the AllowComment 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) GetAllowComment() bool {
// return zero value if Repo type or AllowTag field is nil
if r == nil || r.AllowComment == nil {
return false
}

return *r.AllowComment
}

// GetAllowEvents returns the AllowEvents field.
//
// When the provided Repo type is nil, or the field within
Expand Down Expand Up @@ -552,6 +632,71 @@ func (r *Repo) SetActive(v bool) {
r.Active = &v
}

// SetAllowPull sets the AllowPull field.
//
// When the provided Repo type is nil, it
// will set nothing and immediately return.
func (r *Repo) SetAllowPull(v bool) {
// return if Repo type is nil
if r == nil {
return
}

r.AllowPull = &v
}

// SetAllowPush sets the AllowPush field.
//
// When the provided Repo type is nil, it
// will set nothing and immediately return.
func (r *Repo) SetAllowPush(v bool) {
// return if Repo type is nil
if r == nil {
return
}

r.AllowPush = &v
}

// SetAllowDeploy sets the AllowDeploy field.
//
// When the provided Repo type is nil, it
// will set nothing and immediately return.
func (r *Repo) SetAllowDeploy(v bool) {
// return if Repo type is nil
if r == nil {
return
}

r.AllowDeploy = &v
}

// SetAllowTag sets the AllowTag field.
//
// When the provided Repo type is nil, it
// will set nothing and immediately return.
func (r *Repo) SetAllowTag(v bool) {
// return if Repo type is nil
if r == nil {
return
}

r.AllowTag = &v
}

// SetAllowComment sets the AllowComment field.
//
// When the provided Repo type is nil, it
// will set nothing and immediately return.
func (r *Repo) SetAllowComment(v bool) {
// return if Repo type is nil
if r == nil {
return
}

r.AllowComment = &v
}

// SetAllowEvents sets the AllowEvents field.
//
// When the provided Repo type is nil, it
Expand Down Expand Up @@ -625,6 +770,11 @@ func (r *Repo) EventAllowed(event, action string) (allowed bool) {
func (r *Repo) String() string {
return fmt.Sprintf(`{

Check failure on line 771 in library/repo.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] library/repo.go#L771

771-821 lines are duplicate of `library/repo_test.go:361-411` (dupl)
Raw output
library/repo.go:771: 771-821 lines are duplicate of `library/repo_test.go:361-411` (dupl)
	return fmt.Sprintf(`{
  Active: %t,
  AllowComment: %t,
  AllowDeploy: %t,
  AllowPull: %t,
  AllowPush: %t,
  AllowTag: %t,
  AllowEvents: %s,
  Branch: %s,
  BuildLimit: %d,
  Clone: %s,
  Counter: %d,
  FullName: %s,
  ID: %d,
  Link: %s,
  Name: %s,
  Org: %s,
  PipelineType: %s,
  PreviousName: %s,
  Private: %t,
  Timeout: %d,
  Topics: %s,
  Trusted: %t,
  UserID: %d
  Visibility: %s,
}`,
		r.GetActive(),
		r.GetAllowComment(),
		r.GetAllowDeploy(),
		r.GetAllowPull(),
		r.GetAllowPush(),
		r.GetAllowTag(),
		r.GetAllowEvents().List(),
		r.GetBranch(),
		r.GetBuildLimit(),
		r.GetClone(),
		r.GetCounter(),
		r.GetFullName(),
		r.GetID(),
		r.GetLink(),
		r.GetName(),
		r.GetOrg(),
		r.GetPipelineType(),
		r.GetPreviousName(),
		r.GetPrivate(),
		r.GetTimeout(),
		r.GetTopics(),
		r.GetTrusted(),
		r.GetUserID(),
		r.GetVisibility(),
	)
Active: %t,
AllowComment: %t,
AllowDeploy: %t,
AllowPull: %t,
AllowPush: %t,
AllowTag: %t,
AllowEvents: %s,
Branch: %s,
BuildLimit: %d,
Expand All @@ -645,6 +795,11 @@ func (r *Repo) String() string {
Visibility: %s,
}`,
r.GetActive(),
r.GetAllowComment(),
r.GetAllowDeploy(),
r.GetAllowPull(),
r.GetAllowPush(),
r.GetAllowTag(),
r.GetAllowEvents().List(),
r.GetBranch(),
r.GetBuildLimit(),
Expand Down
Loading

0 comments on commit 3be6442

Please sign in to comment.