rename to notifier
This commit is contained in:
parent
fc62dea471
commit
3888095a74
1
main.go
1
main.go
|
|
@ -16,7 +16,6 @@ import (
|
||||||
// register supported doc types
|
// register supported doc types
|
||||||
_ "code.gitea.io/gitea/modules/markup/markdown"
|
_ "code.gitea.io/gitea/modules/markup/markdown"
|
||||||
_ "code.gitea.io/gitea/modules/markup/orgmode"
|
_ "code.gitea.io/gitea/modules/markup/orgmode"
|
||||||
_ "code.gitea.io/gitea/modules/notification/init"
|
|
||||||
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -715,8 +715,9 @@ func TransferRepoAction(doer, oldOwner *User, repo *Repository) error {
|
||||||
return transferRepoAction(x, doer, oldOwner, repo)
|
return transferRepoAction(x, doer, oldOwner, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue) error {
|
// MergePullRequestAction adds new action for merging pull request.
|
||||||
return notifyWatchers(e, &Action{
|
func MergePullRequestAction(doer *User, repo *Repository, issue *Issue) error {
|
||||||
|
return notifyWatchers(x, &Action{
|
||||||
ActUserID: doer.ID,
|
ActUserID: doer.ID,
|
||||||
ActUser: doer,
|
ActUser: doer,
|
||||||
OpType: ActionMergePullRequest,
|
OpType: ActionMergePullRequest,
|
||||||
|
|
@ -727,11 +728,6 @@ func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// MergePullRequestAction adds new action for merging pull request.
|
|
||||||
func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue) error {
|
|
||||||
return mergePullRequestAction(x, actUser, repo, pull)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetFeedsOptions options for retrieving feeds
|
// GetFeedsOptions options for retrieving feeds
|
||||||
type GetFeedsOptions struct {
|
type GetFeedsOptions struct {
|
||||||
RequestedUser *User
|
RequestedUser *User
|
||||||
|
|
|
||||||
|
|
@ -720,36 +720,9 @@ func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateComment updates information of comment.
|
// UpdateComment updates information of comment.
|
||||||
func UpdateComment(doer *User, c *Comment, oldContent string) error {
|
func UpdateComment(doer *User, c *Comment) error {
|
||||||
if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
|
if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if c.Type == CommentTypeComment {
|
|
||||||
UpdateIssueIndexer(c.IssueID)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.LoadIssue(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := c.Issue.LoadAttributes(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mode, _ := AccessLevel(doer.ID, c.Issue.Repo)
|
|
||||||
if err := PrepareWebhooks(c.Issue.Repo, HookEventIssueComment, &api.IssueCommentPayload{
|
|
||||||
Action: api.HookIssueCommentEdited,
|
|
||||||
Issue: c.Issue.APIFormat(),
|
|
||||||
Comment: c.APIFormat(),
|
|
||||||
Changes: &api.ChangesPayload{
|
|
||||||
Body: &api.ChangesFromPayload{
|
|
||||||
From: oldContent,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Repository: c.Issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", c.ID, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(c.Issue.Repo.ID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -10,28 +10,29 @@ import (
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
type actionReceiver struct {
|
type actionNotifier struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
receiver notification.NotifyReceiver = &actionReceiver{}
|
_ base.Notifier = &actionNotifier{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
// NewNotifier returns a new actionNotifier
|
||||||
notification.RegisterReceiver(receiver)
|
func NewNotifier() *actionNotifier {
|
||||||
|
return &actionNotifier{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *actionReceiver) Run() {}
|
func (r *actionNotifier) Run() {}
|
||||||
|
|
||||||
func (r *actionReceiver) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
func (r *actionNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
issue *models.Issue, comment *models.Comment) {
|
issue *models.Issue, comment *models.Comment) {
|
||||||
panic("not implementation")
|
panic("not implementation")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *actionReceiver) NotifyNewIssue(issue *models.Issue) {
|
func (r *actionNotifier) NotifyNewIssue(issue *models.Issue) {
|
||||||
if err := models.NotifyWatchers(&models.Action{
|
if err := models.NotifyWatchers(&models.Action{
|
||||||
ActUserID: issue.Poster.ID,
|
ActUserID: issue.Poster.ID,
|
||||||
ActUser: issue.Poster,
|
ActUser: issue.Poster,
|
||||||
|
|
@ -45,11 +46,11 @@ func (r *actionReceiver) NotifyNewIssue(issue *models.Issue) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *actionReceiver) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
func (r *actionNotifier) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
panic("not implementation")
|
panic("not implementation")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *actionReceiver) NotifyNewPullRequest(pr *models.PullRequest) {
|
func (r *actionNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
issue := pr.Issue
|
issue := pr.Issue
|
||||||
if err := models.NotifyWatchers(&models.Action{
|
if err := models.NotifyWatchers(&models.Action{
|
||||||
ActUserID: issue.Poster.ID,
|
ActUserID: issue.Poster.ID,
|
||||||
|
|
@ -64,8 +65,11 @@ func (r *actionReceiver) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *actionReceiver) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
|
func (r *actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
|
||||||
if err := models.MergePullRequestAction(doer, pr.Issue.Repo, pr.Issue); err != nil {
|
if err := models.MergePullRequestAction(doer, pr.Issue.Repo, pr.Issue); err != nil {
|
||||||
log.Error(4, "MergePullRequestAction [%d]: %v", pr.ID, err)
|
log.Error(4, "MergePullRequestAction [%d]: %v", pr.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
}
|
||||||
|
|
|
||||||
22
modules/notification/base/base.go
Normal file
22
modules/notification/base/base.go
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright 2018 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 base
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/git"
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Notifier defines an interface to notify receiver
|
||||||
|
type Notifier interface {
|
||||||
|
Run()
|
||||||
|
NotifyCreateIssueComment(*models.User, *models.Repository,
|
||||||
|
*models.Issue, *models.Comment)
|
||||||
|
NotifyNewIssue(*models.Issue)
|
||||||
|
NotifyCloseIssue(*models.Issue, *models.User)
|
||||||
|
NotifyMergePullRequest(*models.PullRequest, *models.User, *git.Repository)
|
||||||
|
NotifyNewPullRequest(*models.PullRequest)
|
||||||
|
NotifyUpdateComment(*models.User, *models.Comment, string)
|
||||||
|
}
|
||||||
|
|
@ -7,39 +7,45 @@ package indexer
|
||||||
import (
|
import (
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
type indexerReceiver struct {
|
type indexerNotifier struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
receiver notification.NotifyReceiver = &indexerReceiver{}
|
_ base.Notifier = &indexerNotifier{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
// NewNotifier create a new indexerNotifier notifier
|
||||||
notification.RegisterReceiver(receiver)
|
func NewNotifier() *indexerNotifier {
|
||||||
|
return &indexerNotifier{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *indexerReceiver) Run() {
|
func (r *indexerNotifier) Run() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *indexerReceiver) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
func (r *indexerNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
issue *models.Issue, comment *models.Comment) {
|
issue *models.Issue, comment *models.Comment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *indexerReceiver) NotifyNewIssue(issue *models.Issue) {
|
func (r *indexerNotifier) NotifyNewIssue(issue *models.Issue) {
|
||||||
models.UpdateIssueIndexer(issue.ID)
|
models.UpdateIssueIndexer(issue.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *indexerReceiver) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
func (r *indexerNotifier) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *indexerReceiver) NotifyNewPullRequest(pr *models.PullRequest) {
|
func (r *indexerNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
models.UpdateIssueIndexer(pr.Issue.ID)
|
models.UpdateIssueIndexer(pr.Issue.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *indexerReceiver) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
|
func (r *indexerNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
if c.Type == models.CommentTypeComment {
|
||||||
|
models.UpdateIssueIndexer(c.IssueID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
package init
|
|
||||||
|
|
||||||
import (
|
|
||||||
// Import all needed receivers
|
|
||||||
_ "code.gitea.io/gitea/modules/notification/action"
|
|
||||||
_ "code.gitea.io/gitea/modules/notification/indexer"
|
|
||||||
_ "code.gitea.io/gitea/modules/notification/mail"
|
|
||||||
_ "code.gitea.io/gitea/modules/notification/ui"
|
|
||||||
_ "code.gitea.io/gitea/modules/notification/webhook"
|
|
||||||
)
|
|
||||||
|
|
@ -8,45 +8,49 @@ import (
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mailReceiver struct {
|
type mailNotifier struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
receiver notification.NotifyReceiver = &mailReceiver{}
|
_ base.Notifier = &mailNotifier{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
// NewNotifier create a new mailNotifier notifier
|
||||||
notification.RegisterReceiver(receiver)
|
func NewNotifier() *mailNotifier {
|
||||||
|
return &mailNotifier{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mailReceiver) Run() {
|
func (m *mailNotifier) Run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mailReceiver) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
issue *models.Issue, comment *models.Comment) {
|
issue *models.Issue, comment *models.Comment) {
|
||||||
panic("not implementation")
|
panic("not implementation")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mailReceiver) NotifyNewIssue(issue *models.Issue) {
|
func (m *mailNotifier) NotifyNewIssue(issue *models.Issue) {
|
||||||
if err := issue.MailParticipants(); err != nil {
|
if err := issue.MailParticipants(); err != nil {
|
||||||
log.Error(4, "MailParticipants: %v", err)
|
log.Error(4, "MailParticipants: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mailReceiver) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
func (m *mailNotifier) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
if err := issue.MailParticipants(); err != nil {
|
if err := issue.MailParticipants(); err != nil {
|
||||||
log.Error(4, "MailParticipants: %v", err)
|
log.Error(4, "MailParticipants: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mailReceiver) NotifyNewPullRequest(pr *models.PullRequest) {
|
func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
if err := pr.Issue.MailParticipants(); err != nil {
|
if err := pr.Issue.MailParticipants(); err != nil {
|
||||||
log.Error(4, "MailParticipants: %v", err)
|
log.Error(4, "MailParticipants: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mailReceiver) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
|
func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,61 +7,71 @@ package notification
|
||||||
import (
|
import (
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/notification/action"
|
||||||
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
|
"code.gitea.io/gitea/modules/notification/indexer"
|
||||||
|
"code.gitea.io/gitea/modules/notification/mail"
|
||||||
|
"code.gitea.io/gitea/modules/notification/ui"
|
||||||
|
"code.gitea.io/gitea/modules/notification/webhook"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NotifyReceiver defines an interface to notify receiver
|
|
||||||
type NotifyReceiver interface {
|
|
||||||
Run()
|
|
||||||
NotifyCreateIssueComment(*models.User, *models.Repository,
|
|
||||||
*models.Issue, *models.Comment)
|
|
||||||
NotifyNewIssue(*models.Issue)
|
|
||||||
NotifyCloseIssue(*models.Issue, *models.User)
|
|
||||||
NotifyMergePullRequest(*models.PullRequest, *models.User, *git.Repository)
|
|
||||||
NotifyNewPullRequest(*models.PullRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
notifyReceivers []NotifyReceiver
|
notifiers []base.Notifier
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterReceiver providers method to receive notify messages
|
// RegisterNotifier providers method to receive notify messages
|
||||||
func RegisterReceiver(receiver NotifyReceiver) {
|
func RegisterNotifier(notifier base.Notifier) {
|
||||||
go receiver.Run()
|
go notifier.Run()
|
||||||
notifyReceivers = append(notifyReceivers, receiver)
|
notifiers = append(notifiers, notifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyCreateIssueComment notifies issue comment related message to receivers
|
func init() {
|
||||||
|
RegisterNotifier(webhook.NewNotifier())
|
||||||
|
RegisterNotifier(ui.NewNotifier())
|
||||||
|
RegisterNotifier(mail.NewNotifier())
|
||||||
|
RegisterNotifier(indexer.NewNotifier())
|
||||||
|
RegisterNotifier(action.NewNotifier())
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyCreateIssueComment notifies issue comment related message to notifiers
|
||||||
func NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
func NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
issue *models.Issue, comment *models.Comment) {
|
issue *models.Issue, comment *models.Comment) {
|
||||||
for _, receiver := range notifyReceivers {
|
for _, notifier := range notifiers {
|
||||||
receiver.NotifyCreateIssueComment(doer, repo, issue, comment)
|
notifier.NotifyCreateIssueComment(doer, repo, issue, comment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyNewIssue notifies new issue to receivers
|
// NotifyNewIssue notifies new issue to notifiers
|
||||||
func NotifyNewIssue(issue *models.Issue) {
|
func NotifyNewIssue(issue *models.Issue) {
|
||||||
for _, receiver := range notifyReceivers {
|
for _, notifier := range notifiers {
|
||||||
receiver.NotifyNewIssue(issue)
|
notifier.NotifyNewIssue(issue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyCloseIssue notifies close issue to receivers
|
// NotifyCloseIssue notifies close issue to notifiers
|
||||||
func NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
func NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
for _, receiver := range notifyReceivers {
|
for _, notifier := range notifiers {
|
||||||
receiver.NotifyCloseIssue(issue, doer)
|
notifier.NotifyCloseIssue(issue, doer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyMergePullRequest notifies merge pull request to receivers
|
// NotifyMergePullRequest notifies merge pull request to notifiers
|
||||||
func NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository) {
|
func NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository) {
|
||||||
for _, receiver := range notifyReceivers {
|
for _, notifier := range notifiers {
|
||||||
receiver.NotifyMergePullRequest(pr, doer, baseGitRepo)
|
notifier.NotifyMergePullRequest(pr, doer, baseGitRepo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyNewPullRequest notifies new pull request to receivers
|
// NotifyNewPullRequest notifies new pull request to notifiers
|
||||||
func NotifyNewPullRequest(pr *models.PullRequest) {
|
func NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
for _, receiver := range notifyReceivers {
|
for _, notifier := range notifiers {
|
||||||
receiver.NotifyNewPullRequest(pr)
|
notifier.NotifyNewPullRequest(pr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyUpdateComment notifies update comment to notifiers
|
||||||
|
func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyUpdateComment(doer, c, oldContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|
@ -23,21 +23,20 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// service is the notification service
|
_ base.Notifier = ¬ificationService{}
|
||||||
service = ¬ificationService{
|
|
||||||
issueQueue: make(chan issueNotificationOpts, 100),
|
|
||||||
}
|
|
||||||
_ notification.NotifyReceiver = ¬ificationService{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
// NewNotifier create a new notificationService notifier
|
||||||
notification.RegisterReceiver(service)
|
func NewNotifier() *notificationService {
|
||||||
|
return ¬ificationService{
|
||||||
|
issueQueue: make(chan issueNotificationOpts, 100),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *notificationService) Run() {
|
func (ns *notificationService) Run() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case opts := <-service.issueQueue:
|
case opts := <-ns.issueQueue:
|
||||||
if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
|
if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
|
||||||
log.Error(4, "Was unable to create issue notification: %v", err)
|
log.Error(4, "Was unable to create issue notification: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -76,3 +75,6 @@ func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
pr.Issue.PosterID,
|
pr.Issue.PosterID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,27 +8,28 @@ import (
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
api "code.gitea.io/sdk/gitea"
|
api "code.gitea.io/sdk/gitea"
|
||||||
)
|
)
|
||||||
|
|
||||||
type webhookReceiver struct {
|
type webhookNotifier struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
receiver notification.NotifyReceiver = &webhookReceiver{}
|
_ base.Notifier = &webhookNotifier{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
// NewNotifier returns a new webhookNotifier
|
||||||
notification.RegisterReceiver(receiver)
|
func NewNotifier() *webhookNotifier {
|
||||||
|
return &webhookNotifier{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *webhookReceiver) Run() {
|
func (w *webhookNotifier) Run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *webhookReceiver) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
func (w *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
issue *models.Issue, comment *models.Comment) {
|
issue *models.Issue, comment *models.Comment) {
|
||||||
mode, _ := models.AccessLevel(doer.ID, repo)
|
mode, _ := models.AccessLevel(doer.ID, repo)
|
||||||
if err := models.PrepareWebhooks(repo, models.HookEventIssueComment, &api.IssueCommentPayload{
|
if err := models.PrepareWebhooks(repo, models.HookEventIssueComment, &api.IssueCommentPayload{
|
||||||
|
|
@ -45,7 +46,7 @@ func (w *webhookReceiver) NotifyCreateIssueComment(doer *models.User, repo *mode
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyNewIssue implements notification.Receiver
|
// NotifyNewIssue implements notification.Receiver
|
||||||
func (w *webhookReceiver) NotifyNewIssue(issue *models.Issue) {
|
func (w *webhookNotifier) NotifyNewIssue(issue *models.Issue) {
|
||||||
mode, _ := models.AccessLevel(issue.Poster.ID, issue.Repo)
|
mode, _ := models.AccessLevel(issue.Poster.ID, issue.Repo)
|
||||||
if err := models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
if err := models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
||||||
Action: api.HookIssueOpened,
|
Action: api.HookIssueOpened,
|
||||||
|
|
@ -61,11 +62,11 @@ func (w *webhookReceiver) NotifyNewIssue(issue *models.Issue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyCloseIssue implements notification.Receiver
|
// NotifyCloseIssue implements notification.Receiver
|
||||||
func (w *webhookReceiver) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
func (w *webhookNotifier) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
panic("not implements")
|
panic("not implements")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *webhookReceiver) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository) {
|
func (w *webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository) {
|
||||||
mode, _ := models.AccessLevel(doer.ID, pr.Issue.Repo)
|
mode, _ := models.AccessLevel(doer.ID, pr.Issue.Repo)
|
||||||
if err := models.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
if err := models.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
Action: api.HookIssueClosed,
|
Action: api.HookIssueClosed,
|
||||||
|
|
@ -111,7 +112,7 @@ func (w *webhookReceiver) NotifyMergePullRequest(pr *models.PullRequest, doer *m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *webhookReceiver) NotifyNewPullRequest(pr *models.PullRequest) {
|
func (w *webhookNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
mode, _ := models.AccessLevel(pr.Issue.Poster.ID, pr.Issue.Repo)
|
mode, _ := models.AccessLevel(pr.Issue.Poster.ID, pr.Issue.Repo)
|
||||||
if err := models.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
if err := models.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
Action: api.HookIssueOpened,
|
Action: api.HookIssueOpened,
|
||||||
|
|
@ -125,3 +126,32 @@ func (w *webhookReceiver) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
go models.HookQueue.Add(pr.Issue.Repo.ID)
|
go models.HookQueue.Add(pr.Issue.Repo.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
if err := c.LoadIssue(); err != nil {
|
||||||
|
log.Error(2, "LoadIssue [comment_id: %d]: %v", c.ID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := c.Issue.LoadAttributes(); err != nil {
|
||||||
|
log.Error(2, "Issue.LoadAttributes [comment_id: %d]: %v", c.ID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, c.Issue.Repo)
|
||||||
|
if err := models.PrepareWebhooks(c.Issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
|
||||||
|
Action: api.HookIssueCommentEdited,
|
||||||
|
Issue: c.Issue.APIFormat(),
|
||||||
|
Comment: c.APIFormat(),
|
||||||
|
Changes: &api.ChangesPayload{
|
||||||
|
Body: &api.ChangesFromPayload{
|
||||||
|
From: oldContent,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Repository: c.Issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", c.ID, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(c.Issue.Repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -266,10 +266,13 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
||||||
|
|
||||||
oldContent := comment.Content
|
oldContent := comment.Content
|
||||||
comment.Content = form.Body
|
comment.Content = form.Body
|
||||||
if err := models.UpdateComment(ctx.User, comment, oldContent); err != nil {
|
if err := models.UpdateComment(ctx.User, comment); err != nil {
|
||||||
ctx.Error(500, "UpdateComment", err)
|
ctx.Error(500, "UpdateComment", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyUpdateComment(ctx.User, comment, oldContent)
|
||||||
|
|
||||||
ctx.JSON(200, comment.APIFormat())
|
ctx.JSON(200, comment.APIFormat())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1094,11 +1094,13 @@ func UpdateCommentContent(ctx *context.Context) {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = models.UpdateComment(ctx.User, comment, oldContent); err != nil {
|
if err = models.UpdateComment(ctx.User, comment); err != nil {
|
||||||
ctx.ServerError("UpdateComment", err)
|
ctx.ServerError("UpdateComment", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyUpdateComment(ctx.User, comment, oldContent)
|
||||||
|
|
||||||
ctx.JSON(200, map[string]interface{}{
|
ctx.JSON(200, map[string]interface{}{
|
||||||
"content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
|
"content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user