Skip to content

Commit

Permalink
adding a delete event type
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire.Nicholas authored and Claire.Nicholas committed Aug 9, 2023
1 parent 817025c commit a2f5580
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions constants/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const (
// EventPush defines the event type for build and repo push events.
EventPush = "push"

// EventDelete defines the event type for build and repo delete events.
EventDelete = "delete"

// EventRepository defines the general event type for repo management.
EventRepository = "repository"

Expand Down
3 changes: 3 additions & 0 deletions database/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type Repo struct {
Active sql.NullBool `sql:"active"`
AllowPull sql.NullBool `sql:"allow_pull"`
AllowPush sql.NullBool `sql:"allow_push"`
AllowDelete sql.NullBool `sql:"allow_delete"`
AllowDeploy sql.NullBool `sql:"allow_deploy"`
AllowTag sql.NullBool `sql:"allow_tag"`
AllowComment sql.NullBool `sql:"allow_comment"`
Expand Down Expand Up @@ -227,6 +228,7 @@ func (r *Repo) ToLibrary() *library.Repo {
repo.SetActive(r.Active.Bool)
repo.SetAllowPull(r.AllowPull.Bool)
repo.SetAllowPush(r.AllowPush.Bool)
repo.SetAllowDelete(r.AllowDelete.Bool)
repo.SetAllowDeploy(r.AllowDeploy.Bool)
repo.SetAllowTag(r.AllowTag.Bool)
repo.SetAllowComment(r.AllowComment.Bool)
Expand Down Expand Up @@ -322,6 +324,7 @@ func RepoFromLibrary(r *library.Repo) *Repo {
Active: sql.NullBool{Bool: r.GetActive(), Valid: true},
AllowPull: sql.NullBool{Bool: r.GetAllowPull(), Valid: true},
AllowPush: sql.NullBool{Bool: r.GetAllowPush(), Valid: true},
AllowDelete: sql.NullBool{Bool: r.GetAllowDelete(), 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},
Expand Down
3 changes: 3 additions & 0 deletions database/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func TestDatabase_Repo_ToLibrary(t *testing.T) {
want.SetActive(true)
want.SetAllowPull(false)
want.SetAllowPush(true)
want.SetAllowDelete(true)
want.SetAllowDeploy(false)
want.SetAllowTag(false)
want.SetAllowComment(false)
Expand Down Expand Up @@ -327,6 +328,7 @@ func TestDatabase_RepoFromLibrary(t *testing.T) {
r.SetActive(true)
r.SetAllowPull(false)
r.SetAllowPush(true)
r.SetAllowDelete(true)
r.SetAllowDeploy(false)
r.SetAllowTag(false)
r.SetAllowComment(false)
Expand Down Expand Up @@ -366,6 +368,7 @@ func testRepo() *Repo {
Active: sql.NullBool{Bool: true, Valid: true},
AllowPull: sql.NullBool{Bool: false, Valid: true},
AllowPush: sql.NullBool{Bool: true, Valid: true},
AllowDelete: 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},
Expand Down
2 changes: 2 additions & 0 deletions item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func TestTypes_ToItem(t *testing.T) {
Active: &booL,
AllowPull: &booL,
AllowPush: &booL,
AllowDelete: &booL,
AllowDeploy: &booL,
AllowTag: &booL,
}
Expand Down Expand Up @@ -149,6 +150,7 @@ func TestTypes_ToItem(t *testing.T) {
Active: &booL,
AllowPull: &booL,
AllowPush: &booL,
AllowDelete: &booL,
AllowDeploy: &booL,
AllowTag: &booL,
},
Expand Down
31 changes: 31 additions & 0 deletions library/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Repo struct {
Active *bool `json:"active,omitempty"`
AllowPull *bool `json:"allow_pull,omitempty"`
AllowPush *bool `json:"allow_push,omitempty"`
AllowDelete *bool `json:"allow_delete,omitempty"`
AllowDeploy *bool `json:"allow_deploy,omitempty"`
AllowTag *bool `json:"allow_tag,omitempty"`
AllowComment *bool `json:"allow_comment,omitempty"`
Expand All @@ -48,6 +49,7 @@ func (r *Repo) Environment() map[string]string {
"VELA_REPO_ALLOW_DEPLOY": ToString(r.GetAllowDeploy()),
"VELA_REPO_ALLOW_PULL": ToString(r.GetAllowPull()),
"VELA_REPO_ALLOW_PUSH": ToString(r.GetAllowPush()),
"VELA_REPO_ALLOW_DELETE": ToString(r.GetAllowDelete()),
"VELA_REPO_ALLOW_TAG": ToString(r.GetAllowTag()),
"VELA_REPO_BRANCH": ToString(r.GetBranch()),
"VELA_REPO_TOPICS": strings.Join(r.GetTopics()[:], ","),
Expand All @@ -69,6 +71,7 @@ func (r *Repo) Environment() map[string]string {
"REPOSITORY_ALLOW_DEPLOY": ToString(r.GetAllowDeploy()),
"REPOSITORY_ALLOW_PULL": ToString(r.GetAllowPull()),
"REPOSITORY_ALLOW_PUSH": ToString(r.GetAllowPush()),
"REPOSITORY_ALLOW_DELETE": ToString(r.GetAllowDelete()),
"REPOSITORY_ALLOW_TAG": ToString(r.GetAllowTag()),
"REPOSITORY_BRANCH": ToString(r.GetBranch()),
"REPOSITORY_CLONE": ToString(r.GetClone()),
Expand Down Expand Up @@ -330,6 +333,19 @@ func (r *Repo) GetAllowPush() bool {
return *r.AllowPush
}

// 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 AllowPush field is nil
if r == nil || r.AllowDelete == nil {
return false
}

return *r.AllowDelete
}

// GetAllowDeploy returns the AllowDeploy field.
//
// When the provided Repo type is nil, or the field within
Expand Down Expand Up @@ -642,6 +658,19 @@ func (r *Repo) SetAllowPush(v bool) {
r.AllowPush = &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
}

// SetAllowDeploy sets the AllowDeploy field.
//
// When the provided Repo type is nil, it
Expand Down Expand Up @@ -715,6 +744,7 @@ func (r *Repo) String() string {
AllowDeploy: %t,
AllowPull: %t,
AllowPush: %t,
AllowDelete: %t,
AllowTag: %t,
Branch: %s,
BuildLimit: %d,
Expand All @@ -739,6 +769,7 @@ func (r *Repo) String() string {
r.GetAllowDeploy(),
r.GetAllowPull(),
r.GetAllowPush(),
r.GetAllowDelete(),
r.GetAllowTag(),
r.GetBranch(),
r.GetBuildLimit(),
Expand Down
12 changes: 12 additions & 0 deletions library/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func TestLibrary_Repo_Getters(t *testing.T) {
t.Errorf("GetAllowPush is %v, want %v", test.repo.GetAllowPush(), test.want.GetAllowPush())
}

if test.repo.GetAllowDelete() != test.want.GetAllowDelete() {
t.Errorf("GetAllowDelete is %v, want %v", test.repo.GetAllowDelete(), test.want.GetAllowDelete())
}

if test.repo.GetAllowDeploy() != test.want.GetAllowDeploy() {
t.Errorf("GetAllowDeploy is %v, want %v", test.repo.GetAllowDeploy(), test.want.GetAllowDeploy())
}
Expand Down Expand Up @@ -210,6 +214,7 @@ func TestLibrary_Repo_Setters(t *testing.T) {
test.repo.SetActive(test.want.GetActive())
test.repo.SetAllowPull(test.want.GetAllowPull())
test.repo.SetAllowPush(test.want.GetAllowPush())
test.repo.SetAllowDelete(test.want.GetAllowDelete())
test.repo.SetAllowDeploy(test.want.GetAllowDeploy())
test.repo.SetAllowTag(test.want.GetAllowTag())
test.repo.SetAllowComment(test.want.GetAllowComment())
Expand Down Expand Up @@ -288,6 +293,10 @@ func TestLibrary_Repo_Setters(t *testing.T) {
t.Errorf("SetAllowPush is %v, want %v", test.repo.GetAllowPush(), test.want.GetAllowPush())
}

if test.repo.GetAllowDelete() != test.want.GetAllowDelete() {
t.Errorf("SetAllowDelete is %v, want %v", test.repo.GetAllowDelete(), test.want.GetAllowDelete())
}

if test.repo.GetAllowDeploy() != test.want.GetAllowDeploy() {
t.Errorf("SetAllowDeploy is %v, want %v", test.repo.GetAllowDeploy(), test.want.GetAllowDeploy())
}
Expand Down Expand Up @@ -320,6 +329,7 @@ func TestLibrary_Repo_String(t *testing.T) {
AllowDeploy: %t,
AllowPull: %t,
AllowPush: %t,
AllowDelete: %t,
AllowTag: %t,
Branch: %s,
BuildLimit: %d,
Expand All @@ -344,6 +354,7 @@ func TestLibrary_Repo_String(t *testing.T) {
r.GetAllowDeploy(),
r.GetAllowPull(),
r.GetAllowPush(),
r.GetAllowDelete(),
r.GetAllowTag(),
r.GetBranch(),
r.GetBuildLimit(),
Expand Down Expand Up @@ -394,6 +405,7 @@ func testRepo() *Repo {
r.SetActive(true)
r.SetAllowPull(false)
r.SetAllowPush(true)
r.SetAllowDelete(true)
r.SetAllowDeploy(false)
r.SetAllowTag(false)
r.SetAllowComment(false)
Expand Down
2 changes: 2 additions & 0 deletions library/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (s *Secret) Match(from *pipeline.Container) bool {
eACL = checkEvent(events, constants.EventPush)
case constants.EventPull:
eACL = checkEvent(events, constants.EventPull)
case constants.EventDelete:
eACL = checkEvent(events, constants.EventDelete)
case constants.EventTag:
eACL = checkEvent(events, constants.EventTag)
case constants.EventDeploy:
Expand Down

0 comments on commit a2f5580

Please sign in to comment.