diff --git a/main.go b/main.go index 1589fa97db434..cf836a01363b4 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,10 @@ 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" + "github.com/urfave/cli" ) diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go deleted file mode 100644 index 4021bbe141022..0000000000000 --- a/modules/notification/base/notifier.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2018 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package base - -import ( - "context" - - issues_model "code.gitea.io/gitea/models/issues" - 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/repository" -) - -// 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, commitID string, 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, - 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, - 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) -} diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go deleted file mode 100644 index 161eadfbecf27..0000000000000 --- a/modules/notification/base/null.go +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2019 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package base - -import ( - "context" - - issues_model "code.gitea.io/gitea/models/issues" - 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/repository" -) - -// NullNotifier implements a blank notifier -type NullNotifier struct{} - -var _ Notifier = &NullNotifier{} - -// Run places a place holder function -func (*NullNotifier) Run() { -} - -// NotifyCreateIssueComment places a place holder function -func (*NullNotifier) NotifyCreateIssueComment(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) { -} - -// NotifyIssueChangeStatus places a place holder function -func (*NullNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, 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) { -} - -// NotifyNewPullRequest places a place holder function -func (*NullNotifier) NotifyNewPullRequest(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) { -} - -// NotifyPullRequestCodeComment places a place holder function -func (*NullNotifier) NotifyPullRequestCodeComment(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) { -} - -// NotifyAutoMergePullRequest places a place holder function -func (*NullNotifier) NotifyAutoMergePullRequest(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) { -} - -// NotifyPullRequestChangeTargetBranch places a place holder function -func (*NullNotifier) NotifyPullRequestChangeTargetBranch(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) { -} - -// 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) { -} - -// NotifyUpdateComment places a place holder function -func (*NullNotifier) NotifyUpdateComment(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) { -} - -// NotifyNewWikiPage places a place holder function -func (*NullNotifier) NotifyNewWikiPage(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) { -} - -// NotifyDeleteWikiPage places a place holder function -func (*NullNotifier) NotifyDeleteWikiPage(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) { -} - -// NotifyUpdateRelease places a place holder function -func (*NullNotifier) NotifyUpdateRelease(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) { -} - -// NotifyIssueChangeMilestone places a place holder function -func (*NullNotifier) NotifyIssueChangeMilestone(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) { -} - -// 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) { -} - -// 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) { -} - -// NotifyIssueClearLabels places a place holder function -func (*NullNotifier) NotifyIssueClearLabels(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) { -} - -// NotifyIssueChangeRef places a place holder function -func (*NullNotifier) NotifyIssueChangeRef(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, - 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) { -} - -// NotifyDeleteRepository places a place holder function -func (*NullNotifier) NotifyDeleteRepository(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) { -} - -// NotifyMigrateRepository places a place holder function -func (*NullNotifier) NotifyMigrateRepository(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) { -} - -// 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) { -} - -// 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) { -} - -// NotifyRenameRepository places a place holder function -func (*NullNotifier) NotifyRenameRepository(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) { -} - -// 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) { -} - -// NotifySyncCreateRef places a place holder function -func (*NullNotifier) NotifySyncCreateRef(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) { -} - -// NotifyRepoPendingTransfer places a place holder function -func (*NullNotifier) NotifyRepoPendingTransfer(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) { -} - -// NotifyPackageDelete places a place holder function -func (*NullNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { -} diff --git a/modules/notification/notification.go b/modules/notification/notification.go deleted file mode 100644 index da2a7ab3a085e..0000000000000 --- a/modules/notification/notification.go +++ /dev/null @@ -1,372 +0,0 @@ -// Copyright 2018 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package notification - -import ( - "context" - - issues_model "code.gitea.io/gitea/models/issues" - 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/log" - "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/repository" - "code.gitea.io/gitea/modules/setting" -) - -var notifiers []base.Notifier - -// RegisterNotifier providers method to receive notify messages -func RegisterNotifier(notifier base.Notifier) { - go notifier.Run() - notifiers = append(notifiers, notifier) -} - -// NewContext registers notification handlers -func NewContext() { - RegisterNotifier(ui.NewNotifier()) - if setting.Service.EnableNotifyMail { - RegisterNotifier(mail.NewNotifier()) - } - RegisterNotifier(indexer.NewNotifier()) - RegisterNotifier(action.NewNotifier()) - RegisterNotifier(mirror.NewNotifier()) -} - -// NotifyNewWikiPage notifies creating new wiki pages to notifiers -func NotifyNewWikiPage(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) - } -} - -// 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) { - 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) { - 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, - issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, -) { - for _, notifier := range notifiers { - notifier.NotifyCreateIssueComment(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) { - 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, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) { - for _, notifier := range notifiers { - notifier.NotifyIssueChangeStatus(ctx, doer, commitID, issue, actionComment, closeOrReopen) - } -} - -// NotifyDeleteIssue notify when some issue deleted -func NotifyDeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { - 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) { - 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) { - 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) { - if err := pr.LoadIssue(ctx); err != nil { - log.Error("%v", err) - return - } - if err := pr.Issue.LoadPoster(ctx); err != nil { - return - } - 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) { - 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) { - if err := review.LoadReviewer(ctx); err != nil { - log.Error("%v", err) - return - } - 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) { - if err := comment.LoadPoster(ctx); err != nil { - log.Error("LoadPoster: %v", err) - return - } - 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) { - 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) { - 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) { - 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) { - 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) { - for _, notifier := range notifiers { - notifier.NotifyDeleteComment(ctx, doer, c) - } -} - -// NotifyNewRelease notifies new release to notifiers -func NotifyNewRelease(ctx context.Context, rel *repo_model.Release) { - if err := rel.LoadAttributes(ctx); err != nil { - log.Error("LoadPublisher: %v", err) - return - } - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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, - addedLabels, removedLabels []*issues_model.Label, -) { - for _, notifier := range notifiers { - notifier.NotifyIssueChangeLabels(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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - for _, notifier := range notifiers { - notifier.NotifyPackageDelete(ctx, doer, pd) - } -} diff --git a/routers/api/packages/conan/conan.go b/routers/api/packages/conan/conan.go index d538cc7d397db..b11c83b23e57b 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.PackageDelete(apictx, apictx.Doer, pd) } return nil diff --git a/routers/api/packages/container/manifest.go b/routers/api/packages/container/manifest.go index 1dbd058d6b11c..fb9ad75c423f2 100644 --- a/routers/api/packages/container/manifest.go +++ b/routers/api/packages/container/manifest.go @@ -17,10 +17,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" container_module "code.gitea.io/gitea/modules/packages/container" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/notify" packages_service "code.gitea.io/gitea/services/packages" digest "github.com/opencontainers/go-digest" @@ -306,7 +306,7 @@ func notifyPackageCreate(doer *user_model.User, pv *packages_model.PackageVersio return err } - notification.NotifyPackageCreate(db.DefaultContext, doer, pd) + notify.PackageCreate(db.DefaultContext, doer, pd) return nil } diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 5bf5fc8c8bcca..c22d9b8e21ef0 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 @@ -829,11 +829,11 @@ func EditIssue(ctx *context.APIContext) { } if titleChanged { - notification.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) + notify.IssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) } if statusChangeComment != nil { - notification.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 efce39e520344..2883967161a1e 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.MigrateRepository(ctx, ctx.Doer, repoOwner, repo) return } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index f4e2969d7d1c2..c87b757c28fe5 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -24,7 +24,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" @@ -36,6 +35,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" ) @@ -596,11 +596,11 @@ func EditPullRequest(ctx *context.APIContext) { } if titleChanged { - notification.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) + notify.IssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) } if statusChangeComment != nil { - notification.NotifyIssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed) + notify.IssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed) } // change pull target branch @@ -624,7 +624,7 @@ func EditPullRequest(ctx *context.APIContext) { } return } - notification.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 0b9a36ec47004..d4313adfbd68d 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, string(wikiName), form.Message) + notify.NewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(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, string(newWikiName), form.Message) + notify.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(newWikiName), form.Message) ctx.JSON(http.StatusOK, wikiPage) } } @@ -242,7 +242,7 @@ func DeleteWikiPage(ctx *context.APIContext) { return } - notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName)) + notify.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName)) ctx.Status(http.StatusNoContent) } diff --git a/routers/init.go b/routers/init.go index 358922b1aea46..fcb0b3d59a9d9 100644 --- a/routers/init.go +++ b/routers/init.go @@ -20,7 +20,6 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/external" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/ssh" "code.gitea.io/gitea/modules/storage" @@ -50,6 +49,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" ) @@ -125,7 +125,7 @@ func GlobalInitInstalled(ctx context.Context) { mailer.NewContext(ctx) mustInit(cache.NewContext) - notification.NewContext() + uinotification.Init() mustInit(archiver.Init) highlight.NewContext() diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 070fc109dcec9..ef59db47ed5ab 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" ) @@ -1518,7 +1518,7 @@ func UpdatePullRequestTarget(ctx *context.Context) { } return } - notification.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 374d1bf2e0691..81634068d5c6b 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" ) @@ -723,7 +723,7 @@ func NewWikiPost(ctx *context.Context) { return } - notification.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName), form.Message) + notify.NewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName), form.Message) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.WebPathToURLPath(wikiName)) } @@ -767,7 +767,7 @@ func EditWikiPost(ctx *context.Context) { return } - notification.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(newWikiName), form.Message) + notify.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(newWikiName), form.Message) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.WebPathToURLPath(newWikiName)) } @@ -784,7 +784,7 @@ func DeleteWikiPagePost(ctx *context.Context) { return } - notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName)) + notify.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName)) ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/wiki/", diff --git a/services/actions/init.go b/services/actions/init.go index 3fd03eeb6f26c..861e600179c09 100644 --- a/services/actions/init.go +++ b/services/actions/init.go @@ -5,9 +5,9 @@ package actions import ( "code.gitea.io/gitea/modules/graceful" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/services/notify" ) func Init() { @@ -18,5 +18,5 @@ func Init() { jobEmitterQueue = queue.CreateUniqueQueue("actions_ready_job", jobEmitterQueueHandle, new(jobUpdate)) go graceful.GetManager().RunWithShutdownFns(jobEmitterQueue.Run) - notification.RegisterNotifier(NewNotifier()) + notify.RegisterNotifier(NewNotifier()) } diff --git a/services/actions/notifier.go b/services/actions/notifier.go index 4ac77276ffe2e..55ac45eb0aaa6 100644 --- a/services/actions/notifier.go +++ b/services/actions/notifier.go @@ -15,22 +15,22 @@ 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/base" "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" ) type actionsNotifier struct { - base.NullNotifier + notify.NullNotifier } -var _ base.Notifier = &actionsNotifier{} +var _ notify.Notifier = &actionsNotifier{} // NewNotifier create a new actionsNotifier notifier -func NewNotifier() base.Notifier { +func NewNotifier() notify.Notifier { return &actionsNotifier{} } diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 376c9820f1983..0dae5bc099bf1 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -98,12 +98,13 @@ func (input *notifyInput) WithPullRequest(pr *issues_model.PullRequest) *notifyI func (input *notifyInput) Notify(ctx context.Context) { log.Trace("execute %v for event %v whose doer is %v", getMethod(ctx), input.Event, input.Doer.Name) - if err := notify(ctx, input); err != nil { + if err := notifyFunc(ctx, input); err != nil { log.Error("an error occurred while executing the %s actions method: %v", getMethod(ctx), err) } } -func notify(ctx context.Context, input *notifyInput) error { +// notifyFunc the name addes suffix Func to avoid name conflict with the notify package +func notifyFunc(ctx context.Context, input *notifyInput) error { if input.Doer.IsActions() { // avoiding triggering cyclically, for example: // a comment of an issue will trigger the runner to add a new comment as reply, diff --git a/services/agit/agit.go b/services/agit/agit.go index 32fc3cba4a36e..de197cf23ab8b 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.PullRequestPushCommits(ctx, pusher, pr, comment) } - notification.NotifyPullRequestSynchronized(ctx, pusher, pr) + notify.PullRequestSynchronized(ctx, pusher, pr) isForcePush := comment != nil && comment.IsForcePush results = append(results, private.HookProcReceiveRefResult{ diff --git a/modules/notification/action/action.go b/services/feed/action.go similarity index 77% rename from modules/notification/action/action.go rename to services/feed/action.go index c043ef62d5acb..0bdf21c01a582 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,23 +15,27 @@ 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/base" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/notify" ) type actionNotifier struct { - base.NullNotifier + notify.NullNotifier } -var _ base.Notifier = &actionNotifier{} +var _ notify.Notifier = &actionNotifier{} // NewNotifier create a new actionNotifier notifier -func NewNotifier() base.Notifier { +func NewNotifier() notify.Notifier { return &actionNotifier{} } -func (a *actionNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { +func init() { + notify.RegisterNotifier(NewNotifier()) +} + +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 @@ -55,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, commitID string, 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, commitID string, 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{ @@ -82,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{ @@ -118,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 @@ -151,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, @@ -165,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, @@ -179,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, @@ -192,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, @@ -205,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 @@ -263,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, @@ -277,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, @@ -291,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 @@ -311,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) @@ -344,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{ @@ -363,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{ @@ -382,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) @@ -403,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), @@ -417,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), @@ -431,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/modules/notification/action/action_test.go b/services/feed/action_test.go similarity index 82% rename from modules/notification/action/action_test.go rename to services/feed/action_test.go index 05ce70f38877d..a5c092bb53716 100644 --- a/modules/notification/action/action_test.go +++ b/services/feed/action_test.go @@ -1,10 +1,9 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package action +package feed_test import ( - "path/filepath" "strings" "testing" @@ -13,16 +12,11 @@ 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" ) -func TestMain(m *testing.M) { - unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), - }) -} - func TestRenameRepoAction(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) @@ -46,7 +40,7 @@ func TestRenameRepoAction(t *testing.T) { } unittest.AssertNotExistsBean(t, actionBean) - NewNotifier().NotifyRenameRepository(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 new file mode 100644 index 0000000000000..544e3952fbfdf --- /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_test + +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/modules/notification/indexer/indexer.go b/services/indexer/notifier.go similarity index 65% rename from modules/notification/indexer/indexer.go rename to services/indexer/notifier.go index c67f79d0f2ae5..534ee9e2231e9 100644 --- a/modules/notification/indexer/indexer.go +++ b/services/indexer/notifier.go @@ -14,23 +14,27 @@ 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/base" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/services/notify" ) type indexerNotifier struct { - base.NullNotifier + notify.NullNotifier } -var _ base.Notifier = &indexerNotifier{} +var _ notify.Notifier = &indexerNotifier{} // NewNotifier create a new indexerNotifier notifier -func NewNotifier() base.Notifier { +func NewNotifier() notify.Notifier { return &indexerNotifier{} } -func (r *indexerNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, +func init() { + notify.RegisterNotifier(NewNotifier()) +} + +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 { @@ -47,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 { @@ -79,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) @@ -108,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) @@ -125,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) } @@ -134,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) } @@ -143,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/issue/assignee.go b/services/issue/assignee.go index 4d0224d4bff10..9f77638c5cff2 100644 --- a/services/issue/assignee.go +++ b/services/issue/assignee.go @@ -13,7 +13,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 @@ -55,7 +55,7 @@ func ToggleAssignee(ctx context.Context, issue *issues_model.Issue, doer *user_m return } - notification.NotifyIssueChangeAssignee(ctx, doer, issue, assignee, removed, comment) + notify.IssueChangeAssignee(ctx, doer, issue, assignee, removed, comment) return removed, comment, err } @@ -73,7 +73,7 @@ func ReviewRequest(ctx context.Context, issue *issues_model.Issue, doer, reviewe } if comment != nil { - notification.NotifyPullReviewRequest(ctx, doer, issue, reviewer, isAdd, comment) + notify.PullReviewRequest(ctx, doer, issue, reviewer, isAdd, comment) } return comment, err @@ -260,7 +260,7 @@ func TeamReviewRequest(ctx context.Context, issue *issues_model.Issue, doer *use continue } comment.AssigneeID = member.ID - notification.NotifyPullReviewRequest(ctx, doer, issue, member, isAdd, comment) + notify.PullReviewRequest(ctx, doer, issue, member, isAdd, comment) } return comment, err diff --git a/services/issue/comments.go b/services/issue/comments.go index 4a181499bcd8e..d9429aa23bd16 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.CreateIssueComment(ctx, doer, repo, issue, comment, mentions) return comment, nil } @@ -115,7 +115,7 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, doer *user_mode } } - notification.NotifyUpdateComment(ctx, doer, c, oldContent) + notify.UpdateComment(ctx, doer, c, oldContent) return nil } @@ -129,7 +129,7 @@ func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_m return err } - notification.NotifyDeleteComment(ctx, doer, comment) + notify.DeleteComment(ctx, doer, comment) return nil } diff --git a/services/issue/content.go b/services/issue/content.go index 819ac3f20f6ba..4a064f5a3c76f 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.IssueChangeContent(db.DefaultContext, doer, issue, oldContent) return nil } diff --git a/services/issue/issue.go b/services/issue/issue.go index d4f827e99af56..feca1076bfe99 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -16,8 +16,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. @@ -37,12 +37,12 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *issues_mo return err } - notification.NotifyNewIssue(ctx, issue, mentions) + notify.NewIssue(ctx, issue, mentions) if len(issue.Labels) > 0 { - notification.NotifyIssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil) + notify.IssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil) } if issue.Milestone != nil { - notification.NotifyIssueChangeMilestone(ctx, issue.Poster, issue, 0) + notify.IssueChangeMilestone(ctx, issue.Poster, issue, 0) } return nil @@ -57,7 +57,7 @@ func ChangeTitle(ctx context.Context, issue *issues_model.Issue, doer *user_mode return } - notification.NotifyIssueChangeTitle(ctx, doer, issue, oldTitle) + notify.IssueChangeTitle(ctx, doer, issue, oldTitle) return nil } @@ -71,7 +71,7 @@ func ChangeIssueRef(ctx context.Context, issue *issues_model.Issue, doer *user_m return err } - notification.NotifyIssueChangeRef(ctx, doer, issue, oldRef) + notify.IssueChangeRef(ctx, doer, issue, oldRef) return nil } @@ -153,7 +153,7 @@ func DeleteIssue(ctx context.Context, doer *user_model.User, gitRepo *git.Reposi } } - notification.NotifyDeleteIssue(ctx, doer, issue) + notify.DeleteIssue(ctx, doer, issue) return nil } diff --git a/services/issue/label.go b/services/issue/label.go index c18abbfcda3d2..a1ebea96144d8 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.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 } - notification.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 } - notification.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 } - notification.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 } - notification.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 a9be8bd887871..332acfd1b3ce9 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.IssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID) return nil } diff --git a/services/issue/status.go b/services/issue/status.go index d4a0fce3e586a..23914f82bfb24 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, commitID, issue, comment, closed) + notify.IssueChangeStatus(ctx, doer, commitID, issue, comment, closed) return nil } diff --git a/services/mailer/mailer.go b/services/mailer/mailer.go index 91cc8cb405e0b..92d28b8ba1769 100644 --- a/services/mailer/mailer.go +++ b/services/mailer/mailer.go @@ -25,6 +25,7 @@ import ( "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" @@ -368,6 +369,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 { @@ -386,6 +388,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 diff --git a/modules/notification/mail/mail.go b/services/mailer/notifier.go similarity index 51% rename from modules/notification/mail/mail.go rename to services/mailer/notifier.go index 7e54df44c4032..50045c4182679 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" @@ -12,22 +12,21 @@ 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/base" - "code.gitea.io/gitea/services/mailer" + "code.gitea.io/gitea/services/notify" ) type mailNotifier struct { - base.NullNotifier + notify.NullNotifier } -var _ base.Notifier = &mailNotifier{} +var _ notify.Notifier = &mailNotifier{} // NewNotifier create a new mailNotifier notifier -func NewNotifier() base.Notifier { +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 @@ -43,18 +42,18 @@ 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 { +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, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { +func (m *mailNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { var actionType activities_model.ActionType if issue.IsPull { if isClosed { @@ -70,30 +69,30 @@ 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) } } -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 } 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 { +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 @@ -102,57 +101,57 @@ 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 { +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) - 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) } } } -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 := 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) } } } -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 } - 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) } } -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 } - 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) } } -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) @@ -173,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) { - if err := mailer.MailParticipantsComment(ctx, comment, activities_model.ActionPullReviewDismissed, review.Issue, nil); err != nil { +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 @@ -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 { +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/mirror_pull.go b/services/mirror/mirror_pull.go index 60699294c18bd..0ab6458a9c72a 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -16,13 +16,13 @@ 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" "code.gitea.io/gitea/modules/proxy" 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 @@ -462,18 +462,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.SyncPushCommits(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.SyncCreateRef(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.SyncDeleteRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName) continue } @@ -508,7 +508,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.SyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ RefFullName: result.refName, OldCommitID: oldCommitID, NewCommitID: newCommitID, diff --git a/modules/notification/mirror/mirror.go b/services/mirror/notifier.go similarity index 62% rename from modules/notification/mirror/mirror.go rename to services/mirror/notifier.go index 426e36ee58bd6..d410860c976ae 100644 --- a/modules/notification/mirror/mirror.go +++ b/services/mirror/notifier.go @@ -10,26 +10,30 @@ 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/base" "code.gitea.io/gitea/modules/repository" + "code.gitea.io/gitea/services/notify" ) type mirrorNotifier struct { - base.NullNotifier + notify.NullNotifier } -var _ base.Notifier = &mirrorNotifier{} +var _ notify.Notifier = &mirrorNotifier{} // NewNotifier create a new mirrorNotifier notifier -func NewNotifier() base.Notifier { +func NewNotifier() notify.Notifier { return &mirrorNotifier{} } -func (m *mirrorNotifier) NotifyPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) { +func init() { + notify.RegisterNotifier(NewNotifier()) +} + +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/notify/notifier.go b/services/notify/notifier.go new file mode 100644 index 0000000000000..4da017388e014 --- /dev/null +++ b/services/notify/notifier.go @@ -0,0 +1,65 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package notify + +import ( + "context" + + issues_model "code.gitea.io/gitea/models/issues" + 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/repository" +) + +// Notifier defines an interface to notify receiver +type Notifier interface { + Run() + 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, commitID string, 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) + 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) + 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 new file mode 100644 index 0000000000000..6ee0d45bb4373 --- /dev/null +++ b/services/notify/notify.go @@ -0,0 +1,339 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package notify + +import ( + "context" + + issues_model "code.gitea.io/gitea/models/issues" + 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/log" + "code.gitea.io/gitea/modules/repository" +) + +var notifiers []Notifier + +// RegisterNotifier providers method to receive notify messages +func RegisterNotifier(notifier Notifier) { + go notifier.Run() + notifiers = append(notifiers, notifier) +} + +// 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.NewWikiPage(ctx, doer, repo, page, comment) + } +} + +// 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.EditWikiPage(ctx, doer, repo, page, comment) + } +} + +// 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.DeleteWikiPage(ctx, doer, repo, page) + } +} + +// 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.CreateIssueComment(ctx, doer, repo, issue, comment, mentions) + } +} + +// NewIssue notifies new issue to notifiers +func NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { + for _, notifier := range notifiers { + notifier.NewIssue(ctx, issue, mentions) + } +} + +// IssueChangeStatus notifies close or reopen issue to notifiers +func IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) { + for _, notifier := range notifiers { + notifier.IssueChangeStatus(ctx, doer, commitID, issue, actionComment, closeOrReopen) + } +} + +// DeleteIssue notify when some issue deleted +func DeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { + for _, notifier := range notifiers { + notifier.DeleteIssue(ctx, doer, issue) + } +} + +// 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.MergePullRequest(ctx, doer, pr) + } +} + +// 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.AutoMergePullRequest(ctx, doer, pr) + } +} + +// 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.NewPullRequest(ctx, pr, mentions) + } +} + +// PullRequestSynchronized notifies Synchronized pull request +func PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { + for _, notifier := range notifiers { + notifier.PullRequestSynchronized(ctx, doer, pr) + } +} + +// 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.PullRequestReview(ctx, pr, review, comment, mentions) + } +} + +// 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.PullRequestCodeComment(ctx, pr, comment, mentions) + } +} + +// 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.PullRequestChangeTargetBranch(ctx, doer, pr, oldBranch) + } +} + +// 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.PullRequestPushCommits(ctx, doer, pr, comment) + } +} + +// 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.PullReviewDismiss(ctx, doer, review, comment) + } +} + +// 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.UpdateComment(ctx, doer, c, oldContent) + } +} + +// DeleteComment notifies delete comment to notifiers +func DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) { + for _, notifier := range notifiers { + notifier.DeleteComment(ctx, doer, c) + } +} + +// NewRelease notifies new release to notifiers +func NewRelease(ctx context.Context, rel *repo_model.Release) { + if err := rel.LoadAttributes(ctx); err != nil { + log.Error("LoadPublisher: %v", err) + return + } + for _, notifier := range notifiers { + notifier.NewRelease(ctx, rel) + } +} + +// UpdateRelease notifies update release to notifiers +func UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { + for _, notifier := range notifiers { + notifier.UpdateRelease(ctx, doer, rel) + } +} + +// DeleteRelease notifies delete release to notifiers +func DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { + for _, notifier := range notifiers { + notifier.DeleteRelease(ctx, doer, rel) + } +} + +// 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.IssueChangeMilestone(ctx, doer, issue, oldMilestoneID) + } +} + +// 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.IssueChangeContent(ctx, doer, issue, oldContent) + } +} + +// 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.IssueChangeAssignee(ctx, doer, issue, assignee, removed, comment) + } +} + +// 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.PullReviewRequest(ctx, doer, issue, reviewer, isRequest, comment) + } +} + +// IssueClearLabels notifies clear labels to notifiers +func IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { + for _, notifier := range notifiers { + notifier.IssueClearLabels(ctx, doer, issue) + } +} + +// 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.IssueChangeTitle(ctx, doer, issue, oldTitle) + } +} + +// 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.IssueChangeRef(ctx, doer, issue, oldRef) + } +} + +// 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.IssueChangeLabels(ctx, doer, issue, addedLabels, removedLabels) + } +} + +// 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.CreateRepository(ctx, doer, u, repo) + } +} + +// 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.MigrateRepository(ctx, doer, u, repo) + } +} + +// 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.TransferRepository(ctx, doer, repo, newOwnerName) + } +} + +// DeleteRepository notifies delete repository to notifiers +func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { + for _, notifier := range notifiers { + notifier.DeleteRepository(ctx, doer, repo) + } +} + +// 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.ForkRepository(ctx, doer, oldRepo, repo) + } +} + +// RenameRepository notifies repository renamed +func RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldName string) { + for _, notifier := range notifiers { + notifier.RenameRepository(ctx, doer, repo, oldName) + } +} + +// 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.PushCommits(ctx, pusher, repo, opts, commits) + } +} + +// 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.CreateRef(ctx, pusher, repo, refType, refFullName, refID) + } +} + +// 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.DeleteRef(ctx, pusher, repo, refType, refFullName) + } +} + +// 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.SyncPushCommits(ctx, pusher, repo, opts, commits) + } +} + +// 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.SyncCreateRef(ctx, pusher, repo, refType, refFullName, refID) + } +} + +// 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.SyncDeleteRef(ctx, pusher, repo, refType, refFullName) + } +} + +// 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.RepoPendingTransfer(ctx, doer, newOwner, repo) + } +} + +// 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.PackageCreate(ctx, doer, pd) + } +} + +// 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.PackageDelete(ctx, doer, pd) + } +} diff --git a/services/notify/null.go b/services/notify/null.go new file mode 100644 index 0000000000000..153a260475503 --- /dev/null +++ b/services/notify/null.go @@ -0,0 +1,201 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package notify + +import ( + "context" + + issues_model "code.gitea.io/gitea/models/issues" + 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/repository" +) + +// NullNotifier implements a blank notifier +type NullNotifier struct{} + +var _ Notifier = &NullNotifier{} + +// Run places a place holder function +func (*NullNotifier) Run() { +} + +// 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) { +} + +// NewIssue places a place holder function +func (*NullNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { +} + +// IssueChangeStatus places a place holder function +func (*NullNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { +} + +// DeleteIssue notify when some issue deleted +func (*NullNotifier) DeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { +} + +// NewPullRequest places a place holder function +func (*NullNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, 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) { +} + +// PullRequestCodeComment places a place holder function +func (*NullNotifier) PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { +} + +// MergePullRequest places a place holder function +func (*NullNotifier) MergePullRequest(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) { +} + +// PullRequestSynchronized places a place holder function +func (*NullNotifier) PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { +} + +// PullRequestChangeTargetBranch places a place holder function +func (*NullNotifier) PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) { +} + +// 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) { +} + +// 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) { +} + +// UpdateComment places a place holder function +func (*NullNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { +} + +// DeleteComment places a place holder function +func (*NullNotifier) DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) { +} + +// NewWikiPage places a place holder function +func (*NullNotifier) NewWikiPage(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) { +} + +// DeleteWikiPage places a place holder function +func (*NullNotifier) DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { +} + +// NewRelease places a place holder function +func (*NullNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) { +} + +// UpdateRelease places a place holder function +func (*NullNotifier) UpdateRelease(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) { +} + +// IssueChangeMilestone places a place holder function +func (*NullNotifier) IssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) { +} + +// IssueChangeContent places a place holder function +func (*NullNotifier) IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) { +} + +// 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) { +} + +// 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) { +} + +// IssueClearLabels places a place holder function +func (*NullNotifier) IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) { +} + +// IssueChangeTitle places a place holder function +func (*NullNotifier) IssueChangeTitle(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) { +} + +// 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) { +} + +// CreateRepository places a place holder function +func (*NullNotifier) CreateRepository(ctx context.Context, doer, u *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) { +} + +// ForkRepository places a place holder function +func (*NullNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, 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) { +} + +// 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) { +} + +// 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) { +} + +// 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) { +} + +// RenameRepository places a place holder function +func (*NullNotifier) RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) { +} + +// TransferRepository places a place holder function +func (*NullNotifier) TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) { +} + +// 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) { +} + +// SyncCreateRef places a place holder function +func (*NullNotifier) SyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { +} + +// SyncDeleteRef places a place holder function +func (*NullNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) { +} + +// RepoPendingTransfer places a place holder function +func (*NullNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { +} + +// PackageCreate places a place holder function +func (*NullNotifier) PackageCreate(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 dd5c63470b8b2..24e9c009a7222 100644 --- a/services/packages/packages.go +++ b/services/packages/packages.go @@ -17,10 +17,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" ) var ( @@ -111,7 +111,7 @@ func createPackageAndAddFile(pvci *PackageCreationInfo, pfci *PackageFileCreatio return nil, nil, err } - notification.NotifyPackageCreate(db.DefaultContext, pvci.Creator, pd) + notify.PackageCreate(db.DefaultContext, pvci.Creator, pd) } return pv, pf, nil @@ -419,7 +419,7 @@ func RemovePackageVersion(doer *user_model.User, pv *packages_model.PackageVersi return err } - notification.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 02d901541461f..26d3c3eb8c2fa 100644 --- a/services/pull/check.go +++ b/services/pull/check.go @@ -22,11 +22,11 @@ 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" asymkey_service "code.gitea.io/gitea/services/asymkey" + "code.gitea.io/gitea/services/notify" ) // prPatchCheckerQueue represents a queue to handle update pull request tests @@ -297,7 +297,7 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool { return false } - notification.NotifyMergePullRequest(ctx, merger, pr) + notify.MergePullRequest(ctx, merger, pr) log.Info("manuallyMerged[%-v]: Marked as manually merged into %s/%s by commit id: %s", pr, pr.BaseRepo.Name, pr.BaseBranch, commit.ID.String()) return true diff --git a/services/pull/merge.go b/services/pull/merge.go index 12e01e8ce74a5..841947522ff97 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -26,12 +26,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/references" 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" ) // GetDefaultMergeMessage returns default message used when merging pull request @@ -197,9 +197,9 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U } if wasAutoMerged { - notification.NotifyAutoMergePullRequest(hammerCtx, doer, pr) + notify.AutoMergePullRequest(hammerCtx, doer, pr) } else { - notification.NotifyMergePullRequest(hammerCtx, doer, pr) + notify.MergePullRequest(hammerCtx, doer, pr) } // Reset cached commit count @@ -512,7 +512,7 @@ func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGit return err } - notification.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 55dfd3c180297..a8f85784791d6 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -22,13 +22,13 @@ 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" "code.gitea.io/gitea/modules/util" issue_service "code.gitea.io/gitea/services/issue" + "code.gitea.io/gitea/services/notify" ) // TODO: use clustered lock (unique queue? or *abuse* cache) @@ -80,12 +80,12 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *issu return err } - notification.NotifyNewPullRequest(prCtx, pr, mentions) + notify.NewPullRequest(prCtx, pr, mentions) if len(pull.Labels) > 0 { - notification.NotifyIssueChangeLabels(prCtx, pull.Poster, pull, pull.Labels, nil) + notify.IssueChangeLabels(prCtx, pull.Poster, pull, pull.Labels, nil) } if pull.Milestone != nil { - notification.NotifyIssueChangeMilestone(prCtx, pull.Poster, pull, 0) + notify.IssueChangeMilestone(prCtx, pull.Poster, pull, 0) } // add first push codes comment @@ -280,7 +280,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 && !pr.Issue.IsClosed { - notification.NotifyPullRequestPushCommits(ctx, doer, pr, comment) + notify.PullRequestPushCommits(ctx, doer, pr, comment) } } @@ -323,7 +323,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, } } - notification.NotifyPullRequestSynchronized(ctx, doer, pr) + notify.PullRequestSynchronized(ctx, doer, pr) } } } diff --git a/services/pull/review.go b/services/pull/review.go index 6feffe4ec4e7a..f99211ab00a76 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" ) var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines?`) @@ -114,7 +114,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.CreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions) return comment, nil } @@ -299,7 +299,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.PullRequestReview(ctx, pr, review, comm, mentions) for _, lines := range review.CodeComments { for _, comments := range lines { @@ -308,7 +308,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.PullRequestCodeComment(ctx, pr, codeComment, mentions) } } } @@ -384,7 +384,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.PullReviewDismiss(ctx, doer, review, comment) return comment, err } diff --git a/services/release/release.go b/services/release/release.go index a9a5231197762..82a5384bc2a28 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.PushCommits( 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.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 { - notification.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 { - notification.NotifyUpdateRelease(gitRepo.Ctx, doer, rel) + notify.UpdateRelease(gitRepo.Ctx, doer, rel) return } if !rel.IsDraft { - notification.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) } - notification.NotifyPushCommits( + notify.PushCommits( 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.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 } } - notification.NotifyDeleteRelease(ctx, doer, rel) + notify.DeleteRelease(ctx, doer, rel) return nil } diff --git a/services/repository/adopt.go b/services/repository/adopt.go index 55e77a78a78a9..9e06e4b4bb13a 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(ctx context.Context, doer, u *user_model.User, opts repo_mo return nil, err } - notification.NotifyCreateRepository(ctx, doer, u, repo) + notify.CreateRepository(ctx, doer, u, repo) return repo, nil } diff --git a/services/repository/branch.go b/services/repository/branch.go index a085026ae1563..15ff99101a12e 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -15,8 +15,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" ) @@ -140,8 +140,8 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m return "", err } - notification.NotifyDeleteRef(ctx, doer, repo, "branch", git.BranchPrefix+from) - notification.NotifyCreateRef(ctx, doer, repo, "branch", git.BranchPrefix+to, refID) + notify.DeleteRef(ctx, doer, repo, "branch", git.BranchPrefix+from) + notify.CreateRef(ctx, doer, repo, "branch", git.BranchPrefix+to, refID) return "", nil } diff --git a/services/repository/fork.go b/services/repository/fork.go index fb93b10f1c312..f9fb2d0da31b3 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.ForkRepository(ctx, doer, opts.BaseRepo, repo) return repo, nil } diff --git a/services/repository/push.go b/services/repository/push.go index 7f174c71b3f86..10d834352fc17 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" ) @@ -121,7 +121,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } tagName := opts.TagName() if opts.IsDelRef() { - notification.NotifyPushCommits( + notify.PushCommits( ctx, pusher, repo, &repo_module.PushUpdateOptions{ RefFullName: git.TagPrefix + tagName, @@ -130,7 +130,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { }, repo_module.NewPushCommits()) delTags = append(delTags, tagName) - notification.NotifyDeleteRef(ctx, pusher, repo, "tag", opts.RefFullName) + notify.DeleteRef(ctx, pusher, repo, "tag", opts.RefFullName) } else { // is new tag newCommit, err := gitRepo.GetCommit(opts.NewCommitID) if err != nil { @@ -141,7 +141,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.PushCommits( ctx, pusher, repo, &repo_module.PushUpdateOptions{ RefFullName: git.TagPrefix + tagName, @@ -150,7 +150,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { }, commits) addTags = append(addTags, tagName) - notification.NotifyCreateRef(ctx, pusher, repo, "tag", opts.RefFullName, opts.NewCommitID) + notify.CreateRef(ctx, pusher, repo, "tag", opts.RefFullName, opts.NewCommitID) } } else if opts.IsBranch() { // If is branch reference if pusher == nil || pusher.ID != opts.PusherID { @@ -199,7 +199,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { if err != nil { return fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err) } - notification.NotifyCreateRef(ctx, pusher, repo, "branch", opts.RefFullName, opts.NewCommitID) + notify.CreateRef(ctx, pusher, repo, "branch", opts.RefFullName, opts.NewCommitID) } else { l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID) if err != nil { @@ -259,7 +259,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { commits.Commits = commits.Commits[:setting.UI.FeedMaxCommitNum] } - notification.NotifyPushCommits(ctx, pusher, repo, opts, commits) + notify.PushCommits(ctx, pusher, repo, opts, commits) if err = git_model.RemoveDeletedBranchByName(ctx, repo.ID, branch); err != nil { log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, branch, err) @@ -270,7 +270,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { log.Error("repo_module.CacheRef %s/%s failed: %v", repo.ID, branch, err) } } else { - notification.NotifyDeleteRef(ctx, pusher, repo, "branch", opts.RefFullName) + notify.DeleteRef(ctx, 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 0d6529383cc8d..78d5594332159 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" + "code.gitea.io/gitea/services/notify" pull_service "code.gitea.io/gitea/services/pull" ) @@ -31,20 +31,20 @@ func CreateRepository(ctx context.Context, doer, owner *user_model.User, opts re return nil, err } - notification.NotifyCreateRepository(ctx, doer, owner, repo) + notify.CreateRepository(ctx, 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... - notification.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 42174d095b035..7f8cf3d661ddc 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 @@ -101,7 +101,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ return nil, err } - notification.NotifyCreateRepository(ctx, doer, owner, generateRepo) + notify.CreateRepository(ctx, doer, owner, generateRepo) return generateRepo, nil } diff --git a/services/repository/transfer.go b/services/repository/transfer.go index b9b26f314c2c3..81bff3709499e 100644 --- a/services/repository/transfer.go +++ b/services/repository/transfer.go @@ -14,9 +14,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 @@ -54,7 +54,7 @@ func TransferOwnership(ctx context.Context, doer, newOwner *user_model.User, rep } } - notification.NotifyTransferRepository(ctx, doer, repo, oldOwner.Name) + notify.TransferRepository(ctx, doer, repo, oldOwner.Name) return nil } @@ -77,7 +77,7 @@ func ChangeRepositoryName(ctx context.Context, doer *user_model.User, repo *repo repoWorkingPool.CheckOut(fmt.Sprint(repo.ID)) repo.Name = newRepoName - notification.NotifyRenameRepository(ctx, doer, repo, oldRepoName) + notify.RenameRepository(ctx, doer, repo, oldRepoName) return nil } @@ -126,7 +126,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.RepoPendingTransfer(ctx, doer, newOwner, repo) return nil } diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go index 1299e66be2781..eff2197002a8e 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,14 @@ 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}) diff --git a/services/task/migrate.go b/services/task/migrate.go index 03d083e596674..97f54d32f0354 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.MigrateRepository(db.DefaultContext, t.Doer, t.Owner, t.Repo) return } diff --git a/modules/notification/ui/ui.go b/services/uinotification/notifier.go similarity index 69% rename from modules/notification/ui/ui.go rename to services/uinotification/notifier.go index 73ea9227482ff..8d9b559ec6491 100644 --- a/modules/notification/ui/ui.go +++ b/services/uinotification/notifier.go @@ -1,7 +1,7 @@ // Copyright 2018 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package ui +package uinotification import ( "context" @@ -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/base" "code.gitea.io/gitea/modules/queue" + "code.gitea.io/gitea/services/notify" ) type ( notificationService struct { - base.NullNotifier + notify.NullNotifier issueQueue queue.Queue } @@ -32,15 +32,20 @@ type ( } ) -var _ base.Notifier = ¬ificationService{} +var _ notify.Notifier = ¬ificationService{} // NewNotifier create a new notificationService notifier -func NewNotifier() base.Notifier { +func NewNotifier() notify.Notifier { ns := ¬ificationService{} ns.issueQueue = queue.CreateQueue("notification-service", ns.handle, issueNotificationOpts{}) return ns } +// Init initializes notification service, we need to create queue so don't run RegisterNotifier in init +func Init() { + notify.RegisterNotifier(NewNotifier()) +} + func (ns *notificationService) handle(data ...queue.Data) []queue.Data { for _, datum := range data { opts := datum.(issueNotificationOpts) @@ -55,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{ @@ -79,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, @@ -93,7 +98,7 @@ func (ns *notificationService) NotifyNewIssue(ctx context.Context, issue *issues } } -func (ns *notificationService) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { +func (ns *notificationService) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { _ = ns.issueQueue.Push(issueNotificationOpts{ IssueID: issue.ID, NotificationAuthorID: doer.ID, @@ -101,7 +106,7 @@ func (ns *notificationService) NotifyIssueChangeStatus(ctx context.Context, doer }) } -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 @@ -114,18 +119,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 @@ -160,7 +165,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, @@ -182,7 +187,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, @@ -193,7 +198,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, @@ -202,7 +207,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, @@ -211,7 +216,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, @@ -227,7 +232,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, @@ -243,7 +248,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.WithTx(ctx, func(ctx context.Context) error { return activities_model.CreateRepoTransferNotification(ctx, doer, newOwner, repo) }) 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 1f7cb8d988a38..9895e5da660c1 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -15,31 +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/notification/base" "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{}) -} - type webhookNotifier struct { - base.NullNotifier + notify.NullNotifier } -var _ base.Notifier = &webhookNotifier{} +var _ notify.Notifier = &webhookNotifier{} // NewNotifier create a new webhookNotifier notifier -func NewNotifier() base.Notifier { +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 @@ -79,7 +74,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) @@ -107,7 +102,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, @@ -119,7 +114,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), @@ -130,7 +125,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, @@ -142,7 +137,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 +182,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 { @@ -227,7 +222,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user } } -func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) { +func (m *webhookNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, 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 { @@ -269,7 +264,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 @@ -291,7 +286,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 @@ -317,7 +312,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 @@ -361,7 +356,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 @@ -401,7 +396,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 @@ -424,7 +419,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 { @@ -461,7 +456,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, @@ -474,7 +469,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, @@ -487,7 +482,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, @@ -499,7 +494,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 @@ -545,7 +540,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 { @@ -587,7 +582,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(ctx, pusher, nil) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL()) if err != nil { @@ -611,12 +606,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) @@ -653,7 +648,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 @@ -678,7 +673,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 { @@ -719,7 +714,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(ctx, pusher, nil) apiRepo := convert.ToRepo(ctx, repo, perm.AccessModeNone) refName := git.RefEndName(refFullName) @@ -735,7 +730,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 @@ -756,7 +751,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(ctx, pusher, nil) apiRepo := convert.ToRepo(ctx, repo, perm.AccessModeNone) refName := git.RefEndName(refFullName) @@ -789,19 +784,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(ctx, pusher, nil) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL()) if err != nil { @@ -825,19 +820,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) } 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 b286f37bf83e2..a508da3ace32a 100644 --- a/tests/mysql.ini.tmpl +++ b/tests/mysql.ini.tmpl @@ -63,14 +63,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 15349aa4c217c..3b53639eed058 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