diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-02 10:35:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-02 10:35:12 +0800 |
commit | f518fe66620bcb60a5251befca116f8caa48ee42 (patch) | |
tree | 0522717b649d6d5148e11e122048cf8629aafcfb /modules | |
parent | 4b8d9e58c58b8952e86e7e5f90a0a8e0480e1de1 (diff) | |
download | gitea-f518fe66620bcb60a5251befca116f8caa48ee42.tar.gz gitea-f518fe66620bcb60a5251befca116f8caa48ee42.zip |
Rename HookQueue to hookQueue (#8778)
* Rename HookQueue to hookQueue
* fix lint
Diffstat (limited to 'modules')
-rw-r--r-- | modules/notification/webhook/webhook.go | 27 | ||||
-rw-r--r-- | modules/repofiles/action.go | 4 | ||||
-rw-r--r-- | modules/webhook/deliver.go | 4 | ||||
-rw-r--r-- | modules/webhook/webhook.go | 18 |
4 files changed, 16 insertions, 37 deletions
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go index 8d98ff0f9e..259b6352ab 100644 --- a/modules/notification/webhook/webhook.go +++ b/modules/notification/webhook/webhook.go @@ -62,8 +62,6 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *model } if err != nil { 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(), }); err != nil { log.Error("PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err) - } else { - go webhook_module.HookQueue.Add(oldRepo.ID) } u := repo.MustOwner() @@ -93,8 +89,6 @@ func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo Sender: doer.APIFormat(), }); err != nil { 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(), }); err != nil { 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 { 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 } } - - go webhook_module.HookQueue.Add(issue.RepoID) } 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 { 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 { 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(), }); err != nil { 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 { 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, }); err != nil { 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, }); err != nil { 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, }); err != nil { 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 { log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) - } else { - go webhook_module.HookQueue.Add(issue.RepoID) } } diff --git a/modules/repofiles/action.go b/modules/repofiles/action.go index addbdb464c..79f6406c53 100644 --- a/modules/repofiles/action.go +++ b/modules/repofiles/action.go @@ -112,10 +112,6 @@ func CommitRepoAction(opts CommitRepoActionOptions) error { return fmt.Errorf("NotifyWatchers: %v", err) } - defer func() { - go webhook.HookQueue.Add(repo.ID) - }() - apiPusher := pusher.APIFormat() apiRepo := repo.APIFormat(models.AccessModeNone) diff --git a/modules/webhook/deliver.go b/modules/webhook/deliver.go index 1b3da25d5e..54f20171fa 100644 --- a/modules/webhook/deliver.go +++ b/modules/webhook/deliver.go @@ -159,9 +159,9 @@ func DeliverHooks() { } // Start listening on new hook requests. - for repoIDStr := range HookQueue.Queue() { + for repoIDStr := range hookQueue.Queue() { log.Trace("DeliverHooks [repo_id: %v]", repoIDStr) - HookQueue.Remove(repoIDStr) + hookQueue.Remove(repoIDStr) repoID, err := com.StrTo(repoIDStr).Int64() if err != nil { diff --git a/modules/webhook/webhook.go b/modules/webhook/webhook.go index da88c58c88..623a475df9 100644 --- a/modules/webhook/webhook.go +++ b/modules/webhook/webhook.go @@ -20,8 +20,8 @@ import ( "github.com/gobwas/glob" ) -// HookQueue is a global queue of web hooks -var HookQueue = sync.NewUniqueQueue(setting.Webhook.QueueLength) +// hookQueue is a global queue of web hooks +var hookQueue = sync.NewUniqueQueue(setting.Webhook.QueueLength) // getPayloadBranch returns branch for hook event, if applicable. 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. 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 { @@ -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. 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 { |