Skip to content

Commit

Permalink
chore: delete legacy allow event fields and methods (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Apr 1, 2024
1 parent 476edfa commit 9b43c70
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 357 deletions.
15 changes: 0 additions & 15 deletions database/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ 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 @@ -235,11 +230,6 @@ 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 @@ -332,11 +322,6 @@ 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: 0 additions & 15 deletions database/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ 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 @@ -332,11 +327,6 @@ 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 @@ -373,11 +363,6 @@ 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
9 changes: 0 additions & 9 deletions database/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type Secret struct {
Value sql.NullString `sql:"value"`
Type sql.NullString `sql:"type"`
Images pq.StringArray `sql:"images" gorm:"type:varchar(1000)"`
Events pq.StringArray `sql:"events" gorm:"type:varchar(1000)"`
AllowEvents sql.NullInt64 `sql:"allow_events"`
AllowCommand sql.NullBool `sql:"allow_command"`
AllowSubstitution sql.NullBool `sql:"allow_substitution"`
Expand Down Expand Up @@ -194,7 +193,6 @@ func (s *Secret) ToLibrary() *library.Secret {
secret.SetValue(s.Value.String)
secret.SetType(s.Type.String)
secret.SetImages(s.Images)
secret.SetEvents(s.Events)
secret.SetAllowEvents(library.NewEventsFromMask(s.AllowEvents.Int64))
secret.SetAllowCommand(s.AllowCommand.Bool)
secret.SetAllowSubstitution(s.AllowSubstitution.Bool)
Expand Down Expand Up @@ -261,12 +259,6 @@ func (s *Secret) Validate() error {
s.Images[i] = sanitize(v)
}

// ensure that all Events are sanitized
// to avoid unsafe HTML content
for i, v := range s.Events {
s.Events[i] = sanitize(v)
}

return nil
}

Expand All @@ -282,7 +274,6 @@ func SecretFromLibrary(s *library.Secret) *Secret {
Value: sql.NullString{String: s.GetValue(), Valid: true},
Type: sql.NullString{String: s.GetType(), Valid: true},
Images: pq.StringArray(s.GetImages()),
Events: pq.StringArray(s.GetEvents()),
AllowEvents: sql.NullInt64{Int64: s.GetAllowEvents().ToDatabase(), Valid: true},
AllowCommand: sql.NullBool{Bool: s.GetAllowCommand(), Valid: true},
AllowSubstitution: sql.NullBool{Bool: s.GetAllowSubstitution(), Valid: true},
Expand Down
3 changes: 0 additions & 3 deletions database/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func TestDatabase_Secret_ToLibrary(t *testing.T) {
want.SetValue("bar")
want.SetType("repo")
want.SetImages([]string{"alpine"})
want.SetEvents([]string{"push", "tag", "deployment"})
want.SetAllowEvents(library.NewEventsFromMask(1))
want.SetAllowCommand(true)
want.SetAllowSubstitution(true)
Expand Down Expand Up @@ -293,7 +292,6 @@ func TestDatabase_SecretFromLibrary(t *testing.T) {
s.SetValue("bar")
s.SetType("repo")
s.SetImages([]string{"alpine"})
s.SetEvents([]string{"push", "tag", "deployment"})
s.SetAllowEvents(library.NewEventsFromMask(1))
s.SetAllowCommand(true)
s.SetAllowSubstitution(true)
Expand Down Expand Up @@ -324,7 +322,6 @@ func testSecret() *Secret {
Value: sql.NullString{String: "bar", Valid: true},
Type: sql.NullString{String: "repo", Valid: true},
Images: []string{"alpine"},
Events: []string{"push", "tag", "deployment"},
AllowEvents: sql.NullInt64{Int64: 1, Valid: true},
AllowCommand: sql.NullBool{Bool: true, Valid: true},
AllowSubstitution: sql.NullBool{Bool: true, Valid: true},
Expand Down
8 changes: 0 additions & 8 deletions item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ 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 @@ -107,10 +103,6 @@ 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: 12 additions & 167 deletions library/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ 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 @@ -44,11 +39,6 @@ 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 @@ -66,23 +56,18 @@ func (r *Repo) Environment() map[string]string {
"VELA_REPO_APPROVE_BUILD": ToString(r.GetApproveBuild()),

// deprecated environment variables
"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()),
"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()),
}
}

Expand Down Expand Up @@ -307,71 +292,6 @@ 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 AllowComment 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 @@ -645,71 +565,6 @@ 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 @@ -768,11 +623,6 @@ func (r *Repo) SetApproveBuild(v string) {
func (r *Repo) String() string {
return fmt.Sprintf(`{
Active: %t,
AllowComment: %t,
AllowDeploy: %t,
AllowPull: %t,
AllowPush: %t,
AllowTag: %t,
AllowEvents: %s,
ApproveBuild: %s,
Branch: %s,
Expand All @@ -794,11 +644,6 @@ func (r *Repo) String() string {
Visibility: %s,
}`,
r.GetActive(),
r.GetAllowComment(),
r.GetAllowDeploy(),
r.GetAllowPull(),
r.GetAllowPush(),
r.GetAllowTag(),
r.GetAllowEvents().List(),
r.GetApproveBuild(),
r.GetBranch(),
Expand Down
Loading

0 comments on commit 9b43c70

Please sign in to comment.