Rename HookQueue to hookQueue (#8778)

* Rename HookQueue to hookQueue

* fix lint
tokarchuk/v1.17
Lunny Xiao 5 years ago committed by GitHub
parent 4b8d9e58c5
commit f518fe6662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      modules/notification/webhook/webhook.go
  2. 4
      modules/repofiles/action.go
  3. 4
      modules/webhook/deliver.go
  4. 18
      modules/webhook/webhook.go
  5. 2
      routers/api/v1/repo/hook.go
  6. 2
      routers/repo/pull.go
  7. 1
      routers/repo/webhook.go
  8. 2
      services/milestone/milestone.go
  9. 4
      services/mirror/sync.go
  10. 2
      services/pull/merge.go
  11. 3
      services/pull/pull.go
  12. 9
      services/pull/review.go
  13. 6
      services/release/release.go

@ -62,8 +62,6 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *model
} }
if err != nil { if err != nil {
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
go webhook_module.HookQueue.Add(issue.RepoID)
} }
} }
@ -78,8 +76,6 @@ func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo
Sender: doer.APIFormat(), Sender: doer.APIFormat(),
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err) log.Error("PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err)
} else {
go webhook_module.HookQueue.Add(oldRepo.ID)
} }
u := repo.MustOwner() u := repo.MustOwner()
@ -93,8 +89,6 @@ func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo
Sender: doer.APIFormat(), Sender: doer.APIFormat(),
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
} else {
go webhook_module.HookQueue.Add(repo.ID)
} }
} }
} }
@ -109,8 +103,6 @@ func (m *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.Us
Sender: doer.APIFormat(), Sender: doer.APIFormat(),
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
} else {
go webhook_module.HookQueue.Add(repo.ID)
} }
} }
} }
@ -127,7 +119,6 @@ func (m *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
} }
go webhook_module.HookQueue.Add(repo.ID)
} }
} }
@ -175,8 +166,6 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *mo
return return
} }
} }
go webhook_module.HookQueue.Add(issue.RepoID)
} }
func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
@ -217,8 +206,6 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *model
if err != nil { if err != nil {
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
go webhook_module.HookQueue.Add(issue.RepoID)
} }
} }
@ -259,8 +246,6 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *mode
} }
if err != nil { if err != nil {
log.Error("PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err) log.Error("PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err)
} else {
go webhook_module.HookQueue.Add(issue.Repo.ID)
} }
} }
@ -274,8 +259,6 @@ func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue) {
Sender: issue.Poster.APIFormat(), Sender: issue.Poster.APIFormat(),
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks: %v", err) log.Error("PrepareWebhooks: %v", err)
} else {
go webhook_module.HookQueue.Add(issue.RepoID)
} }
} }
@ -312,8 +295,6 @@ func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *mod
} }
if err != nil { if err != nil {
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
go webhook_module.HookQueue.Add(issue.RepoID)
} }
} }
@ -347,8 +328,6 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comme
IsPull: c.Issue.IsPull, IsPull: c.Issue.IsPull,
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks [comment_id: %d]: %v", c.ID, err) log.Error("PrepareWebhooks [comment_id: %d]: %v", c.ID, err)
} else {
go webhook_module.HookQueue.Add(c.Issue.Repo.ID)
} }
} }
@ -364,8 +343,6 @@ func (m *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *mode
IsPull: issue.IsPull, IsPull: issue.IsPull,
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
} else {
go webhook_module.HookQueue.Add(repo.ID)
} }
} }
@ -395,8 +372,6 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models
IsPull: comment.Issue.IsPull, IsPull: comment.Issue.IsPull,
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
} else {
go webhook_module.HookQueue.Add(comment.Issue.Repo.ID)
} }
} }
@ -442,7 +417,5 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *mode
} }
if err != nil { if err != nil {
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
go webhook_module.HookQueue.Add(issue.RepoID)
} }
} }

@ -112,10 +112,6 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
return fmt.Errorf("NotifyWatchers: %v", err) return fmt.Errorf("NotifyWatchers: %v", err)
} }
defer func() {
go webhook.HookQueue.Add(repo.ID)
}()
apiPusher := pusher.APIFormat() apiPusher := pusher.APIFormat()
apiRepo := repo.APIFormat(models.AccessModeNone) apiRepo := repo.APIFormat(models.AccessModeNone)

@ -159,9 +159,9 @@ func DeliverHooks() {
} }
// Start listening on new hook requests. // Start listening on new hook requests.
for repoIDStr := range HookQueue.Queue() { for repoIDStr := range hookQueue.Queue() {
log.Trace("DeliverHooks [repo_id: %v]", repoIDStr) log.Trace("DeliverHooks [repo_id: %v]", repoIDStr)
HookQueue.Remove(repoIDStr) hookQueue.Remove(repoIDStr)
repoID, err := com.StrTo(repoIDStr).Int64() repoID, err := com.StrTo(repoIDStr).Int64()
if err != nil { if err != nil {

@ -20,8 +20,8 @@ import (
"github.com/gobwas/glob" "github.com/gobwas/glob"
) )
// HookQueue is a global queue of web hooks // hookQueue is a global queue of web hooks
var HookQueue = sync.NewUniqueQueue(setting.Webhook.QueueLength) var hookQueue = sync.NewUniqueQueue(setting.Webhook.QueueLength)
// getPayloadBranch returns branch for hook event, if applicable. // getPayloadBranch returns branch for hook event, if applicable.
func getPayloadBranch(p api.Payloader) string { func getPayloadBranch(p api.Payloader) string {
@ -44,7 +44,12 @@ func getPayloadBranch(p api.Payloader) string {
// PrepareWebhook adds special webhook to task queue for given payload. // PrepareWebhook adds special webhook to task queue for given payload.
func PrepareWebhook(w *models.Webhook, repo *models.Repository, event models.HookEventType, p api.Payloader) error { func PrepareWebhook(w *models.Webhook, repo *models.Repository, event models.HookEventType, p api.Payloader) error {
return prepareWebhook(w, repo, event, p) if err := prepareWebhook(w, repo, event, p); err != nil {
return err
}
go hookQueue.Add(repo.ID)
return nil
} }
func checkBranch(w *models.Webhook, branch string) bool { func checkBranch(w *models.Webhook, branch string) bool {
@ -147,7 +152,12 @@ func prepareWebhook(w *models.Webhook, repo *models.Repository, event models.Hoo
// PrepareWebhooks adds new webhooks to task queue for given payload. // PrepareWebhooks adds new webhooks to task queue for given payload.
func PrepareWebhooks(repo *models.Repository, event models.HookEventType, p api.Payloader) error { func PrepareWebhooks(repo *models.Repository, event models.HookEventType, p api.Payloader) error {
return prepareWebhooks(repo, event, p) if err := prepareWebhooks(repo, event, p); err != nil {
return err
}
go hookQueue.Add(repo.ID)
return nil
} }
func prepareWebhooks(repo *models.Repository, event models.HookEventType, p api.Payloader) error { func prepareWebhooks(repo *models.Repository, event models.HookEventType, p api.Payloader) error {

@ -137,7 +137,7 @@ func TestHook(ctx *context.APIContext) {
ctx.Error(500, "PrepareWebhook: ", err) ctx.Error(500, "PrepareWebhook: ", err)
return return
} }
go webhook.HookQueue.Add(ctx.Repo.Repository.ID)
ctx.Status(204) ctx.Status(204)
} }

@ -23,7 +23,6 @@ import (
"code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/gitdiff" "code.gitea.io/gitea/services/gitdiff"
pull_service "code.gitea.io/gitea/services/pull" pull_service "code.gitea.io/gitea/services/pull"
repo_service "code.gitea.io/gitea/services/repository" repo_service "code.gitea.io/gitea/services/repository"
@ -824,7 +823,6 @@ func TriggerTask(ctx *context.Context) {
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name) log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
go webhook.HookQueue.Add(repo.ID)
go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true) go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true)
ctx.Status(202) ctx.Status(202)
} }

@ -869,7 +869,6 @@ func TestWebhook(ctx *context.Context) {
ctx.Flash.Error("PrepareWebhook: " + err.Error()) ctx.Flash.Error("PrepareWebhook: " + err.Error())
ctx.Status(500) ctx.Status(500)
} else { } else {
go webhook.HookQueue.Add(ctx.Repo.Repository.ID)
ctx.Flash.Info(ctx.Tr("repo.settings.webhook.test_delivery_success")) ctx.Flash.Info(ctx.Tr("repo.settings.webhook.test_delivery_success"))
ctx.Status(200) ctx.Status(200)
} }

@ -53,8 +53,6 @@ func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneI
} }
if err != nil { if err != nil {
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
go webhook.HookQueue.Add(issue.RepoID)
} }
return nil return nil
} }

@ -28,10 +28,6 @@ func syncAction(opType models.ActionType, repo *models.Repository, refName strin
return fmt.Errorf("notifyWatchers: %v", err) return fmt.Errorf("notifyWatchers: %v", err)
} }
defer func() {
go webhook.HookQueue.Add(repo.ID)
}()
return nil return nil
} }

@ -369,8 +369,6 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
Sender: doer.APIFormat(), Sender: doer.APIFormat(),
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks: %v", err) log.Error("PrepareWebhooks: %v", err)
} else {
go webhook.HookQueue.Add(pr.Issue.Repo.ID)
} }
return nil return nil

@ -50,8 +50,6 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6
Sender: pull.Poster.APIFormat(), Sender: pull.Poster.APIFormat(),
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks: %v", err) log.Error("PrepareWebhooks: %v", err)
} else {
go webhook.HookQueue.Add(repo.ID)
} }
return nil return nil
@ -125,7 +123,6 @@ func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSy
log.Error("PrepareWebhooks [pull_id: %v]: %v", pr.ID, err) log.Error("PrepareWebhooks [pull_id: %v]: %v", pr.ID, err)
continue continue
} }
go webhook.HookQueue.Add(pr.Issue.Repo.ID)
} }
} }

@ -56,7 +56,7 @@ func reviewHook(review *models.Review) error {
if err != nil { if err != nil {
return err return err
} }
if err := webhook.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{ return webhook.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{
Action: api.HookIssueSynchronized, Action: api.HookIssueSynchronized,
Index: review.Issue.Index, Index: review.Issue.Index,
PullRequest: pr.APIFormat(), PullRequest: pr.APIFormat(),
@ -66,10 +66,5 @@ func reviewHook(review *models.Review) error {
Type: string(reviewHookType), Type: string(reviewHookType),
Content: review.Content, Content: review.Content,
}, },
}); err != nil { })
return err
}
go webhook.HookQueue.Add(review.Issue.Repo.ID)
return nil
} }

@ -92,8 +92,6 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
Sender: rel.Publisher.APIFormat(), Sender: rel.Publisher.APIFormat(),
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks: %v", err) log.Error("PrepareWebhooks: %v", err)
} else {
go webhook.HookQueue.Add(rel.Repo.ID)
} }
} }
} }
@ -129,8 +127,6 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea
Sender: doer.APIFormat(), Sender: doer.APIFormat(),
}); err1 != nil { }); err1 != nil {
log.Error("PrepareWebhooks: %v", err) log.Error("PrepareWebhooks: %v", err)
} else {
go webhook.HookQueue.Add(rel.Repo.ID)
} }
return err return err
@ -195,8 +191,6 @@ func DeleteReleaseByID(id int64, doer *models.User, delTag bool) error {
Sender: doer.APIFormat(), Sender: doer.APIFormat(),
}); err != nil { }); err != nil {
log.Error("PrepareWebhooks: %v", err) log.Error("PrepareWebhooks: %v", err)
} else {
go webhook.HookQueue.Add(rel.Repo.ID)
} }
return nil return nil

Loading…
Cancel
Save