diff --git a/api/build/create.go b/api/build/create.go index 110f75434..9d75a4ef0 100644 --- a/api/build/create.go +++ b/api/build/create.go @@ -111,7 +111,7 @@ func CreateBuild(c *gin.Context) { } // verify repo has event configured - if !util.EventAllowed(input.GetEvent(), input.GetEventAction(), r) { + if !r.EventAllowed(input.GetEvent(), input.GetEventAction()) { retErr := fmt.Errorf("unable to create new build: %s does not have %s%s events enabled", r.GetFullName(), input.GetEvent(), ":"+input.GetEventAction()) util.HandleError(c, http.StatusBadRequest, retErr) diff --git a/api/webhook/post.go b/api/webhook/post.go index edc72f5e3..749304029 100644 --- a/api/webhook/post.go +++ b/api/webhook/post.go @@ -258,7 +258,7 @@ func PostWebhook(c *gin.Context) { } // verify the build has a valid event and the repo allows that event type - if !util.EventAllowed(b.GetEvent(), b.GetEventAction(), repo) { + if !repo.EventAllowed(b.GetEvent(), b.GetEventAction()) { retErr := fmt.Errorf("%s: %s does not have %s%s events enabled", baseErr, repo.GetFullName(), b.GetEvent(), ":"+b.GetEventAction()) util.HandleError(c, http.StatusBadRequest, retErr) diff --git a/util/util.go b/util/util.go index e81822d17..31cdd1104 100644 --- a/util/util.go +++ b/util/util.go @@ -8,7 +8,6 @@ import ( "html" "strings" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/gin-gonic/gin" @@ -131,34 +130,3 @@ func CheckAllowlist(r *library.Repo, allowlist []string) bool { return false } - -// ParseEventMask is a helper function to calculate the bit mask for -// a given event. -func EventAllowed(event, action string, r *library.Repo) (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 -}