Skip to content

Commit

Permalink
remove repo version of 'Allowed'
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Jan 5, 2024
1 parent dba7955 commit bdaa6c0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 67 deletions.
32 changes: 0 additions & 32 deletions library/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package library
import (
"fmt"
"strings"

"github.com/go-vela/types/constants"
)

// Repo is the library representation of a repo.
Expand Down Expand Up @@ -764,36 +762,6 @@ func (r *Repo) SetApproveBuild(v string) {
r.ApproveBuild = &v
}

// EventAllowed determines whether or not an event is allowed based on the repository settings.
func (r *Repo) EventAllowed(event, action string) (allowed bool) {
allowed = false

if len(action) > 0 {
event = event + ":" + action
}

switch event {
case constants.EventPush:
allowed = r.GetAllowEvents().GetPush().GetBranch()
case constants.EventPull + ":" + constants.ActionOpened:
allowed = r.GetAllowEvents().GetPullRequest().GetOpened()
case constants.EventPull + ":" + constants.ActionSynchronize:
allowed = r.GetAllowEvents().GetPullRequest().GetSynchronize()
case constants.EventPull + ":" + constants.ActionEdited:
allowed = r.GetAllowEvents().GetPullRequest().GetEdited()
case constants.EventTag:
allowed = r.GetAllowEvents().GetPush().GetTag()
case constants.EventComment + ":" + constants.ActionCreated:
allowed = r.GetAllowEvents().GetComment().GetCreated()
case constants.EventComment + ":" + constants.ActionEdited:
allowed = r.GetAllowEvents().GetComment().GetEdited()
case constants.EventDeploy:
allowed = r.GetAllowEvents().GetDeployment().GetCreated()
}

return
}

// String implements the Stringer interface for the Repo type.
//
//nolint:dupl // ignore duplicate with test func
Expand Down
35 changes: 0 additions & 35 deletions library/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,41 +331,6 @@ func TestLibrary_Repo_Setters(t *testing.T) {
}
}

func TestLibrary_Repo_EventAllowed(t *testing.T) {
// setup tests
tests := []struct {
repo *Repo
event string
action string
want bool
}{
{
repo: testRepo(),
event: "pull_request",
action: "opened",
want: true,
},
{
repo: testRepo(),
event: "deployment",
want: false,
},
{
repo: new(Repo),
event: "push",
want: false,
},
}

for _, test := range tests {
got := test.repo.EventAllowed(test.event, test.action)

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

func TestLibrary_Repo_String(t *testing.T) {
// setup types
r := testRepo()
Expand Down

0 comments on commit bdaa6c0

Please sign in to comment.