"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"
)
}
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(),
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(),
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)
+}
"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 {
}
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
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
}
}
}
- 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
}