From fd9dcc7e3c27017f4e3a5c42c39e71be8781e8fc Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 29 Dec 2022 09:49:59 +0800 Subject: [PATCH 01/12] Move notification implementations out of modules --- modules/notification/notification.go | 13 -------- .../action => services/feed}/action.go | 7 ++++- .../action => services/feed}/action_test.go | 2 +- .../indexer/notifier.go | 5 +++ services/mailer/mailer.go | 5 +++ .../mail.go => services/mailer/notifier.go | 31 +++++++++---------- .../mirror.go => services/mirror/notifier.go | 5 +++ .../notification/notifier.go | 7 ++++- 8 files changed, 43 insertions(+), 32 deletions(-) rename {modules/notification/action => services/feed}/action.go (99%) rename {modules/notification/action => services/feed}/action_test.go (98%) rename modules/notification/indexer/indexer.go => services/indexer/notifier.go (98%) rename modules/notification/mail/mail.go => services/mailer/notifier.go (81%) rename modules/notification/mirror/mirror.go => services/mirror/notifier.go (92%) rename modules/notification/ui/ui.go => services/notification/notifier.go (98%) diff --git a/modules/notification/notification.go b/modules/notification/notification.go index c3e09bb8a9151..f6eab3aed5965 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -10,15 +10,9 @@ import ( packages_model "code.gitea.io/gitea/models/packages" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" - "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/mirror" - "code.gitea.io/gitea/modules/notification/ui" "code.gitea.io/gitea/modules/notification/webhook" "code.gitea.io/gitea/modules/repository" - "code.gitea.io/gitea/modules/setting" ) var notifiers []base.Notifier @@ -31,14 +25,7 @@ func RegisterNotifier(notifier base.Notifier) { // NewContext registers notification handlers func NewContext() { - RegisterNotifier(ui.NewNotifier()) - if setting.Service.EnableNotifyMail { - RegisterNotifier(mail.NewNotifier()) - } - RegisterNotifier(indexer.NewNotifier()) RegisterNotifier(webhook.NewNotifier()) - RegisterNotifier(action.NewNotifier()) - RegisterNotifier(mirror.NewNotifier()) } // NotifyNewWikiPage notifies creating new wiki pages to notifiers diff --git a/modules/notification/action/action.go b/services/feed/action.go similarity index 99% rename from modules/notification/action/action.go rename to services/feed/action.go index 2f882c2cb86e6..37299e2eb8db3 100644 --- a/modules/notification/action/action.go +++ b/services/feed/action.go @@ -1,7 +1,7 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package action +package feed import ( "context" @@ -15,6 +15,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/util" @@ -31,6 +32,10 @@ func NewNotifier() base.Notifier { return &actionNotifier{} } +func init() { + notification.RegisterNotifier(NewNotifier()) +} + func (a *actionNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { if err := issue.LoadPoster(ctx); err != nil { log.Error("issue.LoadPoster: %v", err) diff --git a/modules/notification/action/action_test.go b/services/feed/action_test.go similarity index 98% rename from modules/notification/action/action_test.go rename to services/feed/action_test.go index 05ce70f38877d..69e070a3f6147 100644 --- a/modules/notification/action/action_test.go +++ b/services/feed/action_test.go @@ -1,7 +1,7 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package action +package feed import ( "path/filepath" diff --git a/modules/notification/indexer/indexer.go b/services/indexer/notifier.go similarity index 98% rename from modules/notification/indexer/indexer.go rename to services/indexer/notifier.go index c67f79d0f2ae5..a00b7c9622663 100644 --- a/modules/notification/indexer/indexer.go +++ b/services/indexer/notifier.go @@ -14,6 +14,7 @@ import ( issue_indexer "code.gitea.io/gitea/modules/indexer/issues" stats_indexer "code.gitea.io/gitea/modules/indexer/stats" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" @@ -30,6 +31,10 @@ func NewNotifier() base.Notifier { return &indexerNotifier{} } +func init() { + notification.RegisterNotifier(NewNotifier()) +} + func (r *indexerNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, ) { diff --git a/services/mailer/mailer.go b/services/mailer/mailer.go index 6149644600eaa..ecc3a9ffa8ffa 100644 --- a/services/mailer/mailer.go +++ b/services/mailer/mailer.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/setting" @@ -356,6 +357,10 @@ func NewContext(ctx context.Context) { return } + if setting.Service.EnableNotifyMail { + notification.RegisterNotifier(NewNotifier()) + } + switch setting.MailService.Protocol { case "sendmail": Sender = &sendmailSender{} diff --git a/modules/notification/mail/mail.go b/services/mailer/notifier.go similarity index 81% rename from modules/notification/mail/mail.go rename to services/mailer/notifier.go index 18f7fa22aea6e..bfcad24bc9027 100644 --- a/modules/notification/mail/mail.go +++ b/services/mailer/notifier.go @@ -1,7 +1,7 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package mail +package mailer import ( "context" @@ -13,7 +13,6 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification/base" - "code.gitea.io/gitea/services/mailer" ) type mailNotifier struct { @@ -43,13 +42,13 @@ func (m *mailNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_ act = 0 } - if err := mailer.MailParticipantsComment(ctx, comment, act, issue, mentions); err != nil { + if err := MailParticipantsComment(ctx, comment, act, issue, mentions); err != nil { log.Error("MailParticipantsComment: %v", err) } } func (m *mailNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { - if err := mailer.MailParticipants(ctx, issue, issue.Poster, activities_model.ActionCreateIssue, mentions); err != nil { + if err := MailParticipants(ctx, issue, issue.Poster, activities_model.ActionCreateIssue, mentions); err != nil { log.Error("MailParticipants: %v", err) } } @@ -70,7 +69,7 @@ func (m *mailNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_m } } - if err := mailer.MailParticipants(ctx, issue, doer, actionType, nil); err != nil { + if err := MailParticipants(ctx, issue, doer, actionType, nil); err != nil { log.Error("MailParticipants: %v", err) } } @@ -81,14 +80,14 @@ func (m *mailNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_mo return } if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issue.PullRequest.IsWorkInProgress() { - if err := mailer.MailParticipants(ctx, issue, doer, activities_model.ActionPullRequestReadyForReview, nil); err != nil { + if err := MailParticipants(ctx, issue, doer, activities_model.ActionPullRequestReadyForReview, nil); err != nil { log.Error("MailParticipants: %v", err) } } } func (m *mailNotifier) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { - if err := mailer.MailParticipants(ctx, pr.Issue, pr.Issue.Poster, activities_model.ActionCreatePullRequest, mentions); err != nil { + if err := MailParticipants(ctx, pr.Issue, pr.Issue.Poster, activities_model.ActionCreatePullRequest, mentions); err != nil { log.Error("MailParticipants: %v", err) } } @@ -102,13 +101,13 @@ func (m *mailNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_m } else if comment.Type == issues_model.CommentTypeComment { act = activities_model.ActionCommentPull } - if err := mailer.MailParticipantsComment(ctx, comment, act, pr.Issue, mentions); err != nil { + if err := MailParticipantsComment(ctx, comment, act, pr.Issue, mentions); err != nil { log.Error("MailParticipantsComment: %v", err) } } func (m *mailNotifier) NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { - if err := mailer.MailMentionsComment(ctx, pr, comment, mentions); err != nil { + if err := MailMentionsComment(ctx, pr, comment, mentions); err != nil { log.Error("MailMentionsComment: %v", err) } } @@ -117,7 +116,7 @@ func (m *mailNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user // mail only sent to added assignees and not self-assignee if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() != user_model.EmailNotificationsDisabled { ct := fmt.Sprintf("Assigned #%d.", issue.Index) - if err := mailer.SendIssueAssignedMail(ctx, issue, doer, ct, comment, []*user_model.User{assignee}); err != nil { + if err := SendIssueAssignedMail(ctx, issue, doer, ct, comment, []*user_model.User{assignee}); err != nil { log.Error("Error in SendIssueAssignedMail for issue[%d] to assignee[%d]: %v", issue.ID, assignee.ID, err) } } @@ -126,7 +125,7 @@ func (m *mailNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user func (m *mailNotifier) NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() != user_model.EmailNotificationsDisabled { ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL()) - if err := mailer.SendIssueAssignedMail(ctx, issue, doer, ct, comment, []*user_model.User{reviewer}); err != nil { + if err := SendIssueAssignedMail(ctx, issue, doer, ct, comment, []*user_model.User{reviewer}); err != nil { log.Error("Error in SendIssueAssignedMail for issue[%d] to reviewer[%d]: %v", issue.ID, reviewer.ID, err) } } @@ -137,7 +136,7 @@ func (m *mailNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_mo log.Error("LoadIssue: %v", err) return } - if err := mailer.MailParticipants(ctx, pr.Issue, doer, activities_model.ActionMergePullRequest, nil); err != nil { + if err := MailParticipants(ctx, pr.Issue, doer, activities_model.ActionMergePullRequest, nil); err != nil { log.Error("MailParticipants: %v", err) } } @@ -147,7 +146,7 @@ func (m *mailNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *use log.Error("pr.LoadIssue: %v", err) return } - if err := mailer.MailParticipants(ctx, pr.Issue, doer, activities_model.ActionAutoMergePullRequest, nil); err != nil { + if err := MailParticipants(ctx, pr.Issue, doer, activities_model.ActionAutoMergePullRequest, nil); err != nil { log.Error("MailParticipants: %v", err) } } @@ -177,7 +176,7 @@ func (m *mailNotifier) NotifyPullRequestPushCommits(ctx context.Context, doer *u } func (m *mailNotifier) NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { - if err := mailer.MailParticipantsComment(ctx, comment, activities_model.ActionPullReviewDismissed, review.Issue, nil); err != nil { + if err := MailParticipantsComment(ctx, comment, activities_model.ActionPullReviewDismissed, review.Issue, nil); err != nil { log.Error("MailParticipantsComment: %v", err) } } @@ -192,11 +191,11 @@ func (m *mailNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Rel return } - mailer.MailNewRelease(ctx, rel) + MailNewRelease(ctx, rel) } func (m *mailNotifier) NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { - if err := mailer.SendRepoTransferNotifyMail(ctx, doer, newOwner, repo); err != nil { + if err := SendRepoTransferNotifyMail(ctx, doer, newOwner, repo); err != nil { log.Error("SendRepoTransferNotifyMail: %v", err) } } diff --git a/modules/notification/mirror/mirror.go b/services/mirror/notifier.go similarity index 92% rename from modules/notification/mirror/mirror.go rename to services/mirror/notifier.go index 426e36ee58bd6..b591f94d5e920 100644 --- a/modules/notification/mirror/mirror.go +++ b/services/mirror/notifier.go @@ -10,6 +10,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" mirror_module "code.gitea.io/gitea/modules/mirror" + "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/repository" ) @@ -25,6 +26,10 @@ func NewNotifier() base.Notifier { return &mirrorNotifier{} } +func init() { + notification.RegisterNotifier(NewNotifier()) +} + func (m *mirrorNotifier) NotifyPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) { syncPushMirrorWithSyncOnCommit(ctx, repo.ID) } diff --git a/modules/notification/ui/ui.go b/services/notification/notifier.go similarity index 98% rename from modules/notification/ui/ui.go rename to services/notification/notifier.go index 63a3ffd199989..cba11c3121628 100644 --- a/modules/notification/ui/ui.go +++ b/services/notification/notifier.go @@ -1,7 +1,7 @@ // Copyright 2018 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package ui +package notification import ( "context" @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/queue" ) @@ -41,6 +42,10 @@ func NewNotifier() base.Notifier { return ns } +func init() { + notification.RegisterNotifier(NewNotifier()) +} + func (ns *notificationService) handle(data ...queue.Data) []queue.Data { for _, datum := range data { opts := datum.(issueNotificationOpts) From f4f09ee9bbc15cd00ca362e5563a323189f78c3f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 29 Dec 2022 10:14:04 +0800 Subject: [PATCH 02/12] Fix lint --- services/repository/transfer_test.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go index 1299e66be2781..a18766a0de3dc 100644 --- a/services/repository/transfer_test.go +++ b/services/repository/transfer_test.go @@ -4,7 +4,6 @@ package repository import ( - "sync" "testing" activities_model "code.gitea.io/gitea/models/activities" @@ -14,24 +13,13 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/notification" - "code.gitea.io/gitea/modules/notification/action" "code.gitea.io/gitea/modules/util" + _ "code.gitea.io/gitea/services/feed" // to ensure action notification is registered "github.com/stretchr/testify/assert" ) -var notifySync sync.Once - -func registerNotifier() { - notifySync.Do(func() { - notification.RegisterNotifier(action.NewNotifier()) - }) -} - func TestTransferOwnership(t *testing.T) { - registerNotifier() - assert.NoError(t, unittest.PrepareTestDatabase()) doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) From 7f0221a04298a70dccc4ff813baf6776647bf38a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 29 Dec 2022 10:24:31 +0800 Subject: [PATCH 03/12] Fix lint --- services/repository/transfer_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go index a18766a0de3dc..eff2197002a8e 100644 --- a/services/repository/transfer_test.go +++ b/services/repository/transfer_test.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/util" + _ "code.gitea.io/gitea/services/feed" // to ensure action notification is registered "github.com/stretchr/testify/assert" From b9e5fd6498418fdb28fe09d6e3161aee70103858 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 1 Jan 2023 23:35:13 +0800 Subject: [PATCH 04/12] improvement --- main.go | 4 ++++ services/feed/action.go | 7 +++---- services/indexer/notifier.go | 7 +++---- services/notification/notifier.go | 7 +++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 070e9857d08c0..f9d3d34cd1386 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,10 @@ import ( _ "code.gitea.io/gitea/modules/markup/markdown" _ "code.gitea.io/gitea/modules/markup/orgmode" + _ "code.gitea.io/gitea/services/feed" + _ "code.gitea.io/gitea/services/indexer" + _ "code.gitea.io/gitea/services/notification" + "github.com/urfave/cli" ) diff --git a/services/feed/action.go b/services/feed/action.go index 37299e2eb8db3..31156406b1f66 100644 --- a/services/feed/action.go +++ b/services/feed/action.go @@ -16,19 +16,18 @@ import ( "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" - "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/util" ) type actionNotifier struct { - base.NullNotifier + notification.NullNotifier } -var _ base.Notifier = &actionNotifier{} +var _ notification.Notifier = &actionNotifier{} // NewNotifier create a new actionNotifier notifier -func NewNotifier() base.Notifier { +func NewNotifier() notification.Notifier { return &actionNotifier{} } diff --git a/services/indexer/notifier.go b/services/indexer/notifier.go index a00b7c9622663..11ba7e13bfee6 100644 --- a/services/indexer/notifier.go +++ b/services/indexer/notifier.go @@ -15,19 +15,18 @@ import ( stats_indexer "code.gitea.io/gitea/modules/indexer/stats" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" - "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" ) type indexerNotifier struct { - base.NullNotifier + notification.NullNotifier } -var _ base.Notifier = &indexerNotifier{} +var _ notification.Notifier = &indexerNotifier{} // NewNotifier create a new indexerNotifier notifier -func NewNotifier() base.Notifier { +func NewNotifier() notification.Notifier { return &indexerNotifier{} } diff --git a/services/notification/notifier.go b/services/notification/notifier.go index cba11c3121628..696e501b4e471 100644 --- a/services/notification/notifier.go +++ b/services/notification/notifier.go @@ -15,13 +15,12 @@ import ( "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" - "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/queue" ) type ( notificationService struct { - base.NullNotifier + notification.NullNotifier issueQueue queue.Queue } @@ -33,10 +32,10 @@ type ( } ) -var _ base.Notifier = ¬ificationService{} +var _ notification.Notifier = ¬ificationService{} // NewNotifier create a new notificationService notifier -func NewNotifier() base.Notifier { +func NewNotifier() notification.Notifier { ns := ¬ificationService{} ns.issueQueue = queue.CreateQueue("notification-service", ns.handle, issueNotificationOpts{}) return ns From b7b07806d00ff88c180f6bb2d5620765156c872d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 2 Jan 2023 00:12:46 +0800 Subject: [PATCH 05/12] rename modules/notification -> services/notify --- routers/api/packages/conan/conan.go | 4 +- routers/api/v1/repo/issue.go | 6 +- routers/api/v1/repo/migrate.go | 4 +- routers/api/v1/repo/pull.go | 8 +- routers/api/v1/repo/wiki.go | 8 +- routers/web/repo/pull.go | 4 +- routers/web/repo/wiki.go | 8 +- services/agit/agit.go | 6 +- services/feed/action.go | 10 +-- services/feed/action_test.go | 7 -- services/feed/main_test.go | 17 ++++ services/indexer/notifier.go | 10 +-- services/issue/assignee.go | 8 +- services/issue/comments.go | 8 +- services/issue/content.go | 4 +- services/issue/issue.go | 14 +-- services/issue/label.go | 12 +-- services/issue/milestone.go | 4 +- services/issue/status.go | 4 +- services/mailer/mailer.go | 4 +- services/mailer/notifier.go | 8 +- services/mirror/mirror_pull.go | 10 +-- services/mirror/notifier.go | 10 +-- services/notification/notifier.go | 10 +-- .../notify}/notifier.go | 2 +- .../notify/notify.go | 90 +++++++++---------- .../notification => services/notify}/null.go | 2 +- services/packages/packages.go | 6 +- services/pull/check.go | 4 +- services/pull/merge.go | 8 +- services/pull/pull.go | 12 +-- services/pull/review.go | 10 +-- services/release/release.go | 18 ++-- services/repository/adopt.go | 4 +- services/repository/branch.go | 6 +- services/repository/fork.go | 4 +- services/repository/push.go | 16 ++-- services/repository/repository.go | 6 +- services/repository/template.go | 4 +- services/repository/transfer.go | 8 +- services/task/migrate.go | 4 +- services/webhook/notifier.go | 10 +-- 42 files changed, 206 insertions(+), 196 deletions(-) create mode 100644 services/feed/main_test.go rename {modules/notification => services/notify}/notifier.go (99%) rename modules/notification/notification.go => services/notify/notify.go (84%) rename {modules/notification => services/notify}/null.go (99%) diff --git a/routers/api/packages/conan/conan.go b/routers/api/packages/conan/conan.go index d538cc7d397db..68738788c248f 100644 --- a/routers/api/packages/conan/conan.go +++ b/routers/api/packages/conan/conan.go @@ -17,11 +17,11 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" packages_module "code.gitea.io/gitea/modules/packages" conan_module "code.gitea.io/gitea/modules/packages/conan" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/routers/api/packages/helper" + "code.gitea.io/gitea/services/notify" packages_service "code.gitea.io/gitea/services/packages" ) @@ -678,7 +678,7 @@ func deleteRecipeOrPackage(apictx *context.Context, rref *conan_module.RecipeRef } if versionDeleted { - notification.NotifyPackageDelete(apictx, apictx.Doer, pd) + notify.NotifyPackageDelete(apictx, apictx.Doer, pd) } return nil diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index fecb601dd533d..09dfefbfcd07e 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -20,7 +20,6 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" @@ -29,6 +28,7 @@ import ( "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/convert" issue_service "code.gitea.io/gitea/services/issue" + "code.gitea.io/gitea/services/notify" ) // SearchIssues searches for issues across the repositories that the user has access to @@ -822,11 +822,11 @@ func EditIssue(ctx *context.APIContext) { } if titleChanged { - notification.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) + notify.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) } if statusChangeComment != nil { - notification.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed) + notify.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed) } // Refetch from database to assign some automatic values diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index 09e857b5fcfe8..89031fd883d24 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -21,7 +21,6 @@ import ( "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" base "code.gitea.io/gitea/modules/migration" - "code.gitea.io/gitea/modules/notification" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" @@ -30,6 +29,7 @@ import ( "code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/migrations" + "code.gitea.io/gitea/services/notify" ) // Migrate migrate remote git repository to gitea @@ -194,7 +194,7 @@ func Migrate(ctx *context.APIContext) { } if err == nil { - notification.NotifyMigrateRepository(ctx, ctx.Doer, repoOwner, repo) + notify.NotifyMigrateRepository(ctx, ctx.Doer, repoOwner, repo) return } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 1b1aba17d9299..2a8787e283fc9 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -23,7 +23,6 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" @@ -35,6 +34,7 @@ import ( "code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/gitdiff" issue_service "code.gitea.io/gitea/services/issue" + "code.gitea.io/gitea/services/notify" pull_service "code.gitea.io/gitea/services/pull" repo_service "code.gitea.io/gitea/services/repository" ) @@ -595,11 +595,11 @@ func EditPullRequest(ctx *context.APIContext) { } if titleChanged { - notification.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) + notify.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) } if statusChangeComment != nil { - notification.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed) + notify.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed) } // change pull target branch @@ -623,7 +623,7 @@ func EditPullRequest(ctx *context.APIContext) { } return } - notification.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base) + notify.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base) } // update allow edits diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index 764530a671e6d..654324a83e39b 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -12,12 +12,12 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/convert" + "code.gitea.io/gitea/services/notify" wiki_service "code.gitea.io/gitea/services/wiki" ) @@ -85,7 +85,7 @@ func NewWikiPage(ctx *context.APIContext) { wikiPage := getWikiPage(ctx, wikiName) if !ctx.Written() { - notification.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message) + notify.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message) ctx.JSON(http.StatusCreated, wikiPage) } } @@ -153,7 +153,7 @@ func EditWikiPage(ctx *context.APIContext) { wikiPage := getWikiPage(ctx, newWikiName) if !ctx.Written() { - notification.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message) + notify.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message) ctx.JSON(http.StatusOK, wikiPage) } } @@ -244,7 +244,7 @@ func DeleteWikiPage(ctx *context.APIContext) { return } - notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName) + notify.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName) ctx.Status(http.StatusNoContent) } diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index a18f9f6a56a53..befbcbf5d0300 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -31,7 +31,6 @@ import ( "code.gitea.io/gitea/modules/git" issue_template "code.gitea.io/gitea/modules/issue/template" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/upload" @@ -43,6 +42,7 @@ import ( "code.gitea.io/gitea/services/automerge" "code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/gitdiff" + "code.gitea.io/gitea/services/notify" pull_service "code.gitea.io/gitea/services/pull" repo_service "code.gitea.io/gitea/services/repository" ) @@ -1511,7 +1511,7 @@ func UpdatePullRequestTarget(ctx *context.Context) { } return } - notification.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, targetBranch) + notify.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, targetBranch) ctx.JSON(http.StatusOK, map[string]interface{}{ "base_branch": pr.BaseBranch, diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index b50a4be802043..a97166347d543 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -24,13 +24,13 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/common" "code.gitea.io/gitea/services/forms" + "code.gitea.io/gitea/services/notify" wiki_service "code.gitea.io/gitea/services/wiki" ) @@ -705,7 +705,7 @@ func NewWikiPost(ctx *context.Context) { return } - notification.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message) + notify.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(wikiName)) } @@ -749,7 +749,7 @@ func EditWikiPost(ctx *context.Context) { return } - notification.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message) + notify.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(newWikiName)) } @@ -766,7 +766,7 @@ func DeleteWikiPagePost(ctx *context.Context) { return } - notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName) + notify.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName) ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/wiki/", diff --git a/services/agit/agit.go b/services/agit/agit.go index b61cb6f3f5692..b6a0b76d625f2 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -14,8 +14,8 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/private" + "code.gitea.io/gitea/services/notify" pull_service "code.gitea.io/gitea/services/pull" ) @@ -208,9 +208,9 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. } comment, err := pull_service.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i]) if err == nil && comment != nil { - notification.NotifyPullRequestPushCommits(ctx, pusher, pr, comment) + notify.NotifyPullRequestPushCommits(ctx, pusher, pr, comment) } - notification.NotifyPullRequestSynchronized(ctx, pusher, pr) + notify.NotifyPullRequestSynchronized(ctx, pusher, pr) isForcePush := comment != nil && comment.IsForcePush results = append(results, private.HookProcReceiveRefResult{ diff --git a/services/feed/action.go b/services/feed/action.go index 31156406b1f66..f317137079b50 100644 --- a/services/feed/action.go +++ b/services/feed/action.go @@ -15,24 +15,24 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/notify" ) type actionNotifier struct { - notification.NullNotifier + notify.NullNotifier } -var _ notification.Notifier = &actionNotifier{} +var _ notify.Notifier = &actionNotifier{} // NewNotifier create a new actionNotifier notifier -func NewNotifier() notification.Notifier { +func NewNotifier() notify.Notifier { return &actionNotifier{} } func init() { - notification.RegisterNotifier(NewNotifier()) + notify.RegisterNotifier(NewNotifier()) } func (a *actionNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { diff --git a/services/feed/action_test.go b/services/feed/action_test.go index 69e070a3f6147..0c36231458afe 100644 --- a/services/feed/action_test.go +++ b/services/feed/action_test.go @@ -4,7 +4,6 @@ package feed import ( - "path/filepath" "strings" "testing" @@ -17,12 +16,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) -} - func TestRenameRepoAction(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) diff --git a/services/feed/main_test.go b/services/feed/main_test.go new file mode 100644 index 0000000000000..aa2017a89e819 --- /dev/null +++ b/services/feed/main_test.go @@ -0,0 +1,17 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package feed + +import ( + "path/filepath" + "testing" + + "code.gitea.io/gitea/models/unittest" +) + +func TestMain(m *testing.M) { + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) +} diff --git a/services/indexer/notifier.go b/services/indexer/notifier.go index 11ba7e13bfee6..43b85b7845af2 100644 --- a/services/indexer/notifier.go +++ b/services/indexer/notifier.go @@ -14,24 +14,24 @@ import ( issue_indexer "code.gitea.io/gitea/modules/indexer/issues" stats_indexer "code.gitea.io/gitea/modules/indexer/stats" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/services/notify" ) type indexerNotifier struct { - notification.NullNotifier + notify.NullNotifier } -var _ notification.Notifier = &indexerNotifier{} +var _ notify.Notifier = &indexerNotifier{} // NewNotifier create a new indexerNotifier notifier -func NewNotifier() notification.Notifier { +func NewNotifier() notify.Notifier { return &indexerNotifier{} } func init() { - notification.RegisterNotifier(NewNotifier()) + notify.RegisterNotifier(NewNotifier()) } func (r *indexerNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, diff --git a/services/issue/assignee.go b/services/issue/assignee.go index e5e1456c3f12e..ecc8fdfd63ec0 100644 --- a/services/issue/assignee.go +++ b/services/issue/assignee.go @@ -14,7 +14,7 @@ import ( "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" + "code.gitea.io/gitea/services/notify" ) // DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array @@ -56,7 +56,7 @@ func ToggleAssignee(issue *issues_model.Issue, doer *user_model.User, assigneeID return } - notification.NotifyIssueChangeAssignee(db.DefaultContext, doer, issue, assignee, removed, comment) + notify.NotifyIssueChangeAssignee(db.DefaultContext, doer, issue, assignee, removed, comment) return removed, comment, err } @@ -74,7 +74,7 @@ func ReviewRequest(issue *issues_model.Issue, doer, reviewer *user_model.User, i } if comment != nil { - notification.NotifyPullReviewRequest(db.DefaultContext, doer, issue, reviewer, isAdd, comment) + notify.NotifyPullReviewRequest(db.DefaultContext, doer, issue, reviewer, isAdd, comment) } return comment, err @@ -261,7 +261,7 @@ func TeamReviewRequest(issue *issues_model.Issue, doer *user_model.User, reviewe continue } comment.AssigneeID = member.ID - notification.NotifyPullReviewRequest(db.DefaultContext, doer, issue, member, isAdd, comment) + notify.NotifyPullReviewRequest(db.DefaultContext, doer, issue, member, isAdd, comment) } return comment, err diff --git a/services/issue/comments.go b/services/issue/comments.go index 46c0daf70a336..c66c12d3b1c84 100644 --- a/services/issue/comments.go +++ b/services/issue/comments.go @@ -11,8 +11,8 @@ import ( issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/services/notify" ) // CreateComment creates comment of issue or commit. @@ -83,7 +83,7 @@ func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_m return nil, err } - notification.NotifyCreateIssueComment(ctx, doer, repo, issue, comment, mentions) + notify.NotifyCreateIssueComment(ctx, doer, repo, issue, comment, mentions) return comment, nil } @@ -116,7 +116,7 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, doer *user_mode } } - notification.NotifyUpdateComment(ctx, doer, c, oldContent) + notify.NotifyUpdateComment(ctx, doer, c, oldContent) return nil } @@ -130,7 +130,7 @@ func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_m return err } - notification.NotifyDeleteComment(ctx, doer, comment) + notify.NotifyDeleteComment(ctx, doer, comment) return nil } diff --git a/services/issue/content.go b/services/issue/content.go index 819ac3f20f6ba..60a42c5122a2c 100644 --- a/services/issue/content.go +++ b/services/issue/content.go @@ -7,7 +7,7 @@ import ( "code.gitea.io/gitea/models/db" issues_model "code.gitea.io/gitea/models/issues" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/notification" + "code.gitea.io/gitea/services/notify" ) // ChangeContent changes issue content, as the given user. @@ -18,7 +18,7 @@ func ChangeContent(issue *issues_model.Issue, doer *user_model.User, content str return err } - notification.NotifyIssueChangeContent(db.DefaultContext, doer, issue, oldContent) + notify.NotifyIssueChangeContent(db.DefaultContext, doer, issue, oldContent) return nil } diff --git a/services/issue/issue.go b/services/issue/issue.go index b91ee4fc18b07..de3ff75f58599 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -15,8 +15,8 @@ import ( system_model "code.gitea.io/gitea/models/system" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/storage" + "code.gitea.io/gitea/services/notify" ) // NewIssue creates new issue with labels for repository. @@ -36,12 +36,12 @@ func NewIssue(repo *repo_model.Repository, issue *issues_model.Issue, labelIDs [ return err } - notification.NotifyNewIssue(db.DefaultContext, issue, mentions) + notify.NotifyNewIssue(db.DefaultContext, issue, mentions) if len(issue.Labels) > 0 { - notification.NotifyIssueChangeLabels(db.DefaultContext, issue.Poster, issue, issue.Labels, nil) + notify.NotifyIssueChangeLabels(db.DefaultContext, issue.Poster, issue, issue.Labels, nil) } if issue.Milestone != nil { - notification.NotifyIssueChangeMilestone(db.DefaultContext, issue.Poster, issue, 0) + notify.NotifyIssueChangeMilestone(db.DefaultContext, issue.Poster, issue, 0) } return nil @@ -56,7 +56,7 @@ func ChangeTitle(issue *issues_model.Issue, doer *user_model.User, title string) return } - notification.NotifyIssueChangeTitle(db.DefaultContext, doer, issue, oldTitle) + notify.NotifyIssueChangeTitle(db.DefaultContext, doer, issue, oldTitle) return nil } @@ -70,7 +70,7 @@ func ChangeIssueRef(issue *issues_model.Issue, doer *user_model.User, ref string return err } - notification.NotifyIssueChangeRef(db.DefaultContext, doer, issue, oldRef) + notify.NotifyIssueChangeRef(db.DefaultContext, doer, issue, oldRef) return nil } @@ -152,7 +152,7 @@ func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_m } } - notification.NotifyDeleteIssue(gitRepo.Ctx, doer, issue) + notify.NotifyDeleteIssue(gitRepo.Ctx, doer, issue) return nil } diff --git a/services/issue/label.go b/services/issue/label.go index c18abbfcda3d2..743068cd834c6 100644 --- a/services/issue/label.go +++ b/services/issue/label.go @@ -8,7 +8,7 @@ import ( issues_model "code.gitea.io/gitea/models/issues" access_model "code.gitea.io/gitea/models/perm/access" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/notification" + "code.gitea.io/gitea/services/notify" ) // ClearLabels clears all of an issue's labels @@ -17,7 +17,7 @@ func ClearLabels(issue *issues_model.Issue, doer *user_model.User) (err error) { return } - notification.NotifyIssueClearLabels(db.DefaultContext, doer, issue) + notify.NotifyIssueClearLabels(db.DefaultContext, doer, issue) return nil } @@ -28,7 +28,7 @@ func AddLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_mo return err } - notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, []*issues_model.Label{label}, nil) + notify.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, []*issues_model.Label{label}, nil) return nil } @@ -38,7 +38,7 @@ func AddLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issue return err } - notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, nil) + notify.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, nil) return nil } @@ -73,7 +73,7 @@ func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues return err } - notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, nil, []*issues_model.Label{label}) + notify.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, nil, []*issues_model.Label{label}) return nil } @@ -88,6 +88,6 @@ func ReplaceLabels(issue *issues_model.Issue, doer *user_model.User, labels []*i return err } - notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, old) + notify.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, old) return nil } diff --git a/services/issue/milestone.go b/services/issue/milestone.go index a9be8bd887871..94e788423d2e4 100644 --- a/services/issue/milestone.go +++ b/services/issue/milestone.go @@ -10,7 +10,7 @@ import ( "code.gitea.io/gitea/models/db" issues_model "code.gitea.io/gitea/models/issues" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/notification" + "code.gitea.io/gitea/services/notify" ) func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) error { @@ -78,7 +78,7 @@ func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, old return fmt.Errorf("Commit: %w", err) } - notification.NotifyIssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID) + notify.NotifyIssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID) return nil } diff --git a/services/issue/status.go b/services/issue/status.go index 782ce0bd9675c..0d7152bd94cf7 100644 --- a/services/issue/status.go +++ b/services/issue/status.go @@ -10,7 +10,7 @@ import ( issues_model "code.gitea.io/gitea/models/issues" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" + "code.gitea.io/gitea/services/notify" ) // ChangeStatus changes issue status to open or closed. @@ -37,7 +37,7 @@ func changeStatusCtx(ctx context.Context, issue *issues_model.Issue, doer *user_ } } - notification.NotifyIssueChangeStatus(ctx, doer, issue, comment, closed) + notify.NotifyIssueChangeStatus(ctx, doer, issue, comment, closed) return nil } diff --git a/services/mailer/mailer.go b/services/mailer/mailer.go index ecc3a9ffa8ffa..b278ccba06f0d 100644 --- a/services/mailer/mailer.go +++ b/services/mailer/mailer.go @@ -21,11 +21,11 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" + "code.gitea.io/gitea/services/notify" "github.com/jaytaylor/html2text" "gopkg.in/gomail.v2" @@ -358,7 +358,7 @@ func NewContext(ctx context.Context) { } if setting.Service.EnableNotifyMail { - notification.RegisterNotifier(NewNotifier()) + notify.RegisterNotifier(NewNotifier()) } switch setting.MailService.Protocol { diff --git a/services/mailer/notifier.go b/services/mailer/notifier.go index f4cb569f0a087..4554a7d70c05a 100644 --- a/services/mailer/notifier.go +++ b/services/mailer/notifier.go @@ -12,17 +12,17 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" + "code.gitea.io/gitea/services/notify" ) type mailNotifier struct { - notification.NullNotifier + notify.NullNotifier } -var _ notification.Notifier = &mailNotifier{} +var _ notify.Notifier = &mailNotifier{} // NewNotifier create a new mailNotifier notifier -func NewNotifier() notification.Notifier { +func NewNotifier() notify.Notifier { return &mailNotifier{} } diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 98e8d122a5dfa..e86ab796c2c62 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -16,12 +16,12 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/process" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/notify" ) // gitShortEmptySha Git short empty SHA @@ -458,18 +458,18 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err) continue } - notification.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ + notify.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ RefFullName: result.refName, OldCommitID: git.EmptySHA, NewCommitID: commitID, }, repo_module.NewPushCommits()) - notification.NotifySyncCreateRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName, commitID) + notify.NotifySyncCreateRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName, commitID) continue } // Delete reference if result.newCommitID == gitShortEmptySha { - notification.NotifySyncDeleteRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName) + notify.NotifySyncDeleteRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName) continue } @@ -497,7 +497,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { theCommits.CompareURL = m.Repo.ComposeCompareURL(oldCommitID, newCommitID) - notification.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ + notify.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ RefFullName: result.refName, OldCommitID: oldCommitID, NewCommitID: newCommitID, diff --git a/services/mirror/notifier.go b/services/mirror/notifier.go index fa2fd785a9bde..a150f7c2944fa 100644 --- a/services/mirror/notifier.go +++ b/services/mirror/notifier.go @@ -10,23 +10,23 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" mirror_module "code.gitea.io/gitea/modules/mirror" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/repository" + "code.gitea.io/gitea/services/notify" ) type mirrorNotifier struct { - notification.NullNotifier + notify.NullNotifier } -var _ notification.Notifier = &mirrorNotifier{} +var _ notify.Notifier = &mirrorNotifier{} // NewNotifier create a new mirrorNotifier notifier -func NewNotifier() notification.Notifier { +func NewNotifier() notify.Notifier { return &mirrorNotifier{} } func init() { - notification.RegisterNotifier(NewNotifier()) + notify.RegisterNotifier(NewNotifier()) } func (m *mirrorNotifier) NotifyPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) { diff --git a/services/notification/notifier.go b/services/notification/notifier.go index 696e501b4e471..cb9c80719319b 100644 --- a/services/notification/notifier.go +++ b/services/notification/notifier.go @@ -14,13 +14,13 @@ import ( "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/queue" + "code.gitea.io/gitea/services/notify" ) type ( notificationService struct { - notification.NullNotifier + notify.NullNotifier issueQueue queue.Queue } @@ -32,17 +32,17 @@ type ( } ) -var _ notification.Notifier = ¬ificationService{} +var _ notify.Notifier = ¬ificationService{} // NewNotifier create a new notificationService notifier -func NewNotifier() notification.Notifier { +func NewNotifier() notify.Notifier { ns := ¬ificationService{} ns.issueQueue = queue.CreateQueue("notification-service", ns.handle, issueNotificationOpts{}) return ns } func init() { - notification.RegisterNotifier(NewNotifier()) + notify.RegisterNotifier(NewNotifier()) } func (ns *notificationService) handle(data ...queue.Data) []queue.Data { diff --git a/modules/notification/notifier.go b/services/notify/notifier.go similarity index 99% rename from modules/notification/notifier.go rename to services/notify/notifier.go index 3320c956074df..88dec6c279e97 100644 --- a/modules/notification/notifier.go +++ b/services/notify/notifier.go @@ -1,7 +1,7 @@ // Copyright 2018 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package notification +package notify import ( "context" diff --git a/modules/notification/notification.go b/services/notify/notify.go similarity index 84% rename from modules/notification/notification.go rename to services/notify/notify.go index 3ee2711cd0b29..c29c8fd850216 100644 --- a/modules/notification/notification.go +++ b/services/notify/notify.go @@ -1,7 +1,7 @@ // Copyright 2018 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package notification +package notify import ( "context" @@ -22,28 +22,28 @@ func RegisterNotifier(notifier Notifier) { } // NotifyNewWikiPage notifies creating new wiki pages to notifiers -func NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { +func NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { //nolint for _, notifier := range notifiers { notifier.NotifyNewWikiPage(ctx, doer, repo, page, comment) } } // NotifyEditWikiPage notifies editing or renaming wiki pages to notifiers -func NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { +func NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { //nolint for _, notifier := range notifiers { notifier.NotifyEditWikiPage(ctx, doer, repo, page, comment) } } // NotifyDeleteWikiPage notifies deleting wiki pages to notifiers -func NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { +func NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { //nolint for _, notifier := range notifiers { notifier.NotifyDeleteWikiPage(ctx, doer, repo, page) } } // NotifyCreateIssueComment notifies issue comment related message to notifiers -func NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, +func NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, //nolint issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, ) { for _, notifier := range notifiers { @@ -52,175 +52,175 @@ func NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo * } // NotifyNewIssue notifies new issue to notifiers -func NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { +func NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { //nolint for _, notifier := range notifiers { notifier.NotifyNewIssue(ctx, issue, mentions) } } // NotifyIssueChangeStatus notifies close or reopen issue to notifiers -func NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) { +func NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) { //nolint for _, notifier := range notifiers { notifier.NotifyIssueChangeStatus(ctx, doer, issue, actionComment, closeOrReopen) } } // NotifyDeleteIssue notify when some issue deleted -func NotifyDeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { +func NotifyDeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { //nolint for _, notifier := range notifiers { notifier.NotifyDeleteIssue(ctx, doer, issue) } } // NotifyMergePullRequest notifies merge pull request to notifiers -func NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +func NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { //nolint for _, notifier := range notifiers { notifier.NotifyMergePullRequest(ctx, doer, pr) } } // NotifyAutoMergePullRequest notifies merge pull request to notifiers -func NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +func NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { //nolint for _, notifier := range notifiers { notifier.NotifyAutoMergePullRequest(ctx, doer, pr) } } // NotifyNewPullRequest notifies new pull request to notifiers -func NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { +func NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { //nolint for _, notifier := range notifiers { notifier.NotifyNewPullRequest(ctx, pr, mentions) } } // NotifyPullRequestSynchronized notifies Synchronized pull request -func NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +func NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { //nolint for _, notifier := range notifiers { notifier.NotifyPullRequestSynchronized(ctx, doer, pr) } } // NotifyPullRequestReview notifies new pull request review -func NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { +func NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { //nolint for _, notifier := range notifiers { notifier.NotifyPullRequestReview(ctx, pr, review, comment, mentions) } } // NotifyPullRequestCodeComment notifies new pull request code comment -func NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { +func NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { //nolint for _, notifier := range notifiers { notifier.NotifyPullRequestCodeComment(ctx, pr, comment, mentions) } } // NotifyPullRequestChangeTargetBranch notifies when a pull request's target branch was changed -func NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) { +func NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) { //nolint for _, notifier := range notifiers { notifier.NotifyPullRequestChangeTargetBranch(ctx, doer, pr, oldBranch) } } // NotifyPullRequestPushCommits notifies when push commits to pull request's head branch -func NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { +func NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { //nolint for _, notifier := range notifiers { notifier.NotifyPullRequestPushCommits(ctx, doer, pr, comment) } } // NotifyPullReviewDismiss notifies when a review was dismissed by repo admin -func NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { +func NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { //nolint for _, notifier := range notifiers { notifier.NotifyPullReviewDismiss(ctx, doer, review, comment) } } // NotifyUpdateComment notifies update comment to notifiers -func NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { +func NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { //nolint for _, notifier := range notifiers { notifier.NotifyUpdateComment(ctx, doer, c, oldContent) } } // NotifyDeleteComment notifies delete comment to notifiers -func NotifyDeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) { +func NotifyDeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) { //nolint for _, notifier := range notifiers { notifier.NotifyDeleteComment(ctx, doer, c) } } // NotifyNewRelease notifies new release to notifiers -func NotifyNewRelease(ctx context.Context, rel *repo_model.Release) { +func NotifyNewRelease(ctx context.Context, rel *repo_model.Release) { //nolint for _, notifier := range notifiers { notifier.NotifyNewRelease(ctx, rel) } } // NotifyUpdateRelease notifies update release to notifiers -func NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { +func NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { //nolint for _, notifier := range notifiers { notifier.NotifyUpdateRelease(ctx, doer, rel) } } // NotifyDeleteRelease notifies delete release to notifiers -func NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { +func NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { //nolint for _, notifier := range notifiers { notifier.NotifyDeleteRelease(ctx, doer, rel) } } // NotifyIssueChangeMilestone notifies change milestone to notifiers -func NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) { +func NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) { //nolint for _, notifier := range notifiers { notifier.NotifyIssueChangeMilestone(ctx, doer, issue, oldMilestoneID) } } // NotifyIssueChangeContent notifies change content to notifiers -func NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { +func NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { //nolint for _, notifier := range notifiers { notifier.NotifyIssueChangeContent(ctx, doer, issue, oldContent) } } // NotifyIssueChangeAssignee notifies change content to notifiers -func NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { +func NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { //nolint for _, notifier := range notifiers { notifier.NotifyIssueChangeAssignee(ctx, doer, issue, assignee, removed, comment) } } // NotifyPullReviewRequest notifies Request Review change -func NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { +func NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { //nolint for _, notifier := range notifiers { notifier.NotifyPullReviewRequest(ctx, doer, issue, reviewer, isRequest, comment) } } // NotifyIssueClearLabels notifies clear labels to notifiers -func NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { +func NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { //nolint for _, notifier := range notifiers { notifier.NotifyIssueClearLabels(ctx, doer, issue) } } // NotifyIssueChangeTitle notifies change title to notifiers -func NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { +func NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { //nolint for _, notifier := range notifiers { notifier.NotifyIssueChangeTitle(ctx, doer, issue, oldTitle) } } // NotifyIssueChangeRef notifies change reference to notifiers -func NotifyIssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) { +func NotifyIssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) { //nolint for _, notifier := range notifiers { notifier.NotifyIssueChangeRef(ctx, doer, issue, oldRef) } } // NotifyIssueChangeLabels notifies change labels to notifiers -func NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, +func NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, //nolint addedLabels, removedLabels []*issues_model.Label, ) { for _, notifier := range notifiers { @@ -229,105 +229,105 @@ func NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue * } // NotifyCreateRepository notifies create repository to notifiers -func NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { +func NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { //nolint for _, notifier := range notifiers { notifier.NotifyCreateRepository(ctx, doer, u, repo) } } // NotifyMigrateRepository notifies create repository to notifiers -func NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { +func NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { //nolint for _, notifier := range notifiers { notifier.NotifyMigrateRepository(ctx, doer, u, repo) } } // NotifyTransferRepository notifies create repository to notifiers -func NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, newOwnerName string) { +func NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, newOwnerName string) { //nolint for _, notifier := range notifiers { notifier.NotifyTransferRepository(ctx, doer, repo, newOwnerName) } } // NotifyDeleteRepository notifies delete repository to notifiers -func NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { +func NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { //nolint for _, notifier := range notifiers { notifier.NotifyDeleteRepository(ctx, doer, repo) } } // NotifyForkRepository notifies fork repository to notifiers -func NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { +func NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { //nolint for _, notifier := range notifiers { notifier.NotifyForkRepository(ctx, doer, oldRepo, repo) } } // NotifyRenameRepository notifies repository renamed -func NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldName string) { +func NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldName string) { //nolint for _, notifier := range notifiers { notifier.NotifyRenameRepository(ctx, doer, repo, oldName) } } // NotifyPushCommits notifies commits pushed to notifiers -func NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { //nolint for _, notifier := range notifiers { notifier.NotifyPushCommits(ctx, pusher, repo, opts, commits) } } // NotifyCreateRef notifies branch or tag creation to notifiers -func NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { +func NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { //nolint for _, notifier := range notifiers { notifier.NotifyCreateRef(ctx, pusher, repo, refType, refFullName, refID) } } // NotifyDeleteRef notifies branch or tag deletion to notifiers -func NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { +func NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { //nolint for _, notifier := range notifiers { notifier.NotifyDeleteRef(ctx, pusher, repo, refType, refFullName) } } // NotifySyncPushCommits notifies commits pushed to notifiers -func NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { //nolint for _, notifier := range notifiers { notifier.NotifySyncPushCommits(ctx, pusher, repo, opts, commits) } } // NotifySyncCreateRef notifies branch or tag creation to notifiers -func NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { +func NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { //nolint for _, notifier := range notifiers { notifier.NotifySyncCreateRef(ctx, pusher, repo, refType, refFullName, refID) } } // NotifySyncDeleteRef notifies branch or tag deletion to notifiers -func NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { +func NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { //nolint for _, notifier := range notifiers { notifier.NotifySyncDeleteRef(ctx, pusher, repo, refType, refFullName) } } // NotifyRepoPendingTransfer notifies creation of pending transfer to notifiers -func NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { +func NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { //nolint for _, notifier := range notifiers { notifier.NotifyRepoPendingTransfer(ctx, doer, newOwner, repo) } } // NotifyPackageCreate notifies creation of a package to notifiers -func NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { +func NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { //nolint for _, notifier := range notifiers { notifier.NotifyPackageCreate(ctx, doer, pd) } } // NotifyPackageDelete notifies deletion of a package to notifiers -func NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { +func NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { //nolint for _, notifier := range notifiers { notifier.NotifyPackageDelete(ctx, doer, pd) } diff --git a/modules/notification/null.go b/services/notify/null.go similarity index 99% rename from modules/notification/null.go rename to services/notify/null.go index c86abe8672ef6..ac8db08e72171 100644 --- a/modules/notification/null.go +++ b/services/notify/null.go @@ -1,7 +1,7 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package notification +package notify import ( "context" diff --git a/services/packages/packages.go b/services/packages/packages.go index 49f5a2fac4e21..c85fd29cd6f21 100644 --- a/services/packages/packages.go +++ b/services/packages/packages.go @@ -18,10 +18,10 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" packages_module "code.gitea.io/gitea/modules/packages" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/notify" container_service "code.gitea.io/gitea/services/packages/container" ) @@ -113,7 +113,7 @@ func createPackageAndAddFile(pvci *PackageCreationInfo, pfci *PackageFileCreatio return nil, nil, err } - notification.NotifyPackageCreate(db.DefaultContext, pvci.Creator, pd) + notify.NotifyPackageCreate(db.DefaultContext, pvci.Creator, pd) } return pv, pf, nil @@ -409,7 +409,7 @@ func RemovePackageVersion(doer *user_model.User, pv *packages_model.PackageVersi return err } - notification.NotifyPackageDelete(db.DefaultContext, doer, pd) + notify.NotifyPackageDelete(db.DefaultContext, doer, pd) return nil } diff --git a/services/pull/check.go b/services/pull/check.go index 86460cd49cad0..d1b6bc16aa36f 100644 --- a/services/pull/check.go +++ b/services/pull/check.go @@ -22,12 +22,12 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" asymkey_service "code.gitea.io/gitea/services/asymkey" + "code.gitea.io/gitea/services/notify" ) // prPatchCheckerQueue represents a queue to handle update pull request tests @@ -277,7 +277,7 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool { return false } - notification.NotifyMergePullRequest(ctx, merger, pr) + notify.NotifyMergePullRequest(ctx, merger, pr) log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commit.ID.String()) return true diff --git a/services/pull/merge.go b/services/pull/merge.go index 7a936163f1fe2..c99a049439f68 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -29,13 +29,13 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/references" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" asymkey_service "code.gitea.io/gitea/services/asymkey" issue_service "code.gitea.io/gitea/services/issue" + "code.gitea.io/gitea/services/notify" ) // GetDefaultMergeMessage returns default message used when merging pull request @@ -201,9 +201,9 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U } if wasAutoMerged { - notification.NotifyAutoMergePullRequest(hammerCtx, doer, pr) + notify.NotifyAutoMergePullRequest(hammerCtx, doer, pr) } else { - notification.NotifyMergePullRequest(hammerCtx, doer, pr) + notify.NotifyMergePullRequest(hammerCtx, doer, pr) } // Reset cached commit count @@ -885,7 +885,7 @@ func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGit return err } - notification.NotifyMergePullRequest(baseGitRepo.Ctx, doer, pr) + notify.NotifyMergePullRequest(baseGitRepo.Ctx, doer, pr) log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commitID) return nil } diff --git a/services/pull/pull.go b/services/pull/pull.go index afb0fa244244b..50898cd37f8de 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -24,12 +24,12 @@ import ( "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/process" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/sync" issue_service "code.gitea.io/gitea/services/issue" + "code.gitea.io/gitea/services/notify" ) // TODO: use clustered lock (unique queue? or *abuse* cache) @@ -81,12 +81,12 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *issu return err } - notification.NotifyNewPullRequest(prCtx, pr, mentions) + notify.NotifyNewPullRequest(prCtx, pr, mentions) if len(pull.Labels) > 0 { - notification.NotifyIssueChangeLabels(prCtx, pull.Poster, pull, pull.Labels, nil) + notify.NotifyIssueChangeLabels(prCtx, pull.Poster, pull, pull.Labels, nil) } if pull.Milestone != nil { - notification.NotifyIssueChangeMilestone(prCtx, pull.Poster, pull, 0) + notify.NotifyIssueChangeMilestone(prCtx, pull.Poster, pull, 0) } // add first push codes comment @@ -300,7 +300,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, } pr.Issue.PullRequest = pr - notification.NotifyPullRequestSynchronized(ctx, doer, pr) + notify.NotifyPullRequestSynchronized(ctx, doer, pr) } } } @@ -319,7 +319,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, AddToTaskQueue(pr) comment, err := CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID) if err == nil && comment != nil { - notification.NotifyPullRequestPushCommits(ctx, doer, pr, comment) + notify.NotifyPullRequestPushCommits(ctx, doer, pr, comment) } } diff --git a/services/pull/review.go b/services/pull/review.go index 67a10d7aad61c..2591f0e8c2810 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -17,10 +17,10 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" issue_service "code.gitea.io/gitea/services/issue" + "code.gitea.io/gitea/services/notify" ) // CreateCodeComment creates a comment on the code line @@ -67,7 +67,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git. return nil, err } - notification.NotifyCreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions) + notify.NotifyCreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions) return comment, nil } @@ -254,7 +254,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos return nil, nil, err } - notification.NotifyPullRequestReview(ctx, pr, review, comm, mentions) + notify.NotifyPullRequestReview(ctx, pr, review, comm, mentions) for _, lines := range review.CodeComments { for _, comments := range lines { @@ -263,7 +263,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos if err != nil { return nil, nil, err } - notification.NotifyPullRequestCodeComment(ctx, pr, codeComment, mentions) + notify.NotifyPullRequestCodeComment(ctx, pr, codeComment, mentions) } } } @@ -339,7 +339,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string, comment.Poster = doer comment.Issue = review.Issue - notification.NotifyPullReviewDismiss(ctx, doer, review, comment) + notify.NotifyPullReviewDismiss(ctx, doer, review, comment) return comment, err } diff --git a/services/release/release.go b/services/release/release.go index 13042cd3ac2e8..3affcf751c64b 100644 --- a/services/release/release.go +++ b/services/release/release.go @@ -17,11 +17,11 @@ import ( "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/notify" ) func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) { @@ -80,14 +80,14 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel commits.HeadCommit = repository.CommitToPushCommit(commit) commits.CompareURL = rel.Repo.ComposeCompareURL(git.EmptySHA, commit.ID.String()) - notification.NotifyPushCommits( + notify.NotifyPushCommits( ctx, rel.Publisher, rel.Repo, &repository.PushUpdateOptions{ RefFullName: git.TagPrefix + rel.TagName, OldCommitID: git.EmptySHA, NewCommitID: commit.ID.String(), }, commits) - notification.NotifyCreateRef(ctx, rel.Publisher, rel.Repo, "tag", git.TagPrefix+rel.TagName, commit.ID.String()) + notify.NotifyCreateRef(ctx, rel.Publisher, rel.Repo, "tag", git.TagPrefix+rel.TagName, commit.ID.String()) rel.CreatedUnix = timeutil.TimeStampNow() } commit, err := gitRepo.GetTagCommit(rel.TagName) @@ -138,7 +138,7 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU } if !rel.IsDraft { - notification.NotifyNewRelease(gitRepo.Ctx, rel) + notify.NotifyNewRelease(gitRepo.Ctx, rel) } return nil @@ -278,12 +278,12 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod } if !isCreated { - notification.NotifyUpdateRelease(gitRepo.Ctx, doer, rel) + notify.NotifyUpdateRelease(gitRepo.Ctx, doer, rel) return } if !rel.IsDraft { - notification.NotifyNewRelease(gitRepo.Ctx, rel) + notify.NotifyNewRelease(gitRepo.Ctx, rel) } return err @@ -323,14 +323,14 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del return fmt.Errorf("git tag -d: %w", err) } - notification.NotifyPushCommits( + notify.NotifyPushCommits( ctx, doer, repo, &repository.PushUpdateOptions{ RefFullName: git.TagPrefix + rel.TagName, OldCommitID: rel.Sha1, NewCommitID: git.EmptySHA, }, repository.NewPushCommits()) - notification.NotifyDeleteRef(ctx, doer, repo, "tag", git.TagPrefix+rel.TagName) + notify.NotifyDeleteRef(ctx, doer, repo, "tag", git.TagPrefix+rel.TagName) if err := repo_model.DeleteReleaseByID(ctx, id); err != nil { return fmt.Errorf("DeleteReleaseByID: %w", err) @@ -359,7 +359,7 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del } } - notification.NotifyDeleteRelease(ctx, doer, rel) + notify.NotifyDeleteRelease(ctx, doer, rel) return nil } diff --git a/services/repository/adopt.go b/services/repository/adopt.go index 93eeb56456f45..0473e97b85202 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -17,10 +17,10 @@ import ( "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/notify" "github.com/gobwas/glob" ) @@ -95,7 +95,7 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption return nil, err } - notification.NotifyCreateRepository(db.DefaultContext, doer, u, repo) + notify.NotifyCreateRepository(db.DefaultContext, doer, u, repo) return repo, nil } diff --git a/services/repository/branch.go b/services/repository/branch.go index e5ffbbeb746ef..4946e32701bcb 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -16,8 +16,8 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" repo_module "code.gitea.io/gitea/modules/repository" + "code.gitea.io/gitea/services/notify" pull_service "code.gitea.io/gitea/services/pull" ) @@ -141,8 +141,8 @@ func RenameBranch(repo *repo_model.Repository, doer *user_model.User, gitRepo *g return "", err } - notification.NotifyDeleteRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+from) - notification.NotifyCreateRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+to, refID) + notify.NotifyDeleteRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+from) + notify.NotifyCreateRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+to, refID) return "", nil } diff --git a/services/repository/fork.go b/services/repository/fork.go index ad534be887f1b..4c957e61341dd 100644 --- a/services/repository/fork.go +++ b/services/repository/fork.go @@ -15,10 +15,10 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/notify" ) // ErrForkAlreadyExist represents a "ForkAlreadyExist" kind of error. @@ -183,7 +183,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork } } - notification.NotifyForkRepository(ctx, doer, opts.BaseRepo, repo) + notify.NotifyForkRepository(ctx, doer, opts.BaseRepo, repo) return repo, nil } diff --git a/services/repository/push.go b/services/repository/push.go index f1eedb8e08398..c32ee845bce94 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -18,13 +18,13 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/queue" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" issue_service "code.gitea.io/gitea/services/issue" + "code.gitea.io/gitea/services/notify" pull_service "code.gitea.io/gitea/services/pull" ) @@ -115,7 +115,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } tagName := opts.TagName() if opts.IsDelRef() { - notification.NotifyPushCommits( + notify.NotifyPushCommits( db.DefaultContext, pusher, repo, &repo_module.PushUpdateOptions{ RefFullName: git.TagPrefix + tagName, @@ -124,7 +124,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { }, repo_module.NewPushCommits()) delTags = append(delTags, tagName) - notification.NotifyDeleteRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName) + notify.NotifyDeleteRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName) } else { // is new tag newCommit, err := gitRepo.GetCommit(opts.NewCommitID) if err != nil { @@ -135,7 +135,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { commits.HeadCommit = repo_module.CommitToPushCommit(newCommit) commits.CompareURL = repo.ComposeCompareURL(git.EmptySHA, opts.NewCommitID) - notification.NotifyPushCommits( + notify.NotifyPushCommits( db.DefaultContext, pusher, repo, &repo_module.PushUpdateOptions{ RefFullName: git.TagPrefix + tagName, @@ -144,7 +144,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { }, commits) addTags = append(addTags, tagName) - notification.NotifyCreateRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName, opts.NewCommitID) + notify.NotifyCreateRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName, opts.NewCommitID) } } else if opts.IsBranch() { // If is branch reference if pusher == nil || pusher.ID != opts.PusherID { @@ -189,7 +189,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { if err != nil { return fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err) } - notification.NotifyCreateRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName, opts.NewCommitID) + notify.NotifyCreateRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName, opts.NewCommitID) } else { l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID) if err != nil { @@ -249,7 +249,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { commits.Commits = commits.Commits[:setting.UI.FeedMaxCommitNum] } - notification.NotifyPushCommits(db.DefaultContext, pusher, repo, opts, commits) + notify.NotifyPushCommits(db.DefaultContext, pusher, repo, opts, commits) if err = git_model.RemoveDeletedBranchByName(repo.ID, branch); err != nil { log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, branch, err) @@ -260,7 +260,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { log.Error("repo_module.CacheRef %s/%s failed: %v", repo.ID, branch, err) } } else { - notification.NotifyDeleteRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName) + notify.NotifyDeleteRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName) if err = pull_service.CloseBranchPulls(pusher, repo.ID, branch); err != nil { // close all related pulls log.Error("close related pull request failed: %v", err) diff --git a/services/repository/repository.go b/services/repository/repository.go index 3c3e7e82c3f8f..03db0b50c0931 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -17,9 +17,9 @@ import ( "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" + notify_service "code.gitea.io/gitea/services/notify" pull_service "code.gitea.io/gitea/services/pull" ) @@ -31,7 +31,7 @@ func CreateRepository(doer, owner *user_model.User, opts repo_module.CreateRepoO return nil, err } - notification.NotifyCreateRepository(db.DefaultContext, doer, owner, repo) + notify_service.NotifyCreateRepository(db.DefaultContext, doer, owner, repo) return repo, nil } @@ -44,7 +44,7 @@ func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_mod if notify { // If the repo itself has webhooks, we need to trigger them before deleting it... - notification.NotifyDeleteRepository(ctx, doer, repo) + notify_service.NotifyDeleteRepository(ctx, doer, repo) } if err := models.DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil { diff --git a/services/repository/template.go b/services/repository/template.go index 13e0749869396..f429467d9f65a 100644 --- a/services/repository/template.go +++ b/services/repository/template.go @@ -10,8 +10,8 @@ import ( issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/notification" repo_module "code.gitea.io/gitea/modules/repository" + "code.gitea.io/gitea/services/notify" ) // GenerateIssueLabels generates issue labels from a template repository @@ -100,7 +100,7 @@ func GenerateRepository(doer, owner *user_model.User, templateRepo *repo_model.R return nil, err } - notification.NotifyCreateRepository(db.DefaultContext, doer, owner, generateRepo) + notify.NotifyCreateRepository(db.DefaultContext, doer, owner, generateRepo) return generateRepo, nil } diff --git a/services/repository/transfer.go b/services/repository/transfer.go index f4afb7e2dec28..65690e3f0a84f 100644 --- a/services/repository/transfer.go +++ b/services/repository/transfer.go @@ -15,9 +15,9 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/sync" + "code.gitea.io/gitea/services/notify" ) // repoWorkingPool represents a working pool to order the parallel changes to the same repository @@ -55,7 +55,7 @@ func TransferOwnership(ctx context.Context, doer, newOwner *user_model.User, rep } } - notification.NotifyTransferRepository(ctx, doer, repo, oldOwner.Name) + notify.NotifyTransferRepository(ctx, doer, repo, oldOwner.Name) return nil } @@ -78,7 +78,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *repo_model.Repository, ne repoWorkingPool.CheckOut(fmt.Sprint(repo.ID)) repo.Name = newRepoName - notification.NotifyRenameRepository(db.DefaultContext, doer, repo, oldRepoName) + notify.NotifyRenameRepository(db.DefaultContext, doer, repo, oldRepoName) return nil } @@ -127,7 +127,7 @@ func StartRepositoryTransfer(ctx context.Context, doer, newOwner *user_model.Use } // notify users who are able to accept / reject transfer - notification.NotifyRepoPendingTransfer(ctx, doer, newOwner, repo) + notify.NotifyRepoPendingTransfer(ctx, doer, newOwner, repo) return nil } diff --git a/services/task/migrate.go b/services/task/migrate.go index 03d083e596674..b48e30a165cc9 100644 --- a/services/task/migrate.go +++ b/services/task/migrate.go @@ -17,12 +17,12 @@ import ( "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/migration" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/migrations" + "code.gitea.io/gitea/services/notify" ) func handleCreateError(owner *user_model.User, err error) error { @@ -50,7 +50,7 @@ func runMigrateTask(t *admin_model.Task) (err error) { if err == nil { err = admin_model.FinishMigrateTask(t) if err == nil { - notification.NotifyMigrateRepository(db.DefaultContext, t.Doer, t.Owner, t.Repo) + notify.NotifyMigrateRepository(db.DefaultContext, t.Doer, t.Owner, t.Repo) return } diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 55b1bd851bd9e..10fcd55bf180d 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -15,26 +15,26 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" webhook_module "code.gitea.io/gitea/modules/webhook" "code.gitea.io/gitea/services/convert" + "code.gitea.io/gitea/services/notify" ) func init() { - notification.RegisterNotifier(&webhookNotifier{}) + notify.RegisterNotifier(&webhookNotifier{}) } type webhookNotifier struct { - notification.NullNotifier + notify.NullNotifier } -var _ notification.Notifier = &webhookNotifier{} +var _ notify.Notifier = &webhookNotifier{} // NewNotifier create a new webhookNotifier notifier -func NewNotifier() notification.Notifier { +func NewNotifier() notify.Notifier { return &webhookNotifier{} } From cf0d0c387c789077a72b3d8f9b81f975edbdf5fc Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 2 Jan 2023 10:38:13 +0800 Subject: [PATCH 06/12] follow @delvh suggestion --- main.go | 2 +- routers/api/packages/conan/conan.go | 2 +- routers/api/v1/repo/issue.go | 4 +- routers/api/v1/repo/migrate.go | 2 +- routers/api/v1/repo/pull.go | 6 +- routers/api/v1/repo/wiki.go | 6 +- routers/init.go | 2 + routers/web/repo/pull.go | 2 +- routers/web/repo/wiki.go | 6 +- services/agit/agit.go | 4 +- services/feed/action_test.go | 2 +- services/issue/assignee.go | 6 +- services/issue/comments.go | 6 +- services/issue/content.go | 2 +- services/issue/issue.go | 12 +- services/issue/label.go | 10 +- services/issue/milestone.go | 2 +- services/issue/status.go | 2 +- services/mirror/mirror_pull.go | 8 +- services/notify/notifier.go | 88 +++--- services/notify/notify.go | 264 +++++++++--------- services/notify/null.go | 176 ++++++------ services/packages/packages.go | 4 +- services/pull/check.go | 2 +- services/pull/merge.go | 6 +- services/pull/pull.go | 10 +- services/pull/review.go | 8 +- services/release/release.go | 16 +- services/repository/adopt.go | 2 +- services/repository/branch.go | 4 +- services/repository/fork.go | 2 +- services/repository/push.go | 14 +- services/repository/repository.go | 10 +- services/repository/template.go | 2 +- services/repository/transfer.go | 6 +- services/task/migrate.go | 2 +- .../notifier.go | 6 +- 37 files changed, 356 insertions(+), 352 deletions(-) rename services/{notification => uinotification}/notifier.go (98%) diff --git a/main.go b/main.go index f9d3d34cd1386..5aaa56c7deaa0 100644 --- a/main.go +++ b/main.go @@ -22,9 +22,9 @@ import ( _ "code.gitea.io/gitea/modules/markup/markdown" _ "code.gitea.io/gitea/modules/markup/orgmode" + // register supported notify types _ "code.gitea.io/gitea/services/feed" _ "code.gitea.io/gitea/services/indexer" - _ "code.gitea.io/gitea/services/notification" "github.com/urfave/cli" ) diff --git a/routers/api/packages/conan/conan.go b/routers/api/packages/conan/conan.go index 68738788c248f..b11c83b23e57b 100644 --- a/routers/api/packages/conan/conan.go +++ b/routers/api/packages/conan/conan.go @@ -678,7 +678,7 @@ func deleteRecipeOrPackage(apictx *context.Context, rref *conan_module.RecipeRef } if versionDeleted { - notify.NotifyPackageDelete(apictx, apictx.Doer, pd) + notify.PackageDelete(apictx, apictx.Doer, pd) } return nil diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 09dfefbfcd07e..3d8dc3337ed85 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -822,11 +822,11 @@ func EditIssue(ctx *context.APIContext) { } if titleChanged { - notify.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) + notify.IssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) } if statusChangeComment != nil { - notify.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed) + notify.IssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed) } // Refetch from database to assign some automatic values diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index 89031fd883d24..80d959a10f4b1 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -194,7 +194,7 @@ func Migrate(ctx *context.APIContext) { } if err == nil { - notify.NotifyMigrateRepository(ctx, ctx.Doer, repoOwner, repo) + notify.MigrateRepository(ctx, ctx.Doer, repoOwner, repo) return } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 2a8787e283fc9..92b2e3c294a5a 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -595,11 +595,11 @@ func EditPullRequest(ctx *context.APIContext) { } if titleChanged { - notify.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) + notify.IssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) } if statusChangeComment != nil { - notify.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed) + notify.IssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed) } // change pull target branch @@ -623,7 +623,7 @@ func EditPullRequest(ctx *context.APIContext) { } return } - notify.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base) + notify.PullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base) } // update allow edits diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index 654324a83e39b..a5c82e89f7549 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -85,7 +85,7 @@ func NewWikiPage(ctx *context.APIContext) { wikiPage := getWikiPage(ctx, wikiName) if !ctx.Written() { - notify.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message) + notify.NewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message) ctx.JSON(http.StatusCreated, wikiPage) } } @@ -153,7 +153,7 @@ func EditWikiPage(ctx *context.APIContext) { wikiPage := getWikiPage(ctx, newWikiName) if !ctx.Written() { - notify.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message) + notify.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message) ctx.JSON(http.StatusOK, wikiPage) } } @@ -244,7 +244,7 @@ func DeleteWikiPage(ctx *context.APIContext) { return } - notify.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName) + notify.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName) ctx.Status(http.StatusNoContent) } diff --git a/routers/init.go b/routers/init.go index fd96507d5a207..c628ed38d655a 100644 --- a/routers/init.go +++ b/routers/init.go @@ -46,6 +46,7 @@ import ( repo_service "code.gitea.io/gitea/services/repository" "code.gitea.io/gitea/services/repository/archiver" "code.gitea.io/gitea/services/task" + "code.gitea.io/gitea/services/uinotification" "code.gitea.io/gitea/services/webhook" ) @@ -128,6 +129,7 @@ func GlobalInitInstalled(ctx context.Context) { mailer.NewContext(ctx) mustInit(cache.NewContext) + mustInit(uinotification.Init) mustInit(archiver.Init) highlight.NewContext() diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index befbcbf5d0300..fc8cfdea67b7f 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -1511,7 +1511,7 @@ func UpdatePullRequestTarget(ctx *context.Context) { } return } - notify.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, targetBranch) + notify.PullRequestChangeTargetBranch(ctx, ctx.Doer, pr, targetBranch) ctx.JSON(http.StatusOK, map[string]interface{}{ "base_branch": pr.BaseBranch, diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index a97166347d543..ffed1291d7dbf 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -705,7 +705,7 @@ func NewWikiPost(ctx *context.Context) { return } - notify.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message) + notify.NewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(wikiName)) } @@ -749,7 +749,7 @@ func EditWikiPost(ctx *context.Context) { return } - notify.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message) + notify.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(newWikiName)) } @@ -766,7 +766,7 @@ func DeleteWikiPagePost(ctx *context.Context) { return } - notify.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName) + notify.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName) ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/wiki/", diff --git a/services/agit/agit.go b/services/agit/agit.go index b6a0b76d625f2..b1dca27c21f30 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -208,9 +208,9 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. } comment, err := pull_service.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i]) if err == nil && comment != nil { - notify.NotifyPullRequestPushCommits(ctx, pusher, pr, comment) + notify.PullRequestPushCommits(ctx, pusher, pr, comment) } - notify.NotifyPullRequestSynchronized(ctx, pusher, pr) + notify.PullRequestSynchronized(ctx, pusher, pr) isForcePush := comment != nil && comment.IsForcePush results = append(results, private.HookProcReceiveRefResult{ diff --git a/services/feed/action_test.go b/services/feed/action_test.go index 0c36231458afe..de5e90917a514 100644 --- a/services/feed/action_test.go +++ b/services/feed/action_test.go @@ -39,7 +39,7 @@ func TestRenameRepoAction(t *testing.T) { } unittest.AssertNotExistsBean(t, actionBean) - NewNotifier().NotifyRenameRepository(db.DefaultContext, user, repo, oldRepoName) + NewNotifier().RenameRepository(db.DefaultContext, user, repo, oldRepoName) unittest.AssertExistsAndLoadBean(t, actionBean) unittest.CheckConsistencyFor(t, &activities_model.Action{}) diff --git a/services/issue/assignee.go b/services/issue/assignee.go index ecc8fdfd63ec0..8ceec48e496b4 100644 --- a/services/issue/assignee.go +++ b/services/issue/assignee.go @@ -56,7 +56,7 @@ func ToggleAssignee(issue *issues_model.Issue, doer *user_model.User, assigneeID return } - notify.NotifyIssueChangeAssignee(db.DefaultContext, doer, issue, assignee, removed, comment) + notify.IssueChangeAssignee(db.DefaultContext, doer, issue, assignee, removed, comment) return removed, comment, err } @@ -74,7 +74,7 @@ func ReviewRequest(issue *issues_model.Issue, doer, reviewer *user_model.User, i } if comment != nil { - notify.NotifyPullReviewRequest(db.DefaultContext, doer, issue, reviewer, isAdd, comment) + notify.PullReviewRequest(db.DefaultContext, doer, issue, reviewer, isAdd, comment) } return comment, err @@ -261,7 +261,7 @@ func TeamReviewRequest(issue *issues_model.Issue, doer *user_model.User, reviewe continue } comment.AssigneeID = member.ID - notify.NotifyPullReviewRequest(db.DefaultContext, doer, issue, member, isAdd, comment) + notify.PullReviewRequest(db.DefaultContext, doer, issue, member, isAdd, comment) } return comment, err diff --git a/services/issue/comments.go b/services/issue/comments.go index c66c12d3b1c84..d499d7a05d646 100644 --- a/services/issue/comments.go +++ b/services/issue/comments.go @@ -83,7 +83,7 @@ func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_m return nil, err } - notify.NotifyCreateIssueComment(ctx, doer, repo, issue, comment, mentions) + notify.CreateIssueComment(ctx, doer, repo, issue, comment, mentions) return comment, nil } @@ -116,7 +116,7 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, doer *user_mode } } - notify.NotifyUpdateComment(ctx, doer, c, oldContent) + notify.UpdateComment(ctx, doer, c, oldContent) return nil } @@ -130,7 +130,7 @@ func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_m return err } - notify.NotifyDeleteComment(ctx, doer, comment) + notify.DeleteComment(ctx, doer, comment) return nil } diff --git a/services/issue/content.go b/services/issue/content.go index 60a42c5122a2c..4a064f5a3c76f 100644 --- a/services/issue/content.go +++ b/services/issue/content.go @@ -18,7 +18,7 @@ func ChangeContent(issue *issues_model.Issue, doer *user_model.User, content str return err } - notify.NotifyIssueChangeContent(db.DefaultContext, doer, issue, oldContent) + notify.IssueChangeContent(db.DefaultContext, doer, issue, oldContent) return nil } diff --git a/services/issue/issue.go b/services/issue/issue.go index de3ff75f58599..8024af1e316a3 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -36,12 +36,12 @@ func NewIssue(repo *repo_model.Repository, issue *issues_model.Issue, labelIDs [ return err } - notify.NotifyNewIssue(db.DefaultContext, issue, mentions) + notify.NewIssue(db.DefaultContext, issue, mentions) if len(issue.Labels) > 0 { - notify.NotifyIssueChangeLabels(db.DefaultContext, issue.Poster, issue, issue.Labels, nil) + notify.IssueChangeLabels(db.DefaultContext, issue.Poster, issue, issue.Labels, nil) } if issue.Milestone != nil { - notify.NotifyIssueChangeMilestone(db.DefaultContext, issue.Poster, issue, 0) + notify.IssueChangeMilestone(db.DefaultContext, issue.Poster, issue, 0) } return nil @@ -56,7 +56,7 @@ func ChangeTitle(issue *issues_model.Issue, doer *user_model.User, title string) return } - notify.NotifyIssueChangeTitle(db.DefaultContext, doer, issue, oldTitle) + notify.IssueChangeTitle(db.DefaultContext, doer, issue, oldTitle) return nil } @@ -70,7 +70,7 @@ func ChangeIssueRef(issue *issues_model.Issue, doer *user_model.User, ref string return err } - notify.NotifyIssueChangeRef(db.DefaultContext, doer, issue, oldRef) + notify.IssueChangeRef(db.DefaultContext, doer, issue, oldRef) return nil } @@ -152,7 +152,7 @@ func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_m } } - notify.NotifyDeleteIssue(gitRepo.Ctx, doer, issue) + notify.DeleteIssue(gitRepo.Ctx, doer, issue) return nil } diff --git a/services/issue/label.go b/services/issue/label.go index 743068cd834c6..a1ebea96144d8 100644 --- a/services/issue/label.go +++ b/services/issue/label.go @@ -17,7 +17,7 @@ func ClearLabels(issue *issues_model.Issue, doer *user_model.User) (err error) { return } - notify.NotifyIssueClearLabels(db.DefaultContext, doer, issue) + notify.IssueClearLabels(db.DefaultContext, doer, issue) return nil } @@ -28,7 +28,7 @@ func AddLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_mo return err } - notify.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, []*issues_model.Label{label}, nil) + notify.IssueChangeLabels(db.DefaultContext, doer, issue, []*issues_model.Label{label}, nil) return nil } @@ -38,7 +38,7 @@ func AddLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issue return err } - notify.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, nil) + notify.IssueChangeLabels(db.DefaultContext, doer, issue, labels, nil) return nil } @@ -73,7 +73,7 @@ func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues return err } - notify.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, nil, []*issues_model.Label{label}) + notify.IssueChangeLabels(db.DefaultContext, doer, issue, nil, []*issues_model.Label{label}) return nil } @@ -88,6 +88,6 @@ func ReplaceLabels(issue *issues_model.Issue, doer *user_model.User, labels []*i return err } - notify.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, old) + notify.IssueChangeLabels(db.DefaultContext, doer, issue, labels, old) return nil } diff --git a/services/issue/milestone.go b/services/issue/milestone.go index 94e788423d2e4..332acfd1b3ce9 100644 --- a/services/issue/milestone.go +++ b/services/issue/milestone.go @@ -78,7 +78,7 @@ func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, old return fmt.Errorf("Commit: %w", err) } - notify.NotifyIssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID) + notify.IssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID) return nil } diff --git a/services/issue/status.go b/services/issue/status.go index 0d7152bd94cf7..05a1c4c01efb5 100644 --- a/services/issue/status.go +++ b/services/issue/status.go @@ -37,7 +37,7 @@ func changeStatusCtx(ctx context.Context, issue *issues_model.Issue, doer *user_ } } - notify.NotifyIssueChangeStatus(ctx, doer, issue, comment, closed) + notify.IssueChangeStatus(ctx, doer, issue, comment, closed) return nil } diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index e86ab796c2c62..ee7a9cc4545c6 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -458,18 +458,18 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err) continue } - notify.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ + notify.SyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ RefFullName: result.refName, OldCommitID: git.EmptySHA, NewCommitID: commitID, }, repo_module.NewPushCommits()) - notify.NotifySyncCreateRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName, commitID) + notify.SyncCreateRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName, commitID) continue } // Delete reference if result.newCommitID == gitShortEmptySha { - notify.NotifySyncDeleteRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName) + notify.SyncDeleteRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName) continue } @@ -497,7 +497,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { theCommits.CompareURL = m.Repo.ComposeCompareURL(oldCommitID, newCommitID) - notify.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ + notify.SyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ RefFullName: result.refName, OldCommitID: oldCommitID, NewCommitID: newCommitID, diff --git a/services/notify/notifier.go b/services/notify/notifier.go index 88dec6c279e97..51bd7a3e0331d 100644 --- a/services/notify/notifier.go +++ b/services/notify/notifier.go @@ -16,50 +16,50 @@ import ( // Notifier defines an interface to notify receiver type Notifier interface { Run() - NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) - NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) - NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) - NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) - NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) - NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) - NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) - NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) - NotifyDeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) - NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) - NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) - NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) - NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) - NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) - NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) - NotifyIssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) - NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, + CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) + MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) + DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) + ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) + RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) + TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) + NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) + IssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) + DeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) + IssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) + IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) + PullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) + IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) + IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) + IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) + IssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) + IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, addedLabels, removedLabels []*issues_model.Label) - NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) - NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) - NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) - NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) - NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) - NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) - NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) - NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) - NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) - NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, + NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) + MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) + AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) + PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) + PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) + PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) + PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) + PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) + PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) + CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User) - NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) - NotifyDeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) - NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) - NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) - NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) - NotifyNewRelease(ctx context.Context, rel *repo_model.Release) - NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) - NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) - NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) - NotifyCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) - NotifyDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) - NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) - NotifySyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) - NotifySyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) - NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) - NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) - NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) + UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) + DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) + NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) + EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) + DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) + NewRelease(ctx context.Context, rel *repo_model.Release) + UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) + DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) + PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) + CreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) + DeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) + SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) + SyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) + SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) + RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) + PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) + PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) } diff --git a/services/notify/notify.go b/services/notify/notify.go index c29c8fd850216..703b7ef42de42 100644 --- a/services/notify/notify.go +++ b/services/notify/notify.go @@ -21,314 +21,314 @@ func RegisterNotifier(notifier Notifier) { notifiers = append(notifiers, notifier) } -// NotifyNewWikiPage notifies creating new wiki pages to notifiers -func NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { //nolint +// NewWikiPage notifies creating new wiki pages to notifiers +func NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { for _, notifier := range notifiers { - notifier.NotifyNewWikiPage(ctx, doer, repo, page, comment) + notifier.NewWikiPage(ctx, doer, repo, page, comment) } } -// NotifyEditWikiPage notifies editing or renaming wiki pages to notifiers -func NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { //nolint +// EditWikiPage notifies editing or renaming wiki pages to notifiers +func EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { for _, notifier := range notifiers { - notifier.NotifyEditWikiPage(ctx, doer, repo, page, comment) + notifier.EditWikiPage(ctx, doer, repo, page, comment) } } -// NotifyDeleteWikiPage notifies deleting wiki pages to notifiers -func NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { //nolint +// DeleteWikiPage notifies deleting wiki pages to notifiers +func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { for _, notifier := range notifiers { - notifier.NotifyDeleteWikiPage(ctx, doer, repo, page) + notifier.DeleteWikiPage(ctx, doer, repo, page) } } -// NotifyCreateIssueComment notifies issue comment related message to notifiers -func NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, //nolint +// CreateIssueComment notifies issue comment related message to notifiers +func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, ) { for _, notifier := range notifiers { - notifier.NotifyCreateIssueComment(ctx, doer, repo, issue, comment, mentions) + notifier.CreateIssueComment(ctx, doer, repo, issue, comment, mentions) } } -// NotifyNewIssue notifies new issue to notifiers -func NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { //nolint +// NewIssue notifies new issue to notifiers +func NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { for _, notifier := range notifiers { - notifier.NotifyNewIssue(ctx, issue, mentions) + notifier.NewIssue(ctx, issue, mentions) } } -// NotifyIssueChangeStatus notifies close or reopen issue to notifiers -func NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) { //nolint +// IssueChangeStatus notifies close or reopen issue to notifiers +func IssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) { for _, notifier := range notifiers { - notifier.NotifyIssueChangeStatus(ctx, doer, issue, actionComment, closeOrReopen) + notifier.IssueChangeStatus(ctx, doer, issue, actionComment, closeOrReopen) } } -// NotifyDeleteIssue notify when some issue deleted -func NotifyDeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { //nolint +// DeleteIssue notify when some issue deleted +func DeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { for _, notifier := range notifiers { - notifier.NotifyDeleteIssue(ctx, doer, issue) + notifier.DeleteIssue(ctx, doer, issue) } } -// NotifyMergePullRequest notifies merge pull request to notifiers -func NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { //nolint +// MergePullRequest notifies merge pull request to notifiers +func MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { for _, notifier := range notifiers { - notifier.NotifyMergePullRequest(ctx, doer, pr) + notifier.MergePullRequest(ctx, doer, pr) } } -// NotifyAutoMergePullRequest notifies merge pull request to notifiers -func NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { //nolint +// AutoMergePullRequest notifies merge pull request to notifiers +func AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { for _, notifier := range notifiers { - notifier.NotifyAutoMergePullRequest(ctx, doer, pr) + notifier.AutoMergePullRequest(ctx, doer, pr) } } -// NotifyNewPullRequest notifies new pull request to notifiers -func NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { //nolint +// NewPullRequest notifies new pull request to notifiers +func NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { for _, notifier := range notifiers { - notifier.NotifyNewPullRequest(ctx, pr, mentions) + notifier.NewPullRequest(ctx, pr, mentions) } } -// NotifyPullRequestSynchronized notifies Synchronized pull request -func NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { //nolint +// PullRequestSynchronized notifies Synchronized pull request +func PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { for _, notifier := range notifiers { - notifier.NotifyPullRequestSynchronized(ctx, doer, pr) + notifier.PullRequestSynchronized(ctx, doer, pr) } } -// NotifyPullRequestReview notifies new pull request review -func NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { //nolint +// PullRequestReview notifies new pull request review +func PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { for _, notifier := range notifiers { - notifier.NotifyPullRequestReview(ctx, pr, review, comment, mentions) + notifier.PullRequestReview(ctx, pr, review, comment, mentions) } } -// NotifyPullRequestCodeComment notifies new pull request code comment -func NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { //nolint +// PullRequestCodeComment notifies new pull request code comment +func PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { for _, notifier := range notifiers { - notifier.NotifyPullRequestCodeComment(ctx, pr, comment, mentions) + notifier.PullRequestCodeComment(ctx, pr, comment, mentions) } } -// NotifyPullRequestChangeTargetBranch notifies when a pull request's target branch was changed -func NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) { //nolint +// PullRequestChangeTargetBranch notifies when a pull request's target branch was changed +func PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) { for _, notifier := range notifiers { - notifier.NotifyPullRequestChangeTargetBranch(ctx, doer, pr, oldBranch) + notifier.PullRequestChangeTargetBranch(ctx, doer, pr, oldBranch) } } -// NotifyPullRequestPushCommits notifies when push commits to pull request's head branch -func NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { //nolint +// PullRequestPushCommits notifies when push commits to pull request's head branch +func PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { for _, notifier := range notifiers { - notifier.NotifyPullRequestPushCommits(ctx, doer, pr, comment) + notifier.PullRequestPushCommits(ctx, doer, pr, comment) } } -// NotifyPullReviewDismiss notifies when a review was dismissed by repo admin -func NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { //nolint +// PullReviewDismiss notifies when a review was dismissed by repo admin +func PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { for _, notifier := range notifiers { - notifier.NotifyPullReviewDismiss(ctx, doer, review, comment) + notifier.PullReviewDismiss(ctx, doer, review, comment) } } -// NotifyUpdateComment notifies update comment to notifiers -func NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { //nolint +// UpdateComment notifies update comment to notifiers +func UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { for _, notifier := range notifiers { - notifier.NotifyUpdateComment(ctx, doer, c, oldContent) + notifier.UpdateComment(ctx, doer, c, oldContent) } } -// NotifyDeleteComment notifies delete comment to notifiers -func NotifyDeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) { //nolint +// DeleteComment notifies delete comment to notifiers +func DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) { for _, notifier := range notifiers { - notifier.NotifyDeleteComment(ctx, doer, c) + notifier.DeleteComment(ctx, doer, c) } } -// NotifyNewRelease notifies new release to notifiers -func NotifyNewRelease(ctx context.Context, rel *repo_model.Release) { //nolint +// NewRelease notifies new release to notifiers +func NewRelease(ctx context.Context, rel *repo_model.Release) { for _, notifier := range notifiers { - notifier.NotifyNewRelease(ctx, rel) + notifier.NewRelease(ctx, rel) } } -// NotifyUpdateRelease notifies update release to notifiers -func NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { //nolint +// UpdateRelease notifies update release to notifiers +func UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { for _, notifier := range notifiers { - notifier.NotifyUpdateRelease(ctx, doer, rel) + notifier.UpdateRelease(ctx, doer, rel) } } -// NotifyDeleteRelease notifies delete release to notifiers -func NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { //nolint +// DeleteRelease notifies delete release to notifiers +func DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { for _, notifier := range notifiers { - notifier.NotifyDeleteRelease(ctx, doer, rel) + notifier.DeleteRelease(ctx, doer, rel) } } -// NotifyIssueChangeMilestone notifies change milestone to notifiers -func NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) { //nolint +// IssueChangeMilestone notifies change milestone to notifiers +func IssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) { for _, notifier := range notifiers { - notifier.NotifyIssueChangeMilestone(ctx, doer, issue, oldMilestoneID) + notifier.IssueChangeMilestone(ctx, doer, issue, oldMilestoneID) } } -// NotifyIssueChangeContent notifies change content to notifiers -func NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { //nolint +// IssueChangeContent notifies change content to notifiers +func IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { for _, notifier := range notifiers { - notifier.NotifyIssueChangeContent(ctx, doer, issue, oldContent) + notifier.IssueChangeContent(ctx, doer, issue, oldContent) } } -// NotifyIssueChangeAssignee notifies change content to notifiers -func NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { //nolint +// IssueChangeAssignee notifies change content to notifiers +func IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { for _, notifier := range notifiers { - notifier.NotifyIssueChangeAssignee(ctx, doer, issue, assignee, removed, comment) + notifier.IssueChangeAssignee(ctx, doer, issue, assignee, removed, comment) } } -// NotifyPullReviewRequest notifies Request Review change -func NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { //nolint +// PullReviewRequest notifies Request Review change +func PullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { for _, notifier := range notifiers { - notifier.NotifyPullReviewRequest(ctx, doer, issue, reviewer, isRequest, comment) + notifier.PullReviewRequest(ctx, doer, issue, reviewer, isRequest, comment) } } -// NotifyIssueClearLabels notifies clear labels to notifiers -func NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { //nolint +// IssueClearLabels notifies clear labels to notifiers +func IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { for _, notifier := range notifiers { - notifier.NotifyIssueClearLabels(ctx, doer, issue) + notifier.IssueClearLabels(ctx, doer, issue) } } -// NotifyIssueChangeTitle notifies change title to notifiers -func NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { //nolint +// IssueChangeTitle notifies change title to notifiers +func IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { for _, notifier := range notifiers { - notifier.NotifyIssueChangeTitle(ctx, doer, issue, oldTitle) + notifier.IssueChangeTitle(ctx, doer, issue, oldTitle) } } -// NotifyIssueChangeRef notifies change reference to notifiers -func NotifyIssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) { //nolint +// IssueChangeRef notifies change reference to notifiers +func IssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) { for _, notifier := range notifiers { - notifier.NotifyIssueChangeRef(ctx, doer, issue, oldRef) + notifier.IssueChangeRef(ctx, doer, issue, oldRef) } } -// NotifyIssueChangeLabels notifies change labels to notifiers -func NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, //nolint +// IssueChangeLabels notifies change labels to notifiers +func IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, addedLabels, removedLabels []*issues_model.Label, ) { for _, notifier := range notifiers { - notifier.NotifyIssueChangeLabels(ctx, doer, issue, addedLabels, removedLabels) + notifier.IssueChangeLabels(ctx, doer, issue, addedLabels, removedLabels) } } -// NotifyCreateRepository notifies create repository to notifiers -func NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { //nolint +// CreateRepository notifies create repository to notifiers +func CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { for _, notifier := range notifiers { - notifier.NotifyCreateRepository(ctx, doer, u, repo) + notifier.CreateRepository(ctx, doer, u, repo) } } -// NotifyMigrateRepository notifies create repository to notifiers -func NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { //nolint +// MigrateRepository notifies create repository to notifiers +func MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { for _, notifier := range notifiers { - notifier.NotifyMigrateRepository(ctx, doer, u, repo) + notifier.MigrateRepository(ctx, doer, u, repo) } } -// NotifyTransferRepository notifies create repository to notifiers -func NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, newOwnerName string) { //nolint +// TransferRepository notifies create repository to notifiers +func TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, newOwnerName string) { for _, notifier := range notifiers { - notifier.NotifyTransferRepository(ctx, doer, repo, newOwnerName) + notifier.TransferRepository(ctx, doer, repo, newOwnerName) } } -// NotifyDeleteRepository notifies delete repository to notifiers -func NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { //nolint +// DeleteRepository notifies delete repository to notifiers +func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { for _, notifier := range notifiers { - notifier.NotifyDeleteRepository(ctx, doer, repo) + notifier.DeleteRepository(ctx, doer, repo) } } -// NotifyForkRepository notifies fork repository to notifiers -func NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { //nolint +// ForkRepository notifies fork repository to notifiers +func ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { for _, notifier := range notifiers { - notifier.NotifyForkRepository(ctx, doer, oldRepo, repo) + notifier.ForkRepository(ctx, doer, oldRepo, repo) } } -// NotifyRenameRepository notifies repository renamed -func NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldName string) { //nolint +// RenameRepository notifies repository renamed +func RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldName string) { for _, notifier := range notifiers { - notifier.NotifyRenameRepository(ctx, doer, repo, oldName) + notifier.RenameRepository(ctx, doer, repo, oldName) } } -// NotifyPushCommits notifies commits pushed to notifiers -func NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { //nolint +// PushCommits notifies commits pushed to notifiers +func PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { for _, notifier := range notifiers { - notifier.NotifyPushCommits(ctx, pusher, repo, opts, commits) + notifier.PushCommits(ctx, pusher, repo, opts, commits) } } -// NotifyCreateRef notifies branch or tag creation to notifiers -func NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { //nolint +// CreateRef notifies branch or tag creation to notifiers +func CreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { for _, notifier := range notifiers { - notifier.NotifyCreateRef(ctx, pusher, repo, refType, refFullName, refID) + notifier.CreateRef(ctx, pusher, repo, refType, refFullName, refID) } } -// NotifyDeleteRef notifies branch or tag deletion to notifiers -func NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { //nolint +// DeleteRef notifies branch or tag deletion to notifiers +func DeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { for _, notifier := range notifiers { - notifier.NotifyDeleteRef(ctx, pusher, repo, refType, refFullName) + notifier.DeleteRef(ctx, pusher, repo, refType, refFullName) } } -// NotifySyncPushCommits notifies commits pushed to notifiers -func NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { //nolint +// SyncPushCommits notifies commits pushed to notifiers +func SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { for _, notifier := range notifiers { - notifier.NotifySyncPushCommits(ctx, pusher, repo, opts, commits) + notifier.SyncPushCommits(ctx, pusher, repo, opts, commits) } } -// NotifySyncCreateRef notifies branch or tag creation to notifiers -func NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { //nolint +// SyncCreateRef notifies branch or tag creation to notifiers +func SyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { for _, notifier := range notifiers { - notifier.NotifySyncCreateRef(ctx, pusher, repo, refType, refFullName, refID) + notifier.SyncCreateRef(ctx, pusher, repo, refType, refFullName, refID) } } -// NotifySyncDeleteRef notifies branch or tag deletion to notifiers -func NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { //nolint +// SyncDeleteRef notifies branch or tag deletion to notifiers +func SyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { for _, notifier := range notifiers { - notifier.NotifySyncDeleteRef(ctx, pusher, repo, refType, refFullName) + notifier.SyncDeleteRef(ctx, pusher, repo, refType, refFullName) } } -// NotifyRepoPendingTransfer notifies creation of pending transfer to notifiers -func NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { //nolint +// RepoPendingTransfer notifies creation of pending transfer to notifiers +func RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { for _, notifier := range notifiers { - notifier.NotifyRepoPendingTransfer(ctx, doer, newOwner, repo) + notifier.RepoPendingTransfer(ctx, doer, newOwner, repo) } } -// NotifyPackageCreate notifies creation of a package to notifiers -func NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { //nolint +// PackageCreate notifies creation of a package to notifiers +func PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { for _, notifier := range notifiers { - notifier.NotifyPackageCreate(ctx, doer, pd) + notifier.PackageCreate(ctx, doer, pd) } } -// NotifyPackageDelete notifies deletion of a package to notifiers -func NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { //nolint +// PackageDelete notifies deletion of a package to notifiers +func PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { for _, notifier := range notifiers { - notifier.NotifyPackageDelete(ctx, doer, pd) + notifier.PackageDelete(ctx, doer, pd) } } diff --git a/services/notify/null.go b/services/notify/null.go index ac8db08e72171..2453faf36120f 100644 --- a/services/notify/null.go +++ b/services/notify/null.go @@ -22,180 +22,180 @@ var _ Notifier = &NullNotifier{} func (*NullNotifier) Run() { } -// NotifyCreateIssueComment places a place holder function -func (*NullNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, +// CreateIssueComment places a place holder function +func (*NullNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User) { } -// NotifyNewIssue places a place holder function -func (*NullNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { +// NewIssue places a place holder function +func (*NullNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { } -// NotifyIssueChangeStatus places a place holder function -func (*NullNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { +// IssueChangeStatus places a place holder function +func (*NullNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { } -// NotifyDeleteIssue notify when some issue deleted -func (*NullNotifier) NotifyDeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { +// DeleteIssue notify when some issue deleted +func (*NullNotifier) DeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { } -// NotifyNewPullRequest places a place holder function -func (*NullNotifier) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { +// NewPullRequest places a place holder function +func (*NullNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { } -// NotifyPullRequestReview places a place holder function -func (*NullNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { +// PullRequestReview places a place holder function +func (*NullNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { } -// NotifyPullRequestCodeComment places a place holder function -func (*NullNotifier) NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { +// PullRequestCodeComment places a place holder function +func (*NullNotifier) PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { } -// NotifyMergePullRequest places a place holder function -func (*NullNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +// MergePullRequest places a place holder function +func (*NullNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { } -// NotifyAutoMergePullRequest places a place holder function -func (*NullNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +// AutoMergePullRequest places a place holder function +func (*NullNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { } -// NotifyPullRequestSynchronized places a place holder function -func (*NullNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +// PullRequestSynchronized places a place holder function +func (*NullNotifier) PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { } -// NotifyPullRequestChangeTargetBranch places a place holder function -func (*NullNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) { +// PullRequestChangeTargetBranch places a place holder function +func (*NullNotifier) PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) { } -// NotifyPullRequestPushCommits notifies when push commits to pull request's head branch -func (*NullNotifier) NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { +// PullRequestPushCommits notifies when push commits to pull request's head branch +func (*NullNotifier) PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { } -// NotifyPullReviewDismiss notifies when a review was dismissed by repo admin -func (*NullNotifier) NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { +// PullReviewDismiss notifies when a review was dismissed by repo admin +func (*NullNotifier) PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { } -// NotifyUpdateComment places a place holder function -func (*NullNotifier) NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { +// UpdateComment places a place holder function +func (*NullNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { } -// NotifyDeleteComment places a place holder function -func (*NullNotifier) NotifyDeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) { +// DeleteComment places a place holder function +func (*NullNotifier) DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) { } -// NotifyNewWikiPage places a place holder function -func (*NullNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { +// NewWikiPage places a place holder function +func (*NullNotifier) NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { } -// NotifyEditWikiPage places a place holder function -func (*NullNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { +// EditWikiPage places a place holder function +func (*NullNotifier) EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { } -// NotifyDeleteWikiPage places a place holder function -func (*NullNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { +// DeleteWikiPage places a place holder function +func (*NullNotifier) DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { } -// NotifyNewRelease places a place holder function -func (*NullNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) { +// NewRelease places a place holder function +func (*NullNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) { } -// NotifyUpdateRelease places a place holder function -func (*NullNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { +// UpdateRelease places a place holder function +func (*NullNotifier) UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { } -// NotifyDeleteRelease places a place holder function -func (*NullNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { +// DeleteRelease places a place holder function +func (*NullNotifier) DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { } -// NotifyIssueChangeMilestone places a place holder function -func (*NullNotifier) NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) { +// IssueChangeMilestone places a place holder function +func (*NullNotifier) IssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) { } -// NotifyIssueChangeContent places a place holder function -func (*NullNotifier) NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { +// IssueChangeContent places a place holder function +func (*NullNotifier) IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { } -// NotifyIssueChangeAssignee places a place holder function -func (*NullNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { +// IssueChangeAssignee places a place holder function +func (*NullNotifier) IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { } -// NotifyPullReviewRequest places a place holder function -func (*NullNotifier) NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { +// PullReviewRequest places a place holder function +func (*NullNotifier) PullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { } -// NotifyIssueClearLabels places a place holder function -func (*NullNotifier) NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { +// IssueClearLabels places a place holder function +func (*NullNotifier) IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { } -// NotifyIssueChangeTitle places a place holder function -func (*NullNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { +// IssueChangeTitle places a place holder function +func (*NullNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { } -// NotifyIssueChangeRef places a place holder function -func (*NullNotifier) NotifyIssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { +// IssueChangeRef places a place holder function +func (*NullNotifier) IssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { } -// NotifyIssueChangeLabels places a place holder function -func (*NullNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, +// IssueChangeLabels places a place holder function +func (*NullNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, addedLabels, removedLabels []*issues_model.Label) { } -// NotifyCreateRepository places a place holder function -func (*NullNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { +// CreateRepository places a place holder function +func (*NullNotifier) CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { } -// NotifyDeleteRepository places a place holder function -func (*NullNotifier) NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { +// DeleteRepository places a place holder function +func (*NullNotifier) DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { } -// NotifyForkRepository places a place holder function -func (*NullNotifier) NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { +// ForkRepository places a place holder function +func (*NullNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { } -// NotifyMigrateRepository places a place holder function -func (*NullNotifier) NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { +// MigrateRepository places a place holder function +func (*NullNotifier) MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { } -// NotifyPushCommits notifies commits pushed to notifiers -func (*NullNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +// PushCommits notifies commits pushed to notifiers +func (*NullNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { } -// NotifyCreateRef notifies branch or tag creation to notifiers -func (*NullNotifier) NotifyCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { +// CreateRef notifies branch or tag creation to notifiers +func (*NullNotifier) CreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { } -// NotifyDeleteRef notifies branch or tag deletion to notifiers -func (*NullNotifier) NotifyDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { +// DeleteRef notifies branch or tag deletion to notifiers +func (*NullNotifier) DeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { } -// NotifyRenameRepository places a place holder function -func (*NullNotifier) NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) { +// RenameRepository places a place holder function +func (*NullNotifier) RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) { } -// NotifyTransferRepository places a place holder function -func (*NullNotifier) NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) { +// TransferRepository places a place holder function +func (*NullNotifier) TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) { } -// NotifySyncPushCommits places a place holder function -func (*NullNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +// SyncPushCommits places a place holder function +func (*NullNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { } -// NotifySyncCreateRef places a place holder function -func (*NullNotifier) NotifySyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { +// SyncCreateRef places a place holder function +func (*NullNotifier) SyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { } -// NotifySyncDeleteRef places a place holder function -func (*NullNotifier) NotifySyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { +// SyncDeleteRef places a place holder function +func (*NullNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { } -// NotifyRepoPendingTransfer places a place holder function -func (*NullNotifier) NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { +// RepoPendingTransfer places a place holder function +func (*NullNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { } -// NotifyPackageCreate places a place holder function -func (*NullNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { +// PackageCreate places a place holder function +func (*NullNotifier) PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { } -// NotifyPackageDelete places a place holder function -func (*NullNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { +// PackageDelete places a place holder function +func (*NullNotifier) PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { } diff --git a/services/packages/packages.go b/services/packages/packages.go index c85fd29cd6f21..aa18d24177d6a 100644 --- a/services/packages/packages.go +++ b/services/packages/packages.go @@ -113,7 +113,7 @@ func createPackageAndAddFile(pvci *PackageCreationInfo, pfci *PackageFileCreatio return nil, nil, err } - notify.NotifyPackageCreate(db.DefaultContext, pvci.Creator, pd) + notify.PackageCreate(db.DefaultContext, pvci.Creator, pd) } return pv, pf, nil @@ -409,7 +409,7 @@ func RemovePackageVersion(doer *user_model.User, pv *packages_model.PackageVersi return err } - notify.NotifyPackageDelete(db.DefaultContext, doer, pd) + notify.PackageDelete(db.DefaultContext, doer, pd) return nil } diff --git a/services/pull/check.go b/services/pull/check.go index d1b6bc16aa36f..29de6a4174242 100644 --- a/services/pull/check.go +++ b/services/pull/check.go @@ -277,7 +277,7 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool { return false } - notify.NotifyMergePullRequest(ctx, merger, pr) + notify.MergePullRequest(ctx, merger, pr) log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commit.ID.String()) return true diff --git a/services/pull/merge.go b/services/pull/merge.go index c99a049439f68..9163de3cd678a 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -201,9 +201,9 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U } if wasAutoMerged { - notify.NotifyAutoMergePullRequest(hammerCtx, doer, pr) + notify.AutoMergePullRequest(hammerCtx, doer, pr) } else { - notify.NotifyMergePullRequest(hammerCtx, doer, pr) + notify.MergePullRequest(hammerCtx, doer, pr) } // Reset cached commit count @@ -885,7 +885,7 @@ func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGit return err } - notify.NotifyMergePullRequest(baseGitRepo.Ctx, doer, pr) + notify.MergePullRequest(baseGitRepo.Ctx, doer, pr) log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commitID) return nil } diff --git a/services/pull/pull.go b/services/pull/pull.go index 50898cd37f8de..fc5a262d0df67 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -81,12 +81,12 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *issu return err } - notify.NotifyNewPullRequest(prCtx, pr, mentions) + notify.NewPullRequest(prCtx, pr, mentions) if len(pull.Labels) > 0 { - notify.NotifyIssueChangeLabels(prCtx, pull.Poster, pull, pull.Labels, nil) + notify.IssueChangeLabels(prCtx, pull.Poster, pull, pull.Labels, nil) } if pull.Milestone != nil { - notify.NotifyIssueChangeMilestone(prCtx, pull.Poster, pull, 0) + notify.IssueChangeMilestone(prCtx, pull.Poster, pull, 0) } // add first push codes comment @@ -300,7 +300,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, } pr.Issue.PullRequest = pr - notify.NotifyPullRequestSynchronized(ctx, doer, pr) + notify.PullRequestSynchronized(ctx, doer, pr) } } } @@ -319,7 +319,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, AddToTaskQueue(pr) comment, err := CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID) if err == nil && comment != nil { - notify.NotifyPullRequestPushCommits(ctx, doer, pr, comment) + notify.PullRequestPushCommits(ctx, doer, pr, comment) } } diff --git a/services/pull/review.go b/services/pull/review.go index 2591f0e8c2810..595475a489319 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -67,7 +67,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git. return nil, err } - notify.NotifyCreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions) + notify.CreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions) return comment, nil } @@ -254,7 +254,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos return nil, nil, err } - notify.NotifyPullRequestReview(ctx, pr, review, comm, mentions) + notify.PullRequestReview(ctx, pr, review, comm, mentions) for _, lines := range review.CodeComments { for _, comments := range lines { @@ -263,7 +263,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos if err != nil { return nil, nil, err } - notify.NotifyPullRequestCodeComment(ctx, pr, codeComment, mentions) + notify.PullRequestCodeComment(ctx, pr, codeComment, mentions) } } } @@ -339,7 +339,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string, comment.Poster = doer comment.Issue = review.Issue - notify.NotifyPullReviewDismiss(ctx, doer, review, comment) + notify.PullReviewDismiss(ctx, doer, review, comment) return comment, err } diff --git a/services/release/release.go b/services/release/release.go index 3affcf751c64b..4a4748dc4dc56 100644 --- a/services/release/release.go +++ b/services/release/release.go @@ -80,14 +80,14 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel commits.HeadCommit = repository.CommitToPushCommit(commit) commits.CompareURL = rel.Repo.ComposeCompareURL(git.EmptySHA, commit.ID.String()) - notify.NotifyPushCommits( + notify.PushCommits( ctx, rel.Publisher, rel.Repo, &repository.PushUpdateOptions{ RefFullName: git.TagPrefix + rel.TagName, OldCommitID: git.EmptySHA, NewCommitID: commit.ID.String(), }, commits) - notify.NotifyCreateRef(ctx, rel.Publisher, rel.Repo, "tag", git.TagPrefix+rel.TagName, commit.ID.String()) + notify.CreateRef(ctx, rel.Publisher, rel.Repo, "tag", git.TagPrefix+rel.TagName, commit.ID.String()) rel.CreatedUnix = timeutil.TimeStampNow() } commit, err := gitRepo.GetTagCommit(rel.TagName) @@ -138,7 +138,7 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU } if !rel.IsDraft { - notify.NotifyNewRelease(gitRepo.Ctx, rel) + notify.NewRelease(gitRepo.Ctx, rel) } return nil @@ -278,12 +278,12 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod } if !isCreated { - notify.NotifyUpdateRelease(gitRepo.Ctx, doer, rel) + notify.UpdateRelease(gitRepo.Ctx, doer, rel) return } if !rel.IsDraft { - notify.NotifyNewRelease(gitRepo.Ctx, rel) + notify.NewRelease(gitRepo.Ctx, rel) } return err @@ -323,14 +323,14 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del return fmt.Errorf("git tag -d: %w", err) } - notify.NotifyPushCommits( + notify.PushCommits( ctx, doer, repo, &repository.PushUpdateOptions{ RefFullName: git.TagPrefix + rel.TagName, OldCommitID: rel.Sha1, NewCommitID: git.EmptySHA, }, repository.NewPushCommits()) - notify.NotifyDeleteRef(ctx, doer, repo, "tag", git.TagPrefix+rel.TagName) + notify.DeleteRef(ctx, doer, repo, "tag", git.TagPrefix+rel.TagName) if err := repo_model.DeleteReleaseByID(ctx, id); err != nil { return fmt.Errorf("DeleteReleaseByID: %w", err) @@ -359,7 +359,7 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del } } - notify.NotifyDeleteRelease(ctx, doer, rel) + notify.DeleteRelease(ctx, doer, rel) return nil } diff --git a/services/repository/adopt.go b/services/repository/adopt.go index 0473e97b85202..f0cb9632a24cf 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -95,7 +95,7 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption return nil, err } - notify.NotifyCreateRepository(db.DefaultContext, doer, u, repo) + notify.CreateRepository(db.DefaultContext, doer, u, repo) return repo, nil } diff --git a/services/repository/branch.go b/services/repository/branch.go index 4946e32701bcb..160d6907ee1c5 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -141,8 +141,8 @@ func RenameBranch(repo *repo_model.Repository, doer *user_model.User, gitRepo *g return "", err } - notify.NotifyDeleteRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+from) - notify.NotifyCreateRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+to, refID) + notify.DeleteRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+from) + notify.CreateRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+to, refID) return "", nil } diff --git a/services/repository/fork.go b/services/repository/fork.go index 4c957e61341dd..b744497d0222f 100644 --- a/services/repository/fork.go +++ b/services/repository/fork.go @@ -183,7 +183,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork } } - notify.NotifyForkRepository(ctx, doer, opts.BaseRepo, repo) + notify.ForkRepository(ctx, doer, opts.BaseRepo, repo) return repo, nil } diff --git a/services/repository/push.go b/services/repository/push.go index c32ee845bce94..ba95c4f1b86c2 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -115,7 +115,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } tagName := opts.TagName() if opts.IsDelRef() { - notify.NotifyPushCommits( + notify.PushCommits( db.DefaultContext, pusher, repo, &repo_module.PushUpdateOptions{ RefFullName: git.TagPrefix + tagName, @@ -124,7 +124,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { }, repo_module.NewPushCommits()) delTags = append(delTags, tagName) - notify.NotifyDeleteRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName) + notify.DeleteRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName) } else { // is new tag newCommit, err := gitRepo.GetCommit(opts.NewCommitID) if err != nil { @@ -135,7 +135,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { commits.HeadCommit = repo_module.CommitToPushCommit(newCommit) commits.CompareURL = repo.ComposeCompareURL(git.EmptySHA, opts.NewCommitID) - notify.NotifyPushCommits( + notify.PushCommits( db.DefaultContext, pusher, repo, &repo_module.PushUpdateOptions{ RefFullName: git.TagPrefix + tagName, @@ -144,7 +144,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { }, commits) addTags = append(addTags, tagName) - notify.NotifyCreateRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName, opts.NewCommitID) + notify.CreateRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName, opts.NewCommitID) } } else if opts.IsBranch() { // If is branch reference if pusher == nil || pusher.ID != opts.PusherID { @@ -189,7 +189,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { if err != nil { return fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err) } - notify.NotifyCreateRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName, opts.NewCommitID) + notify.CreateRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName, opts.NewCommitID) } else { l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID) if err != nil { @@ -249,7 +249,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { commits.Commits = commits.Commits[:setting.UI.FeedMaxCommitNum] } - notify.NotifyPushCommits(db.DefaultContext, pusher, repo, opts, commits) + notify.PushCommits(db.DefaultContext, pusher, repo, opts, commits) if err = git_model.RemoveDeletedBranchByName(repo.ID, branch); err != nil { log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, branch, err) @@ -260,7 +260,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { log.Error("repo_module.CacheRef %s/%s failed: %v", repo.ID, branch, err) } } else { - notify.NotifyDeleteRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName) + notify.DeleteRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName) if err = pull_service.CloseBranchPulls(pusher, repo.ID, branch); err != nil { // close all related pulls log.Error("close related pull request failed: %v", err) diff --git a/services/repository/repository.go b/services/repository/repository.go index 03db0b50c0931..aa3ffb99c002a 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -19,7 +19,7 @@ import ( "code.gitea.io/gitea/modules/log" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" - notify_service "code.gitea.io/gitea/services/notify" + "code.gitea.io/gitea/services/notify" pull_service "code.gitea.io/gitea/services/pull" ) @@ -31,20 +31,20 @@ func CreateRepository(doer, owner *user_model.User, opts repo_module.CreateRepoO return nil, err } - notify_service.NotifyCreateRepository(db.DefaultContext, doer, owner, repo) + notify.CreateRepository(db.DefaultContext, doer, owner, repo) return repo, nil } // DeleteRepository deletes a repository for a user or organization. -func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, notify bool) error { +func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, triggerNotify bool) error { if err := pull_service.CloseRepoBranchesPulls(ctx, doer, repo); err != nil { log.Error("CloseRepoBranchesPulls failed: %v", err) } - if notify { + if triggerNotify { // If the repo itself has webhooks, we need to trigger them before deleting it... - notify_service.NotifyDeleteRepository(ctx, doer, repo) + notify.DeleteRepository(ctx, doer, repo) } if err := models.DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil { diff --git a/services/repository/template.go b/services/repository/template.go index f429467d9f65a..17f2c27676bbf 100644 --- a/services/repository/template.go +++ b/services/repository/template.go @@ -100,7 +100,7 @@ func GenerateRepository(doer, owner *user_model.User, templateRepo *repo_model.R return nil, err } - notify.NotifyCreateRepository(db.DefaultContext, doer, owner, generateRepo) + notify.CreateRepository(db.DefaultContext, doer, owner, generateRepo) return generateRepo, nil } diff --git a/services/repository/transfer.go b/services/repository/transfer.go index 65690e3f0a84f..6d665da98b6ac 100644 --- a/services/repository/transfer.go +++ b/services/repository/transfer.go @@ -55,7 +55,7 @@ func TransferOwnership(ctx context.Context, doer, newOwner *user_model.User, rep } } - notify.NotifyTransferRepository(ctx, doer, repo, oldOwner.Name) + notify.TransferRepository(ctx, doer, repo, oldOwner.Name) return nil } @@ -78,7 +78,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *repo_model.Repository, ne repoWorkingPool.CheckOut(fmt.Sprint(repo.ID)) repo.Name = newRepoName - notify.NotifyRenameRepository(db.DefaultContext, doer, repo, oldRepoName) + notify.RenameRepository(db.DefaultContext, doer, repo, oldRepoName) return nil } @@ -127,7 +127,7 @@ func StartRepositoryTransfer(ctx context.Context, doer, newOwner *user_model.Use } // notify users who are able to accept / reject transfer - notify.NotifyRepoPendingTransfer(ctx, doer, newOwner, repo) + notify.RepoPendingTransfer(ctx, doer, newOwner, repo) return nil } diff --git a/services/task/migrate.go b/services/task/migrate.go index b48e30a165cc9..97f54d32f0354 100644 --- a/services/task/migrate.go +++ b/services/task/migrate.go @@ -50,7 +50,7 @@ func runMigrateTask(t *admin_model.Task) (err error) { if err == nil { err = admin_model.FinishMigrateTask(t) if err == nil { - notify.NotifyMigrateRepository(db.DefaultContext, t.Doer, t.Owner, t.Repo) + notify.MigrateRepository(db.DefaultContext, t.Doer, t.Owner, t.Repo) return } diff --git a/services/notification/notifier.go b/services/uinotification/notifier.go similarity index 98% rename from services/notification/notifier.go rename to services/uinotification/notifier.go index cb9c80719319b..3e6a376c8b88d 100644 --- a/services/notification/notifier.go +++ b/services/uinotification/notifier.go @@ -1,7 +1,7 @@ // Copyright 2018 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package notification +package uinotification import ( "context" @@ -41,8 +41,10 @@ func NewNotifier() notify.Notifier { return ns } -func init() { +// Init initializes notification service, we need to create queue so don't run RegisterNotifier in init +func Init() error { notify.RegisterNotifier(NewNotifier()) + return nil } func (ns *notificationService) handle(data ...queue.Data) []queue.Data { From d76c7357bdcba12a6f1940077e0dd4caad7e0cc3 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 2 Jan 2023 19:17:04 +0800 Subject: [PATCH 07/12] Fix bugs --- routers/init.go | 2 +- services/feed/action.go | 50 +++++++++--------- services/feed/action_test.go | 5 +- services/feed/main_test.go | 2 +- services/indexer/notifier.go | 24 ++++----- services/mailer/notifier.go | 32 ++++++------ services/mirror/notifier.go | 4 +- services/uinotification/notifier.go | 33 ++++++------ services/webhook/notifier.go | 78 ++++++++++++++--------------- 9 files changed, 115 insertions(+), 115 deletions(-) diff --git a/routers/init.go b/routers/init.go index c628ed38d655a..939d11e686398 100644 --- a/routers/init.go +++ b/routers/init.go @@ -129,7 +129,7 @@ func GlobalInitInstalled(ctx context.Context) { mailer.NewContext(ctx) mustInit(cache.NewContext) - mustInit(uinotification.Init) + uinotification.Init() mustInit(archiver.Init) highlight.NewContext() diff --git a/services/feed/action.go b/services/feed/action.go index f317137079b50..488ff743e02f4 100644 --- a/services/feed/action.go +++ b/services/feed/action.go @@ -35,7 +35,7 @@ func init() { notify.RegisterNotifier(NewNotifier()) } -func (a *actionNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { +func (a *actionNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { if err := issue.LoadPoster(ctx); err != nil { log.Error("issue.LoadPoster: %v", err) return @@ -59,8 +59,8 @@ func (a *actionNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model } } -// NotifyIssueChangeStatus notifies close or reopen issue to notifiers -func (a *actionNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) { +// IssueChangeStatus notifies close or reopen issue to notifiers +func (a *actionNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) { // Compose comment action, could be plain comment, close or reopen issue/pull request. // This object will be used to notify watchers in the end of function. act := &activities_model.Action{ @@ -86,14 +86,14 @@ func (a *actionNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user } } - // Notify watchers for whatever action comes in, ignore if no action type. + // watchers for whatever action comes in, ignore if no action type. if err := activities_model.NotifyWatchers(ctx, act); err != nil { log.Error("NotifyWatchers: %v", err) } } -// NotifyCreateIssueComment notifies comment on an issue to notifiers -func (a *actionNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, +// CreateIssueComment notifies comment on an issue to notifiers +func (a *actionNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, ) { act := &activities_model.Action{ @@ -122,13 +122,13 @@ func (a *actionNotifier) NotifyCreateIssueComment(ctx context.Context, doer *use act.OpType = activities_model.ActionCommentIssue } - // Notify watchers for whatever action comes in, ignore if no action type. + // watchers for whatever action comes in, ignore if no action type. if err := activities_model.NotifyWatchers(ctx, act); err != nil { log.Error("NotifyWatchers: %v", err) } } -func (a *actionNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_model.PullRequest, mentions []*user_model.User) { +func (a *actionNotifier) NewPullRequest(ctx context.Context, pull *issues_model.PullRequest, mentions []*user_model.User) { if err := pull.LoadIssue(ctx); err != nil { log.Error("pull.LoadIssue: %v", err) return @@ -155,7 +155,7 @@ func (a *actionNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_ } } -func (a *actionNotifier) NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) { +func (a *actionNotifier) RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) { if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ ActUserID: doer.ID, ActUser: doer, @@ -169,7 +169,7 @@ func (a *actionNotifier) NotifyRenameRepository(ctx context.Context, doer *user_ } } -func (a *actionNotifier) NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) { +func (a *actionNotifier) TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) { if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ ActUserID: doer.ID, ActUser: doer, @@ -183,7 +183,7 @@ func (a *actionNotifier) NotifyTransferRepository(ctx context.Context, doer *use } } -func (a *actionNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { +func (a *actionNotifier) CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ ActUserID: doer.ID, ActUser: doer, @@ -196,7 +196,7 @@ func (a *actionNotifier) NotifyCreateRepository(ctx context.Context, doer, u *us } } -func (a *actionNotifier) NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { +func (a *actionNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ ActUserID: doer.ID, ActUser: doer, @@ -209,7 +209,7 @@ func (a *actionNotifier) NotifyForkRepository(ctx context.Context, doer *user_mo } } -func (a *actionNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { +func (a *actionNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { if err := review.LoadReviewer(ctx); err != nil { log.Error("LoadReviewer '%d/%d': %v", review.ID, review.ReviewerID, err) return @@ -267,7 +267,7 @@ func (a *actionNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues } } -func (*actionNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +func (*actionNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ ActUserID: doer.ID, ActUser: doer, @@ -281,7 +281,7 @@ func (*actionNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_mo } } -func (*actionNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +func (*actionNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ ActUserID: doer.ID, ActUser: doer, @@ -295,7 +295,7 @@ func (*actionNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *use } } -func (*actionNotifier) NotifyPullRevieweDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { +func (*actionNotifier) PullRevieweDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { reviewerName := review.Reviewer.Name if len(review.OriginalAuthor) > 0 { reviewerName = review.OriginalAuthor @@ -315,7 +315,7 @@ func (*actionNotifier) NotifyPullRevieweDismiss(ctx context.Context, doer *user_ } } -func (a *actionNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (a *actionNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { data, err := json.Marshal(commits) if err != nil { log.Error("Marshal: %v", err) @@ -348,10 +348,10 @@ func (a *actionNotifier) NotifyPushCommits(ctx context.Context, pusher *user_mod } } -func (a *actionNotifier) NotifyCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { +func (a *actionNotifier) CreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { opType := activities_model.ActionCommitRepo if refType == "tag" { - // has sent same action in `NotifyPushCommits`, so skip it. + // has sent same action in `PushCommits`, so skip it. return } if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ @@ -367,10 +367,10 @@ func (a *actionNotifier) NotifyCreateRef(ctx context.Context, doer *user_model.U } } -func (a *actionNotifier) NotifyDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { +func (a *actionNotifier) DeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { opType := activities_model.ActionDeleteBranch if refType == "tag" { - // has sent same action in `NotifyPushCommits`, so skip it. + // has sent same action in `PushCommits`, so skip it. return } if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ @@ -386,7 +386,7 @@ func (a *actionNotifier) NotifyDeleteRef(ctx context.Context, doer *user_model.U } } -func (a *actionNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (a *actionNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { data, err := json.Marshal(commits) if err != nil { log.Error("json.Marshal: %v", err) @@ -407,7 +407,7 @@ func (a *actionNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user } } -func (a *actionNotifier) NotifySyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { +func (a *actionNotifier) SyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ ActUserID: repo.OwnerID, ActUser: repo.MustOwner(ctx), @@ -421,7 +421,7 @@ func (a *actionNotifier) NotifySyncCreateRef(ctx context.Context, doer *user_mod } } -func (a *actionNotifier) NotifySyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { +func (a *actionNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ ActUserID: repo.OwnerID, ActUser: repo.MustOwner(ctx), @@ -435,7 +435,7 @@ func (a *actionNotifier) NotifySyncDeleteRef(ctx context.Context, doer *user_mod } } -func (a *actionNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) { +func (a *actionNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) { if err := rel.LoadAttributes(ctx); err != nil { log.Error("LoadAttributes: %v", err) return diff --git a/services/feed/action_test.go b/services/feed/action_test.go index de5e90917a514..a5c092bb53716 100644 --- a/services/feed/action_test.go +++ b/services/feed/action_test.go @@ -1,7 +1,7 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package feed +package feed_test import ( "strings" @@ -12,6 +12,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/services/feed" "github.com/stretchr/testify/assert" ) @@ -39,7 +40,7 @@ func TestRenameRepoAction(t *testing.T) { } unittest.AssertNotExistsBean(t, actionBean) - NewNotifier().RenameRepository(db.DefaultContext, user, repo, oldRepoName) + feed.NewNotifier().RenameRepository(db.DefaultContext, user, repo, oldRepoName) unittest.AssertExistsAndLoadBean(t, actionBean) unittest.CheckConsistencyFor(t, &activities_model.Action{}) diff --git a/services/feed/main_test.go b/services/feed/main_test.go index aa2017a89e819..544e3952fbfdf 100644 --- a/services/feed/main_test.go +++ b/services/feed/main_test.go @@ -1,7 +1,7 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package feed +package feed_test import ( "path/filepath" diff --git a/services/indexer/notifier.go b/services/indexer/notifier.go index 43b85b7845af2..534ee9e2231e9 100644 --- a/services/indexer/notifier.go +++ b/services/indexer/notifier.go @@ -34,7 +34,7 @@ func init() { notify.RegisterNotifier(NewNotifier()) } -func (r *indexerNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, +func (r *indexerNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, ) { if comment.Type == issues_model.CommentTypeComment { @@ -51,15 +51,15 @@ func (r *indexerNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us } } -func (r *indexerNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { +func (r *indexerNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { issue_indexer.UpdateIssueIndexer(issue) } -func (r *indexerNotifier) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { +func (r *indexerNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { issue_indexer.UpdateIssueIndexer(pr.Issue) } -func (r *indexerNotifier) NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { +func (r *indexerNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { if c.Type == issues_model.CommentTypeComment { var found bool if c.Issue.Comments != nil { @@ -83,7 +83,7 @@ func (r *indexerNotifier) NotifyUpdateComment(ctx context.Context, doer *user_mo } } -func (r *indexerNotifier) NotifyDeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) { +func (r *indexerNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) { if comment.Type == issues_model.CommentTypeComment { if err := comment.LoadIssue(ctx); err != nil { log.Error("LoadIssue: %v", err) @@ -112,14 +112,14 @@ func (r *indexerNotifier) NotifyDeleteComment(ctx context.Context, doer *user_mo } } -func (r *indexerNotifier) NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { +func (r *indexerNotifier) DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { issue_indexer.DeleteRepoIssueIndexer(ctx, repo) if setting.Indexer.RepoIndexerEnabled { code_indexer.UpdateRepoIndexer(repo) } } -func (r *indexerNotifier) NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { +func (r *indexerNotifier) MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { issue_indexer.UpdateRepoIndexer(ctx, repo) if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty { code_indexer.UpdateRepoIndexer(repo) @@ -129,7 +129,7 @@ func (r *indexerNotifier) NotifyMigrateRepository(ctx context.Context, doer, u * } } -func (r *indexerNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (r *indexerNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { if setting.Indexer.RepoIndexerEnabled && opts.RefFullName == git.BranchPrefix+repo.DefaultBranch { code_indexer.UpdateRepoIndexer(repo) } @@ -138,7 +138,7 @@ func (r *indexerNotifier) NotifyPushCommits(ctx context.Context, pusher *user_mo } } -func (r *indexerNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (r *indexerNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { if setting.Indexer.RepoIndexerEnabled && opts.RefFullName == git.BranchPrefix+repo.DefaultBranch { code_indexer.UpdateRepoIndexer(repo) } @@ -147,14 +147,14 @@ func (r *indexerNotifier) NotifySyncPushCommits(ctx context.Context, pusher *use } } -func (r *indexerNotifier) NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { +func (r *indexerNotifier) IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { issue_indexer.UpdateIssueIndexer(issue) } -func (r *indexerNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { +func (r *indexerNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { issue_indexer.UpdateIssueIndexer(issue) } -func (r *indexerNotifier) NotifyIssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) { +func (r *indexerNotifier) IssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) { issue_indexer.UpdateIssueIndexer(issue) } diff --git a/services/mailer/notifier.go b/services/mailer/notifier.go index 4554a7d70c05a..ea7d605e763bb 100644 --- a/services/mailer/notifier.go +++ b/services/mailer/notifier.go @@ -26,7 +26,7 @@ func NewNotifier() notify.Notifier { return &mailNotifier{} } -func (m *mailNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, +func (m *mailNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, ) { var act activities_model.ActionType @@ -47,13 +47,13 @@ func (m *mailNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_ } } -func (m *mailNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { +func (m *mailNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { if err := MailParticipants(ctx, issue, issue.Poster, activities_model.ActionCreateIssue, mentions); err != nil { log.Error("MailParticipants: %v", err) } } -func (m *mailNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { +func (m *mailNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { var actionType activities_model.ActionType if issue.IsPull { if isClosed { @@ -74,7 +74,7 @@ func (m *mailNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_m } } -func (m *mailNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { +func (m *mailNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { if err := issue.LoadPullRequest(ctx); err != nil { log.Error("issue.LoadPullRequest: %v", err) return @@ -86,13 +86,13 @@ func (m *mailNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_mo } } -func (m *mailNotifier) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { +func (m *mailNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { if err := MailParticipants(ctx, pr.Issue, pr.Issue.Poster, activities_model.ActionCreatePullRequest, mentions); err != nil { log.Error("MailParticipants: %v", err) } } -func (m *mailNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { +func (m *mailNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { var act activities_model.ActionType if comment.Type == issues_model.CommentTypeClose { act = activities_model.ActionCloseIssue @@ -106,13 +106,13 @@ func (m *mailNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_m } } -func (m *mailNotifier) NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { +func (m *mailNotifier) PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { if err := MailMentionsComment(ctx, pr, comment, mentions); err != nil { log.Error("MailMentionsComment: %v", err) } } -func (m *mailNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { +func (m *mailNotifier) IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { // mail only sent to added assignees and not self-assignee if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() != user_model.EmailNotificationsDisabled { ct := fmt.Sprintf("Assigned #%d.", issue.Index) @@ -122,7 +122,7 @@ func (m *mailNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user } } -func (m *mailNotifier) NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { +func (m *mailNotifier) PullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() != user_model.EmailNotificationsDisabled { ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL()) if err := SendIssueAssignedMail(ctx, issue, doer, ct, comment, []*user_model.User{reviewer}); err != nil { @@ -131,7 +131,7 @@ func (m *mailNotifier) NotifyPullReviewRequest(ctx context.Context, doer *user_m } } -func (m *mailNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +func (m *mailNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { if err := pr.LoadIssue(ctx); err != nil { log.Error("LoadIssue: %v", err) return @@ -141,7 +141,7 @@ func (m *mailNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_mo } } -func (m *mailNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +func (m *mailNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { if err := pr.LoadIssue(ctx); err != nil { log.Error("pr.LoadIssue: %v", err) return @@ -151,7 +151,7 @@ func (m *mailNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *use } } -func (m *mailNotifier) NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { +func (m *mailNotifier) PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { var err error if err = comment.LoadIssue(ctx); err != nil { log.Error("comment.LoadIssue: %v", err) @@ -172,16 +172,16 @@ func (m *mailNotifier) NotifyPullRequestPushCommits(ctx context.Context, doer *u if err := comment.LoadPushCommits(ctx); err != nil { log.Error("comment.LoadPushCommits: %v", err) } - m.NotifyCreateIssueComment(ctx, doer, comment.Issue.Repo, comment.Issue, comment, nil) + m.CreateIssueComment(ctx, doer, comment.Issue.Repo, comment.Issue, comment, nil) } -func (m *mailNotifier) NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { +func (m *mailNotifier) PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { if err := MailParticipantsComment(ctx, comment, activities_model.ActionPullReviewDismissed, review.Issue, nil); err != nil { log.Error("MailParticipantsComment: %v", err) } } -func (m *mailNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) { +func (m *mailNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) { if err := rel.LoadAttributes(ctx); err != nil { log.Error("LoadAttributes: %v", err) return @@ -194,7 +194,7 @@ func (m *mailNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Rel MailNewRelease(ctx, rel) } -func (m *mailNotifier) NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { +func (m *mailNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { if err := SendRepoTransferNotifyMail(ctx, doer, newOwner, repo); err != nil { log.Error("SendRepoTransferNotifyMail: %v", err) } diff --git a/services/mirror/notifier.go b/services/mirror/notifier.go index a150f7c2944fa..d410860c976ae 100644 --- a/services/mirror/notifier.go +++ b/services/mirror/notifier.go @@ -29,11 +29,11 @@ func init() { notify.RegisterNotifier(NewNotifier()) } -func (m *mirrorNotifier) NotifyPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) { +func (m *mirrorNotifier) PushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) { syncPushMirrorWithSyncOnCommit(ctx, repo.ID) } -func (m *mirrorNotifier) NotifySyncPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) { +func (m *mirrorNotifier) SyncPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) { syncPushMirrorWithSyncOnCommit(ctx, repo.ID) } diff --git a/services/uinotification/notifier.go b/services/uinotification/notifier.go index 3e6a376c8b88d..8a516ca8c0417 100644 --- a/services/uinotification/notifier.go +++ b/services/uinotification/notifier.go @@ -42,9 +42,8 @@ func NewNotifier() notify.Notifier { } // Init initializes notification service, we need to create queue so don't run RegisterNotifier in init -func Init() error { +func Init() { notify.RegisterNotifier(NewNotifier()) - return nil } func (ns *notificationService) handle(data ...queue.Data) []queue.Data { @@ -61,7 +60,7 @@ func (ns *notificationService) Run() { graceful.GetManager().RunWithShutdownFns(ns.issueQueue.Run) } -func (ns *notificationService) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, +func (ns *notificationService) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, ) { opts := issueNotificationOpts{ @@ -85,7 +84,7 @@ func (ns *notificationService) NotifyCreateIssueComment(ctx context.Context, doe } } -func (ns *notificationService) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { +func (ns *notificationService) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { _ = ns.issueQueue.Push(issueNotificationOpts{ IssueID: issue.ID, NotificationAuthorID: issue.Poster.ID, @@ -99,14 +98,14 @@ func (ns *notificationService) NotifyNewIssue(ctx context.Context, issue *issues } } -func (ns *notificationService) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { +func (ns *notificationService) IssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { _ = ns.issueQueue.Push(issueNotificationOpts{ IssueID: issue.ID, NotificationAuthorID: doer.ID, }) } -func (ns *notificationService) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { +func (ns *notificationService) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { if err := issue.LoadPullRequest(ctx); err != nil { log.Error("issue.LoadPullRequest: %v", err) return @@ -119,18 +118,18 @@ func (ns *notificationService) NotifyIssueChangeTitle(ctx context.Context, doer } } -func (ns *notificationService) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +func (ns *notificationService) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { _ = ns.issueQueue.Push(issueNotificationOpts{ IssueID: pr.Issue.ID, NotificationAuthorID: doer.ID, }) } -func (ns *notificationService) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { - ns.NotifyMergePullRequest(ctx, doer, pr) +func (ns *notificationService) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { + ns.MergePullRequest(ctx, doer, pr) } -func (ns *notificationService) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { +func (ns *notificationService) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { if err := pr.LoadIssue(ctx); err != nil { log.Error("Unable to load issue: %d for pr: %d: Error: %v", pr.IssueID, pr.ID, err) return @@ -165,7 +164,7 @@ func (ns *notificationService) NotifyNewPullRequest(ctx context.Context, pr *iss } } -func (ns *notificationService) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, c *issues_model.Comment, mentions []*user_model.User) { +func (ns *notificationService) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, c *issues_model.Comment, mentions []*user_model.User) { opts := issueNotificationOpts{ IssueID: pr.Issue.ID, NotificationAuthorID: r.Reviewer.ID, @@ -187,7 +186,7 @@ func (ns *notificationService) NotifyPullRequestReview(ctx context.Context, pr * } } -func (ns *notificationService) NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, c *issues_model.Comment, mentions []*user_model.User) { +func (ns *notificationService) PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, c *issues_model.Comment, mentions []*user_model.User) { for _, mention := range mentions { _ = ns.issueQueue.Push(issueNotificationOpts{ IssueID: pr.Issue.ID, @@ -198,7 +197,7 @@ func (ns *notificationService) NotifyPullRequestCodeComment(ctx context.Context, } } -func (ns *notificationService) NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { +func (ns *notificationService) PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { opts := issueNotificationOpts{ IssueID: pr.IssueID, NotificationAuthorID: doer.ID, @@ -207,7 +206,7 @@ func (ns *notificationService) NotifyPullRequestPushCommits(ctx context.Context, _ = ns.issueQueue.Push(opts) } -func (ns *notificationService) NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { +func (ns *notificationService) PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { opts := issueNotificationOpts{ IssueID: review.IssueID, NotificationAuthorID: doer.ID, @@ -216,7 +215,7 @@ func (ns *notificationService) NotifyPullReviewDismiss(ctx context.Context, doer _ = ns.issueQueue.Push(opts) } -func (ns *notificationService) NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { +func (ns *notificationService) IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { if !removed && doer.ID != assignee.ID { opts := issueNotificationOpts{ IssueID: issue.ID, @@ -232,7 +231,7 @@ func (ns *notificationService) NotifyIssueChangeAssignee(ctx context.Context, do } } -func (ns *notificationService) NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { +func (ns *notificationService) PullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { if isRequest { opts := issueNotificationOpts{ IssueID: issue.ID, @@ -248,7 +247,7 @@ func (ns *notificationService) NotifyPullReviewRequest(ctx context.Context, doer } } -func (ns *notificationService) NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { +func (ns *notificationService) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { err := db.AutoTx(ctx, func(ctx context.Context) error { return activities_model.CreateRepoTransferNotification(ctx, doer, newOwner, repo) }) diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 10fcd55bf180d..ff341b30ac001 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -38,7 +38,7 @@ func NewNotifier() notify.Notifier { return &webhookNotifier{} } -func (m *webhookNotifier) NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { +func (m *webhookNotifier) IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { if err := issue.LoadPoster(ctx); err != nil { log.Error("LoadPoster: %v", err) return @@ -78,7 +78,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(ctx context.Context, doer *user } } -func (m *webhookNotifier) NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { +func (m *webhookNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { oldMode, _ := access_model.AccessLevel(ctx, doer, oldRepo) mode, _ := access_model.AccessLevel(ctx, doer, repo) @@ -106,7 +106,7 @@ func (m *webhookNotifier) NotifyForkRepository(ctx context.Context, doer *user_m } } -func (m *webhookNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { +func (m *webhookNotifier) CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { // Add to hook queue for created repo after session commit. if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{ Action: api.HookRepoCreated, @@ -118,7 +118,7 @@ func (m *webhookNotifier) NotifyCreateRepository(ctx context.Context, doer, u *u } } -func (m *webhookNotifier) NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { +func (m *webhookNotifier) DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{ Action: api.HookRepoDeleted, Repository: convert.ToRepo(ctx, repo, perm.AccessModeOwner), @@ -129,7 +129,7 @@ func (m *webhookNotifier) NotifyDeleteRepository(ctx context.Context, doer *user } } -func (m *webhookNotifier) NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { +func (m *webhookNotifier) MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { // Add to hook queue for created repo after session commit. if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{ Action: api.HookRepoCreated, @@ -141,7 +141,7 @@ func (m *webhookNotifier) NotifyMigrateRepository(ctx context.Context, doer, u * } } -func (m *webhookNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { +func (m *webhookNotifier) IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) { if issue.IsPull { mode, _ := access_model.AccessLevelUnit(ctx, doer, issue.Repo, unit.TypePullRequests) @@ -187,7 +187,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *u } } -func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { +func (m *webhookNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo) var err error if issue.IsPull { @@ -228,7 +228,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user } } -func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { +func (m *webhookNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo) var err error if issue.IsPull { @@ -268,7 +268,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use } } -func (m *webhookNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { +func (m *webhookNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { if err := issue.LoadRepo(ctx); err != nil { log.Error("issue.LoadRepo: %v", err) return @@ -290,7 +290,7 @@ func (m *webhookNotifier) NotifyNewIssue(ctx context.Context, issue *issues_mode } } -func (m *webhookNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_model.PullRequest, mentions []*user_model.User) { +func (m *webhookNotifier) NewPullRequest(ctx context.Context, pull *issues_model.PullRequest, mentions []*user_model.User) { if err := pull.LoadIssue(ctx); err != nil { log.Error("pull.LoadIssue: %v", err) return @@ -316,7 +316,7 @@ func (m *webhookNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues } } -func (m *webhookNotifier) NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { +func (m *webhookNotifier) IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { if err := issue.LoadRepo(ctx); err != nil { log.Error("LoadRepo: %v", err) return @@ -357,7 +357,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(ctx context.Context, doer *us } } -func (m *webhookNotifier) NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { +func (m *webhookNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { if err := c.LoadPoster(ctx); err != nil { log.Error("LoadPoster: %v", err) return @@ -397,7 +397,7 @@ func (m *webhookNotifier) NotifyUpdateComment(ctx context.Context, doer *user_mo } } -func (m *webhookNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, +func (m *webhookNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, ) { var eventType webhook_module.HookEventType @@ -420,7 +420,7 @@ func (m *webhookNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us } } -func (m *webhookNotifier) NotifyDeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) { +func (m *webhookNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) { var err error if err = comment.LoadPoster(ctx); err != nil { @@ -457,7 +457,7 @@ func (m *webhookNotifier) NotifyDeleteComment(ctx context.Context, doer *user_mo } } -func (m *webhookNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { +func (m *webhookNotifier) NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { // Add to hook queue for created wiki page. if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{ Action: api.HookWikiCreated, @@ -470,7 +470,7 @@ func (m *webhookNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_mode } } -func (m *webhookNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { +func (m *webhookNotifier) EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { // Add to hook queue for edit wiki page. if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{ Action: api.HookWikiEdited, @@ -483,7 +483,7 @@ func (m *webhookNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_mod } } -func (m *webhookNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { +func (m *webhookNotifier) DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { // Add to hook queue for edit wiki page. if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{ Action: api.HookWikiDeleted, @@ -495,7 +495,7 @@ func (m *webhookNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_m } } -func (m *webhookNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, +func (m *webhookNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, addedLabels, removedLabels []*issues_model.Label, ) { var err error @@ -541,7 +541,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use } } -func (m *webhookNotifier) NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) { +func (m *webhookNotifier) IssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) { var hookAction api.HookIssueAction var err error if issue.MilestoneID > 0 { @@ -583,7 +583,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(ctx context.Context, doer * } } -func (m *webhookNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (m *webhookNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { apiPusher := convert.ToUser(pusher, nil) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL()) if err != nil { @@ -607,12 +607,12 @@ func (m *webhookNotifier) NotifyPushCommits(ctx context.Context, pusher *user_mo } } -func (m *webhookNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { - // just redirect to the NotifyMergePullRequest - m.NotifyMergePullRequest(ctx, doer, pr) +func (m *webhookNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { + // just redirect to the MergePullRequest + m.MergePullRequest(ctx, doer, pr) } -func (*webhookNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +func (*webhookNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { // Reload pull request information. if err := pr.LoadAttributes(ctx); err != nil { log.Error("LoadAttributes: %v", err) @@ -649,7 +649,7 @@ func (*webhookNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_m } } -func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) { +func (m *webhookNotifier) PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) { if err := pr.LoadIssue(ctx); err != nil { log.Error("LoadIssue: %v", err) return @@ -674,7 +674,7 @@ func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Contex } } -func (m *webhookNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { +func (m *webhookNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) { var reviewHookType webhook_module.HookEventType switch review.Type { @@ -715,7 +715,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(ctx context.Context, pr *issue } } -func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { +func (m *webhookNotifier) CreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { apiPusher := convert.ToUser(pusher, nil) apiRepo := convert.ToRepo(ctx, repo, perm.AccessModeNone) refName := git.RefEndName(refFullName) @@ -731,7 +731,7 @@ func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_mode } } -func (m *webhookNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +func (m *webhookNotifier) PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { if err := pr.LoadIssue(ctx); err != nil { log.Error("LoadIssue: %v", err) return @@ -752,7 +752,7 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(ctx context.Context, doe } } -func (m *webhookNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { +func (m *webhookNotifier) DeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { apiPusher := convert.ToUser(pusher, nil) apiRepo := convert.ToRepo(ctx, repo, perm.AccessModeNone) refName := git.RefEndName(refFullName) @@ -785,19 +785,19 @@ func sendReleaseHook(ctx context.Context, doer *user_model.User, rel *repo_model } } -func (m *webhookNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) { +func (m *webhookNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) { sendReleaseHook(ctx, rel.Publisher, rel, api.HookReleasePublished) } -func (m *webhookNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { +func (m *webhookNotifier) UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { sendReleaseHook(ctx, doer, rel, api.HookReleaseUpdated) } -func (m *webhookNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { +func (m *webhookNotifier) DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { sendReleaseHook(ctx, doer, rel, api.HookReleaseDeleted) } -func (m *webhookNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (m *webhookNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { apiPusher := convert.ToUser(pusher, nil) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL()) if err != nil { @@ -821,19 +821,19 @@ func (m *webhookNotifier) NotifySyncPushCommits(ctx context.Context, pusher *use } } -func (m *webhookNotifier) NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { - m.NotifyCreateRef(ctx, pusher, repo, refType, refFullName, refID) +func (m *webhookNotifier) SyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { + m.CreateRef(ctx, pusher, repo, refType, refFullName, refID) } -func (m *webhookNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { - m.NotifyDeleteRef(ctx, pusher, repo, refType, refFullName) +func (m *webhookNotifier) SyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { + m.DeleteRef(ctx, pusher, repo, refType, refFullName) } -func (m *webhookNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { +func (m *webhookNotifier) PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { notifyPackage(ctx, doer, pd, api.HookPackageCreated) } -func (m *webhookNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { +func (m *webhookNotifier) PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { notifyPackage(ctx, doer, pd, api.HookPackageDeleted) } From acfac226534cf98485699a314449981cf3b6c950 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 2 Jan 2023 23:31:08 +0800 Subject: [PATCH 08/12] Fix test --- services/webhook/deliver.go | 3 +++ services/webhook/notifier.go | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/services/webhook/deliver.go b/services/webhook/deliver.go index effbe45e56910..c730895ce25a9 100644 --- a/services/webhook/deliver.go +++ b/services/webhook/deliver.go @@ -27,6 +27,7 @@ import ( "code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/setting" webhook_module "code.gitea.io/gitea/modules/webhook" + "code.gitea.io/gitea/services/notify" "github.com/gobwas/glob" ) @@ -290,6 +291,8 @@ func Init() error { go graceful.GetManager().RunWithShutdownContext(populateWebhookSendingQueue) + notify.RegisterNotifier(&webhookNotifier{}) + return nil } diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index ff341b30ac001..a8a03093b7532 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -23,10 +23,6 @@ import ( "code.gitea.io/gitea/services/notify" ) -func init() { - notify.RegisterNotifier(&webhookNotifier{}) -} - type webhookNotifier struct { notify.NullNotifier } From d55e1e802782b2ce1418b396f617386c81ceb6af Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 3 Jan 2023 15:40:29 +0800 Subject: [PATCH 09/12] Try to fix test --- services/mailer/mailer.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/mailer/mailer.go b/services/mailer/mailer.go index b278ccba06f0d..02cb8f06b70d1 100644 --- a/services/mailer/mailer.go +++ b/services/mailer/mailer.go @@ -357,10 +357,6 @@ func NewContext(ctx context.Context) { return } - if setting.Service.EnableNotifyMail { - notify.RegisterNotifier(NewNotifier()) - } - switch setting.MailService.Protocol { case "sendmail": Sender = &sendmailSender{} @@ -387,6 +383,10 @@ func NewContext(ctx context.Context) { go graceful.GetManager().RunWithShutdownFns(mailQueue.Run) subjectTemplates, bodyTemplates = templates.Mailer(ctx) + + if setting.Service.EnableNotifyMail { + notify.RegisterNotifier(NewNotifier()) + } } // SendAsync send mail asynchronously From 5faece7940ed29870dd7069f44be33e1054cd154 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 7 Jan 2023 11:01:41 +0800 Subject: [PATCH 10/12] revert change of webhook --- services/webhook/deliver.go | 3 --- services/webhook/notifier.go | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/services/webhook/deliver.go b/services/webhook/deliver.go index c730895ce25a9..effbe45e56910 100644 --- a/services/webhook/deliver.go +++ b/services/webhook/deliver.go @@ -27,7 +27,6 @@ import ( "code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/setting" webhook_module "code.gitea.io/gitea/modules/webhook" - "code.gitea.io/gitea/services/notify" "github.com/gobwas/glob" ) @@ -291,8 +290,6 @@ func Init() error { go graceful.GetManager().RunWithShutdownContext(populateWebhookSendingQueue) - notify.RegisterNotifier(&webhookNotifier{}) - return nil } diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index a8a03093b7532..ff341b30ac001 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -23,6 +23,10 @@ import ( "code.gitea.io/gitea/services/notify" ) +func init() { + notify.RegisterNotifier(&webhookNotifier{}) +} + type webhookNotifier struct { notify.NullNotifier } From 80f64932e97bf85502509a7571fb4a55f2b70d85 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 7 Jan 2023 21:59:39 +0800 Subject: [PATCH 11/12] Fix test --- services/mailer/mailer.go | 3 ++- services/mailer/notifier.go | 2 +- tests/mssql.ini.tmpl | 3 +-- tests/mysql.ini.tmpl | 3 +-- tests/pgsql.ini.tmpl | 1 - 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/services/mailer/mailer.go b/services/mailer/mailer.go index 02cb8f06b70d1..9c47b4374fce7 100644 --- a/services/mailer/mailer.go +++ b/services/mailer/mailer.go @@ -365,6 +365,7 @@ func NewContext(ctx context.Context) { default: Sender = &smtpSender{} } + log.Trace("Init mail service %s success", setting.MailService.Protocol) mailQueue = queue.CreateQueue("mail", func(data ...queue.Data) []queue.Data { for _, datum := range data { @@ -385,7 +386,7 @@ func NewContext(ctx context.Context) { subjectTemplates, bodyTemplates = templates.Mailer(ctx) if setting.Service.EnableNotifyMail { - notify.RegisterNotifier(NewNotifier()) + notify.RegisterNotifier(newNotifier()) } } diff --git a/services/mailer/notifier.go b/services/mailer/notifier.go index ea7d605e763bb..a65b849daf7a2 100644 --- a/services/mailer/notifier.go +++ b/services/mailer/notifier.go @@ -22,7 +22,7 @@ type mailNotifier struct { var _ notify.Notifier = &mailNotifier{} // NewNotifier create a new mailNotifier notifier -func NewNotifier() notify.Notifier { +func newNotifier() notify.Notifier { return &mailNotifier{} } diff --git a/tests/mssql.ini.tmpl b/tests/mssql.ini.tmpl index 9cec6169f979b..77f38b931ab57 100644 --- a/tests/mssql.ini.tmpl +++ b/tests/mssql.ini.tmpl @@ -64,14 +64,13 @@ FROM = mssql-{{TEST_TYPE}}-test@gitea.io [service] REGISTER_EMAIL_CONFIRM = false REGISTER_MANUAL_CONFIRM = false -ENABLE_NOTIFY_MAIL = false DISABLE_REGISTRATION = false ENABLE_CAPTCHA = false REQUIRE_SIGNIN_VIEW = false DEFAULT_KEEP_EMAIL_PRIVATE = false DEFAULT_ALLOW_CREATE_ORGANIZATION = true NO_REPLY_ADDRESS = noreply.example.org -ENABLE_NOTIFY_MAIL = true +ENABLE_NOTIFY_MAIL = false [picture] DISABLE_GRAVATAR = false diff --git a/tests/mysql.ini.tmpl b/tests/mysql.ini.tmpl index 24a9a02dc46ce..033f326812890 100644 --- a/tests/mysql.ini.tmpl +++ b/tests/mysql.ini.tmpl @@ -85,14 +85,13 @@ FROM = mysql-{{TEST_TYPE}}-test@gitea.io [service] REGISTER_EMAIL_CONFIRM = false REGISTER_MANUAL_CONFIRM = false -ENABLE_NOTIFY_MAIL = false DISABLE_REGISTRATION = false ENABLE_CAPTCHA = false REQUIRE_SIGNIN_VIEW = false DEFAULT_KEEP_EMAIL_PRIVATE = false DEFAULT_ALLOW_CREATE_ORGANIZATION = true NO_REPLY_ADDRESS = noreply.example.org -ENABLE_NOTIFY_MAIL = true +ENABLE_NOTIFY_MAIL = false [picture] DISABLE_GRAVATAR = false diff --git a/tests/pgsql.ini.tmpl b/tests/pgsql.ini.tmpl index c39b6a79c3a8b..f8a0780f97f76 100644 --- a/tests/pgsql.ini.tmpl +++ b/tests/pgsql.ini.tmpl @@ -72,7 +72,6 @@ REQUIRE_SIGNIN_VIEW = false DEFAULT_KEEP_EMAIL_PRIVATE = false DEFAULT_ALLOW_CREATE_ORGANIZATION = true NO_REPLY_ADDRESS = noreply.example.org -ENABLE_NOTIFY_MAIL = true [picture] DISABLE_GRAVATAR = false From 6cf06ff6e27893c5110f4ec68777aaa9081083b6 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 1 May 2023 22:40:32 +0800 Subject: [PATCH 12/12] register notify in Init --- services/webhook/deliver.go | 4 ++++ services/webhook/notifier.go | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/webhook/deliver.go b/services/webhook/deliver.go index e389b1f9fe670..93429163442e3 100644 --- a/services/webhook/deliver.go +++ b/services/webhook/deliver.go @@ -26,6 +26,7 @@ import ( "code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/setting" webhook_module "code.gitea.io/gitea/modules/webhook" + "code.gitea.io/gitea/services/notify" "github.com/gobwas/glob" "github.com/minio/sha256-simd" @@ -282,10 +283,13 @@ func Init() error { }, } + notify.RegisterNotifier(&webhookNotifier{}) + hookQueue = queue.CreateUniqueQueue("webhook_sender", handle, int64(0)) if hookQueue == nil { return fmt.Errorf("Unable to create webhook_sender Queue") } + go graceful.GetManager().RunWithShutdownFns(hookQueue.Run) go graceful.GetManager().RunWithShutdownContext(populateWebhookSendingQueue) diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 9afe1ff2c59a4..9895e5da660c1 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -23,10 +23,6 @@ import ( "code.gitea.io/gitea/services/notify" ) -func init() { - notify.RegisterNotifier(&webhookNotifier{}) -} - type webhookNotifier struct { notify.NullNotifier }