summaryrefslogtreecommitdiffstats
path: root/services/release
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-11-06 16:25:50 +0800
committerGitHub <noreply@github.com>2019-11-06 16:25:50 +0800
commit0109229928d8603ebedc2364943538f788635370 (patch)
treea5a1909bb4a1780a372751db1928a7e635242248 /services/release
parent6d42add37f6120f9fa6b4f2f32f6ee316c621d41 (diff)
downloadgitea-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 'services/release')
-rw-r--r--services/release/release.go42
1 files changed, 4 insertions, 38 deletions
diff --git a/services/release/release.go b/services/release/release.go
index a3f027c949..681e8c0d9a 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -12,10 +12,9 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/process"
- api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
- "code.gitea.io/gitea/modules/webhook"
)
func createTag(gitRepo *git.Repository, rel *models.Release) error {
@@ -81,19 +80,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
}
if !rel.IsDraft {
- if err := rel.LoadAttributes(); err != nil {
- log.Error("LoadAttributes: %v", err)
- } else {
- mode, _ := models.AccessLevel(rel.Publisher, rel.Repo)
- if err := webhook.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
- Action: api.HookReleasePublished,
- Release: rel.APIFormat(),
- Repository: rel.Repo.APIFormat(mode),
- Sender: rel.Publisher.APIFormat(),
- }); err != nil {
- log.Error("PrepareWebhooks: %v", err)
- }
- }
+ notification.NotifyNewRelease(rel)
}
return nil
@@ -114,20 +101,7 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea
log.Error("AddReleaseAttachments: %v", err)
}
- if err = rel.LoadAttributes(); err != nil {
- return err
- }
-
- // even if attachments added failed, hooks will be still triggered
- mode, _ := models.AccessLevel(doer, rel.Repo)
- if err1 := webhook.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
- Action: api.HookReleaseUpdated,
- Release: rel.APIFormat(),
- Repository: rel.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
- }); err1 != nil {
- log.Error("PrepareWebhooks: %v", err)
- }
+ notification.NotifyUpdateRelease(doer, rel)
return err
}
@@ -183,15 +157,7 @@ func DeleteReleaseByID(id int64, doer *models.User, delTag bool) error {
}
}
- mode, _ := models.AccessLevel(doer, rel.Repo)
- if err := webhook.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
- Action: api.HookReleaseDeleted,
- Release: rel.APIFormat(),
- Repository: rel.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
- }); err != nil {
- log.Error("PrepareWebhooks: %v", err)
- }
+ notification.NotifyDeleteRelease(doer, rel)
return nil
}