diff --git a/applicationset/webhook/webhook.go b/applicationset/webhook/webhook.go index aef9a562377e6..28f00b1cf675f 100644 --- a/applicationset/webhook/webhook.go +++ b/applicationset/webhook/webhook.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" "regexp" + "slices" "strconv" "strings" "sync" @@ -234,7 +235,7 @@ func getPRGeneratorInfo(payload any) *prGeneratorInfo { var info prGeneratorInfo switch payload := payload.(type) { case github.PullRequestPayload: - if !isAllowedGithubPullRequestAction(payload.Action) { + if !slices.Contains(githubAllowedPullRequestActions, payload.Action) { return nil } @@ -250,7 +251,7 @@ func getPRGeneratorInfo(payload any) *prGeneratorInfo { APIRegexp: apiRegexp, } case gitlab.MergeRequestEventPayload: - if !isAllowedGitlabPullRequestAction(payload.ObjectAttributes.Action) { + if !slices.Contains(gitlabAllowedPullRequestActions, payload.ObjectAttributes.Action) { return nil } @@ -266,7 +267,7 @@ func getPRGeneratorInfo(payload any) *prGeneratorInfo { APIHostname: urlObj.Hostname(), } case azuredevops.GitPullRequestEvent: - if !isAllowedAzureDevOpsPullRequestAction(string(payload.EventType)) { + if !slices.Contains(azuredevopsAllowedPullRequestActions, string(payload.EventType)) { return nil } @@ -311,33 +312,6 @@ var azuredevopsAllowedPullRequestActions = []string{ "git.pullrequest.updated", } -func isAllowedGithubPullRequestAction(action string) bool { - for _, allow := range githubAllowedPullRequestActions { - if allow == action { - return true - } - } - return false -} - -func isAllowedGitlabPullRequestAction(action string) bool { - for _, allow := range gitlabAllowedPullRequestActions { - if allow == action { - return true - } - } - return false -} - -func isAllowedAzureDevOpsPullRequestAction(action string) bool { - for _, allow := range azuredevopsAllowedPullRequestActions { - if allow == action { - return true - } - } - return false -} - func shouldRefreshGitGenerator(gen *v1alpha1.GitGenerator, info *gitGeneratorInfo) bool { if gen == nil || info == nil { return false