diff options
author | 6543 <6543@obermui.de> | 2020-12-25 09:59:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-25 11:59:32 +0200 |
commit | a19447aed128ecadfcd938d6a80cd4951af1f4ce (patch) | |
tree | 6312bf946d601aab29731645a4777feeaea66036 /routers/api/v1/utils | |
parent | 04ae0f2f3f4556c6d0b4adc5f2cffd0cc7d25151 (diff) | |
download | gitea-a19447aed128ecadfcd938d6a80cd4951af1f4ce.tar.gz gitea-a19447aed128ecadfcd938d6a80cd4951af1f4ce.zip |
migrate from com.* to alternatives (#14103)
* remove github.com/unknwon/com from models
* dont use "com.ToStr()"
* replace "com.ToStr" with "fmt.Sprint" where its easy to do
* more refactor
* fix test
* just "proxy" Copy func for now
* as per @lunny
Diffstat (limited to 'routers/api/v1/utils')
-rw-r--r-- | routers/api/v1/utils/hook.go | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index 8decc5cf43..b0ce40b9fb 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -14,10 +14,9 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/routers/utils" "code.gitea.io/gitea/services/webhook" - - "github.com/unknwon/com" ) // GetOrgHook get an organization's webhook. If there is an error, write to @@ -89,11 +88,11 @@ func AddRepoHook(ctx *context.APIContext, form *api.CreateHookOption) { } func issuesHook(events []string, event string) bool { - return com.IsSliceContainsStr(events, event) || com.IsSliceContainsStr(events, string(models.HookEventIssues)) + return util.IsStringInSlice(event, events, true) || util.IsStringInSlice(string(models.HookEventIssues), events, true) } func pullHook(events []string, event string) bool { - return com.IsSliceContainsStr(events, event) || com.IsSliceContainsStr(events, string(models.HookEventPullRequest)) + return util.IsStringInSlice(event, events, true) || util.IsStringInSlice(string(models.HookEventPullRequest), events, true) } // addHook add the hook specified by `form`, `orgID` and `repoID`. If there is @@ -112,15 +111,15 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID HookEvent: &models.HookEvent{ ChooseEvents: true, HookEvents: models.HookEvents{ - Create: com.IsSliceContainsStr(form.Events, string(models.HookEventCreate)), - Delete: com.IsSliceContainsStr(form.Events, string(models.HookEventDelete)), - Fork: com.IsSliceContainsStr(form.Events, string(models.HookEventFork)), + Create: util.IsStringInSlice(string(models.HookEventCreate), form.Events, true), + Delete: util.IsStringInSlice(string(models.HookEventDelete), form.Events, true), + Fork: util.IsStringInSlice(string(models.HookEventFork), form.Events, true), Issues: issuesHook(form.Events, "issues_only"), IssueAssign: issuesHook(form.Events, string(models.HookEventIssueAssign)), IssueLabel: issuesHook(form.Events, string(models.HookEventIssueLabel)), IssueMilestone: issuesHook(form.Events, string(models.HookEventIssueMilestone)), IssueComment: issuesHook(form.Events, string(models.HookEventIssueComment)), - Push: com.IsSliceContainsStr(form.Events, string(models.HookEventPush)), + Push: util.IsStringInSlice(string(models.HookEventPush), form.Events, true), PullRequest: pullHook(form.Events, "pull_request_only"), PullRequestAssign: pullHook(form.Events, string(models.HookEventPullRequestAssign)), PullRequestLabel: pullHook(form.Events, string(models.HookEventPullRequestLabel)), @@ -128,8 +127,8 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID PullRequestComment: pullHook(form.Events, string(models.HookEventPullRequestComment)), PullRequestReview: pullHook(form.Events, "pull_request_review"), PullRequestSync: pullHook(form.Events, string(models.HookEventPullRequestSync)), - Repository: com.IsSliceContainsStr(form.Events, string(models.HookEventRepository)), - Release: com.IsSliceContainsStr(form.Events, string(models.HookEventRelease)), + Repository: util.IsStringInSlice(string(models.HookEventRepository), form.Events, true), + Release: util.IsStringInSlice(string(models.HookEventRelease), form.Events, true), }, BranchFilter: form.BranchFilter, }, @@ -244,18 +243,18 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *models.Webho w.PushOnly = false w.SendEverything = false w.ChooseEvents = true - w.Create = com.IsSliceContainsStr(form.Events, string(models.HookEventCreate)) - w.Push = com.IsSliceContainsStr(form.Events, string(models.HookEventPush)) - w.PullRequest = com.IsSliceContainsStr(form.Events, string(models.HookEventPullRequest)) - w.Create = com.IsSliceContainsStr(form.Events, string(models.HookEventCreate)) - w.Delete = com.IsSliceContainsStr(form.Events, string(models.HookEventDelete)) - w.Fork = com.IsSliceContainsStr(form.Events, string(models.HookEventFork)) - w.Issues = com.IsSliceContainsStr(form.Events, string(models.HookEventIssues)) - w.IssueComment = com.IsSliceContainsStr(form.Events, string(models.HookEventIssueComment)) - w.Push = com.IsSliceContainsStr(form.Events, string(models.HookEventPush)) - w.PullRequest = com.IsSliceContainsStr(form.Events, string(models.HookEventPullRequest)) - w.Repository = com.IsSliceContainsStr(form.Events, string(models.HookEventRepository)) - w.Release = com.IsSliceContainsStr(form.Events, string(models.HookEventRelease)) + w.Create = util.IsStringInSlice(string(models.HookEventCreate), form.Events, true) + w.Push = util.IsStringInSlice(string(models.HookEventPush), form.Events, true) + w.PullRequest = util.IsStringInSlice(string(models.HookEventPullRequest), form.Events, true) + w.Create = util.IsStringInSlice(string(models.HookEventCreate), form.Events, true) + w.Delete = util.IsStringInSlice(string(models.HookEventDelete), form.Events, true) + w.Fork = util.IsStringInSlice(string(models.HookEventFork), form.Events, true) + w.Issues = util.IsStringInSlice(string(models.HookEventIssues), form.Events, true) + w.IssueComment = util.IsStringInSlice(string(models.HookEventIssueComment), form.Events, true) + w.Push = util.IsStringInSlice(string(models.HookEventPush), form.Events, true) + w.PullRequest = util.IsStringInSlice(string(models.HookEventPullRequest), form.Events, true) + w.Repository = util.IsStringInSlice(string(models.HookEventRepository), form.Events, true) + w.Release = util.IsStringInSlice(string(models.HookEventRelease), form.Events, true) w.BranchFilter = form.BranchFilter if err := w.UpdateEvent(); err != nil { |