mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	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
This commit is contained in:
		@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user