mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-24 00:34:23 +01:00
20477a69ea
* move clearlabels from models to issue service * improve code * Apply suggestions from code review Co-Authored-By: zeripath <art27@cantab.net>
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package webhook
|
|
|
|
import (
|
|
"code.gitea.io/gitea/models"
|
|
"code.gitea.io/gitea/modules/log"
|
|
"code.gitea.io/gitea/modules/notification/base"
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
)
|
|
|
|
type webhookNotifier struct {
|
|
base.NullNotifier
|
|
}
|
|
|
|
var (
|
|
_ base.Notifier = &webhookNotifier{}
|
|
)
|
|
|
|
// NewNotifier create a new webhookNotifier notifier
|
|
func NewNotifier() base.Notifier {
|
|
return &webhookNotifier{}
|
|
}
|
|
|
|
func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
|
|
if err := issue.LoadPoster(); err != nil {
|
|
log.Error("loadPoster: %v", err)
|
|
return
|
|
}
|
|
|
|
if err := issue.LoadRepo(); err != nil {
|
|
log.Error("LoadRepo: %v", err)
|
|
return
|
|
}
|
|
|
|
mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
|
|
var err error
|
|
if issue.IsPull {
|
|
if err = issue.LoadPullRequest(); err != nil {
|
|
log.Error("LoadPullRequest: %v", err)
|
|
return
|
|
}
|
|
|
|
err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
|
Action: api.HookIssueLabelCleared,
|
|
Index: issue.Index,
|
|
PullRequest: issue.PullRequest.APIFormat(),
|
|
Repository: issue.Repo.APIFormat(mode),
|
|
Sender: doer.APIFormat(),
|
|
})
|
|
} else {
|
|
err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
|
Action: api.HookIssueLabelCleared,
|
|
Index: issue.Index,
|
|
Issue: issue.APIFormat(),
|
|
Repository: issue.Repo.APIFormat(mode),
|
|
Sender: doer.APIFormat(),
|
|
})
|
|
}
|
|
if err != nil {
|
|
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
|
} else {
|
|
go models.HookQueue.Add(issue.RepoID)
|
|
}
|
|
}
|