diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-06 16:25:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-06 16:25:50 +0800 |
commit | 0109229928d8603ebedc2364943538f788635370 (patch) | |
tree | a5a1909bb4a1780a372751db1928a7e635242248 /modules/notification/webhook | |
parent | 6d42add37f6120f9fa6b4f2f32f6ee316c621d41 (diff) | |
download | gitea-0109229928d8603ebedc2364943538f788635370.tar.gz gitea-0109229928d8603ebedc2364943538f788635370.zip |
Move release webhook to notification (#8817)
* Move release webhook to notification
* Extract release webhook method
* fix bug
* fix import
Diffstat (limited to 'modules/notification/webhook')
-rw-r--r-- | modules/notification/webhook/webhook.go | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go index 6eb03d3ebc..8059ec1c00 100644 --- a/modules/notification/webhook/webhook.go +++ b/modules/notification/webhook/webhook.go @@ -11,7 +11,6 @@ import ( "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/webhook" webhook_module "code.gitea.io/gitea/modules/webhook" ) @@ -289,7 +288,7 @@ func (m *webhookNotifier) NotifyNewPullRequest(pull *models.PullRequest) { } mode, _ := models.AccessLevel(pull.Issue.Poster, pull.Issue.Repo) - if err := webhook.PrepareWebhooks(pull.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{ + if err := webhook_module.PrepareWebhooks(pull.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{ Action: api.HookIssueOpened, Index: pull.Issue.Index, PullRequest: pull.APIFormat(), @@ -548,7 +547,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review log.Error("models.AccessLevel: %v", err) return } - if err := webhook.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{ + if err := webhook_module.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{ Action: api.HookIssueSynchronized, Index: review.Issue.Index, PullRequest: pr.APIFormat(), @@ -627,3 +626,32 @@ func (m *webhookNotifier) NotifyDeleteRef(pusher *models.User, repo *models.Repo log.Error("PrepareWebhooks.(delete branch): %v", err) } } + +func sendReleaseHook(doer *models.User, rel *models.Release, action api.HookReleaseAction) { + if err := rel.LoadAttributes(); err != nil { + log.Error("LoadAttributes: %v", err) + return + } + + mode, _ := models.AccessLevel(rel.Publisher, rel.Repo) + if err := webhook_module.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{ + Action: action, + Release: rel.APIFormat(), + Repository: rel.Repo.APIFormat(mode), + Sender: rel.Publisher.APIFormat(), + }); err != nil { + log.Error("PrepareWebhooks: %v", err) + } +} + +func (m *webhookNotifier) NotifyNewRelease(rel *models.Release) { + sendReleaseHook(rel.Publisher, rel, api.HookReleasePublished) +} + +func (m *webhookNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) { + sendReleaseHook(doer, rel, api.HookReleaseUpdated) +} + +func (m *webhookNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) { + sendReleaseHook(doer, rel, api.HookReleaseDeleted) +} |