1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-22 17:34:03 +03:00

Move notification interface to services layer (#26915)

Extract from #22266
This commit is contained in:
Lunny Xiao 2023-09-06 02:37:47 +08:00 committed by GitHub
parent 084eacb5d4
commit 540bf9fa6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 972 additions and 969 deletions

View File

@ -1,67 +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/git"
"code.gitea.io/gitea/modules/repository"
)
// Notifier defines an interface to notify receiver
type Notifier interface {
Run()
NotifyAdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository)
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)
NotifyPullRequestReviewRequest(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, refFullName git.RefName, refID string)
NotifyDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName)
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, refFullName git.RefName, refID string)
NotifySyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName)
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)
}

View File

@ -1,206 +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/git"
"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) {
}
// NotifyPullRequestReviewRequest places a place holder function
func (*NullNotifier) NotifyPullRequestReviewRequest(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) {
}
// NotifyAdoptRepository places a place holder function
func (*NullNotifier) NotifyAdoptRepository(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, refFullName git.RefName, refID string) {
}
// NotifyDeleteRef notifies branch or tag deletion to notifiers
func (*NullNotifier) NotifyDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
}
// 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, refFullName git.RefName, refID string) {
}
// NotifySyncDeleteRef places a place holder function
func (*NullNotifier) NotifySyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
}
// 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) {
}

View File

@ -1,363 +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/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository"
)
var notifiers []base.Notifier
// RegisterNotifier providers method to receive notify messages
func RegisterNotifier(notifier base.Notifier) {
go notifier.Run()
notifiers = append(notifiers, notifier)
}
// NotifyNewWikiPage notifies creating new wiki pages to notifiers
func NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
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)
}
}
// NotifyPullRequestReviewRequest notifies Request Review change
func NotifyPullRequestReviewRequest(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.NotifyPullRequestReviewRequest(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)
}
}
// NotifyAdoptRepository notifies the adoption of a repository to notifiers
func NotifyAdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
for _, notifier := range notifiers {
notifier.NotifyAdoptRepository(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, refFullName git.RefName, refID string) {
for _, notifier := range notifiers {
notifier.NotifyCreateRef(ctx, pusher, repo, refFullName, refID)
}
}
// NotifyDeleteRef notifies branch or tag deletion to notifiers
func NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
for _, notifier := range notifiers {
notifier.NotifyDeleteRef(ctx, pusher, repo, 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, refFullName git.RefName, refID string) {
for _, notifier := range notifiers {
notifier.NotifySyncCreateRef(ctx, pusher, repo, refFullName, refID)
}
}
// NotifySyncDeleteRef notifies branch or tag deletion to notifiers
func NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
for _, notifier := range notifiers {
notifier.NotifySyncDeleteRef(ctx, pusher, repo, 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)
}
}

View File

@ -18,11 +18,11 @@ import (
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
conan_module "code.gitea.io/gitea/modules/packages/conan" conan_module "code.gitea.io/gitea/modules/packages/conan"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/api/packages/helper" "code.gitea.io/gitea/routers/api/packages/helper"
notify_service "code.gitea.io/gitea/services/notify"
packages_service "code.gitea.io/gitea/services/packages" packages_service "code.gitea.io/gitea/services/packages"
) )
@ -663,7 +663,7 @@ func deleteRecipeOrPackage(apictx *context.Context, rref *conan_module.RecipeRef
} }
if versionDeleted { if versionDeleted {
notification.NotifyPackageDelete(apictx, apictx.Doer, pd) notify_service.PackageDelete(apictx, apictx.Doer, pd)
} }
return nil return nil

View File

@ -17,10 +17,10 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
container_module "code.gitea.io/gitea/modules/packages/container" container_module "code.gitea.io/gitea/modules/packages/container"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify"
packages_service "code.gitea.io/gitea/services/packages" packages_service "code.gitea.io/gitea/services/packages"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
@ -306,7 +306,7 @@ func notifyPackageCreate(ctx context.Context, doer *user_model.User, pv *package
return err return err
} }
notification.NotifyPackageCreate(ctx, doer, pd) notify_service.PackageCreate(ctx, doer, pd)
return nil return nil
} }

View File

@ -14,11 +14,11 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/notification"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
debian_module "code.gitea.io/gitea/modules/packages/debian" debian_module "code.gitea.io/gitea/modules/packages/debian"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/api/packages/helper" "code.gitea.io/gitea/routers/api/packages/helper"
notify_service "code.gitea.io/gitea/services/notify"
packages_service "code.gitea.io/gitea/services/packages" packages_service "code.gitea.io/gitea/services/packages"
debian_service "code.gitea.io/gitea/services/packages/debian" debian_service "code.gitea.io/gitea/services/packages/debian"
) )
@ -296,7 +296,7 @@ func DeletePackageFile(ctx *context.Context) {
} }
if pd != nil { if pd != nil {
notification.NotifyPackageDelete(ctx, ctx.Doer, pd) notify_service.PackageDelete(ctx, ctx.Doer, pd)
} }
if err := debian_service.BuildSpecificRepositoryFiles(ctx, ctx.Package.Owner.ID, distribution, component, architecture); err != nil { if err := debian_service.BuildSpecificRepositoryFiles(ctx, ctx.Package.Owner.ID, distribution, component, architecture); err != nil {

View File

@ -15,12 +15,12 @@ import (
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/notification"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
rpm_module "code.gitea.io/gitea/modules/packages/rpm" rpm_module "code.gitea.io/gitea/modules/packages/rpm"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/api/packages/helper" "code.gitea.io/gitea/routers/api/packages/helper"
notify_service "code.gitea.io/gitea/services/notify"
packages_service "code.gitea.io/gitea/services/packages" packages_service "code.gitea.io/gitea/services/packages"
rpm_service "code.gitea.io/gitea/services/packages/rpm" rpm_service "code.gitea.io/gitea/services/packages/rpm"
) )
@ -247,7 +247,7 @@ func DeletePackageFile(webctx *context.Context) {
} }
if pd != nil { if pd != nil {
notification.NotifyPackageDelete(webctx, webctx.Doer, pd) notify_service.PackageDelete(webctx, webctx.Doer, pd)
} }
if err := rpm_service.BuildRepositoryFiles(webctx, webctx.Package.Owner.ID); err != nil { if err := rpm_service.BuildRepositoryFiles(webctx, webctx.Package.Owner.ID); err != nil {

View File

@ -20,7 +20,6 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
issue_indexer "code.gitea.io/gitea/modules/indexer/issues" issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
@ -29,6 +28,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/convert"
issue_service "code.gitea.io/gitea/services/issue" issue_service "code.gitea.io/gitea/services/issue"
notify_service "code.gitea.io/gitea/services/notify"
) )
// SearchIssues searches for issues across the repositories that the user has access to // SearchIssues searches for issues across the repositories that the user has access to
@ -859,11 +859,11 @@ func EditIssue(ctx *context.APIContext) {
} }
if titleChanged { if titleChanged {
notification.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) notify_service.IssueChangeTitle(ctx, ctx.Doer, issue, oldTitle)
} }
if statusChangeComment != nil { if statusChangeComment != nil {
notification.NotifyIssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed) notify_service.IssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed)
} }
// Refetch from database to assign some automatic values // Refetch from database to assign some automatic values

View File

@ -22,7 +22,6 @@ import (
"code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration" base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
@ -31,6 +30,7 @@ import (
"code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/convert"
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/migrations" "code.gitea.io/gitea/services/migrations"
notify_service "code.gitea.io/gitea/services/notify"
) )
// Migrate migrate remote git repository to gitea // Migrate migrate remote git repository to gitea
@ -195,7 +195,7 @@ func Migrate(ctx *context.APIContext) {
} }
if err == nil { if err == nil {
notification.NotifyMigrateRepository(ctx, ctx.Doer, repoOwner, repo) notify_service.MigrateRepository(ctx, ctx.Doer, repoOwner, repo)
return return
} }

View File

@ -24,7 +24,6 @@ import (
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
@ -36,6 +35,7 @@ import (
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/gitdiff" "code.gitea.io/gitea/services/gitdiff"
issue_service "code.gitea.io/gitea/services/issue" issue_service "code.gitea.io/gitea/services/issue"
notify_service "code.gitea.io/gitea/services/notify"
pull_service "code.gitea.io/gitea/services/pull" pull_service "code.gitea.io/gitea/services/pull"
repo_service "code.gitea.io/gitea/services/repository" repo_service "code.gitea.io/gitea/services/repository"
) )
@ -594,11 +594,11 @@ func EditPullRequest(ctx *context.APIContext) {
} }
if titleChanged { if titleChanged {
notification.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle) notify_service.IssueChangeTitle(ctx, ctx.Doer, issue, oldTitle)
} }
if statusChangeComment != nil { if statusChangeComment != nil {
notification.NotifyIssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed) notify_service.IssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed)
} }
// change pull target branch // change pull target branch
@ -622,7 +622,7 @@ func EditPullRequest(ctx *context.APIContext) {
} }
return return
} }
notification.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base) notify_service.PullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base)
} }
// update allow edits // update allow edits

View File

@ -12,12 +12,12 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/convert"
notify_service "code.gitea.io/gitea/services/notify"
wiki_service "code.gitea.io/gitea/services/wiki" wiki_service "code.gitea.io/gitea/services/wiki"
) )
@ -85,7 +85,7 @@ func NewWikiPage(ctx *context.APIContext) {
wikiPage := getWikiPage(ctx, wikiName) wikiPage := getWikiPage(ctx, wikiName)
if !ctx.Written() { if !ctx.Written() {
notification.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName), form.Message) notify_service.NewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName), form.Message)
ctx.JSON(http.StatusCreated, wikiPage) ctx.JSON(http.StatusCreated, wikiPage)
} }
} }
@ -153,7 +153,7 @@ func EditWikiPage(ctx *context.APIContext) {
wikiPage := getWikiPage(ctx, newWikiName) wikiPage := getWikiPage(ctx, newWikiName)
if !ctx.Written() { if !ctx.Written() {
notification.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(newWikiName), form.Message) notify_service.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(newWikiName), form.Message)
ctx.JSON(http.StatusOK, wikiPage) ctx.JSON(http.StatusOK, wikiPage)
} }
} }
@ -242,7 +242,7 @@ func DeleteWikiPage(ctx *context.APIContext) {
return return
} }
notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName)) notify_service.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName))
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusNoContent)
} }

View File

@ -31,7 +31,6 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
issue_template "code.gitea.io/gitea/modules/issue/template" issue_template "code.gitea.io/gitea/modules/issue/template"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/upload" "code.gitea.io/gitea/modules/upload"
@ -42,6 +41,7 @@ import (
"code.gitea.io/gitea/services/automerge" "code.gitea.io/gitea/services/automerge"
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/gitdiff" "code.gitea.io/gitea/services/gitdiff"
notify_service "code.gitea.io/gitea/services/notify"
pull_service "code.gitea.io/gitea/services/pull" pull_service "code.gitea.io/gitea/services/pull"
repo_service "code.gitea.io/gitea/services/repository" repo_service "code.gitea.io/gitea/services/repository"
@ -1672,7 +1672,7 @@ func UpdatePullRequestTarget(ctx *context.Context) {
} }
return return
} }
notification.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, targetBranch) notify_service.PullRequestChangeTargetBranch(ctx, ctx.Doer, pr, targetBranch)
ctx.JSON(http.StatusOK, map[string]any{ ctx.JSON(http.StatusOK, map[string]any{
"base_branch": pr.BaseBranch, "base_branch": pr.BaseBranch,

View File

@ -23,13 +23,13 @@ import (
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/common" "code.gitea.io/gitea/routers/common"
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
notify_service "code.gitea.io/gitea/services/notify"
wiki_service "code.gitea.io/gitea/services/wiki" wiki_service "code.gitea.io/gitea/services/wiki"
) )
@ -727,7 +727,7 @@ func NewWikiPost(ctx *context.Context) {
return return
} }
notification.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName), form.Message) notify_service.NewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName), form.Message)
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.WebPathToURLPath(wikiName)) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.WebPathToURLPath(wikiName))
} }
@ -771,7 +771,7 @@ func EditWikiPost(ctx *context.Context) {
return return
} }
notification.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(newWikiName), form.Message) notify_service.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(newWikiName), form.Message)
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.WebPathToURLPath(newWikiName)) ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.WebPathToURLPath(newWikiName))
} }
@ -788,7 +788,7 @@ func DeleteWikiPagePost(ctx *context.Context) {
return return
} }
notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName)) notify_service.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName))
ctx.JSONRedirect(ctx.Repo.RepoLink + "/wiki/") ctx.JSONRedirect(ctx.Repo.RepoLink + "/wiki/")
} }

View File

@ -6,9 +6,9 @@ package actions
import ( import (
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/queue"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
notify_service "code.gitea.io/gitea/services/notify"
) )
func Init() { func Init() {
@ -22,5 +22,5 @@ func Init() {
} }
go graceful.GetManager().RunWithCancel(jobEmitterQueue) go graceful.GetManager().RunWithCancel(jobEmitterQueue)
notification.RegisterNotifier(NewNotifier()) notify_service.RegisterNotifier(NewNotifier())
} }

View File

@ -15,28 +15,28 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
webhook_module "code.gitea.io/gitea/modules/webhook" webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/convert"
notify_service "code.gitea.io/gitea/services/notify"
) )
type actionsNotifier struct { type actionsNotifier struct {
base.NullNotifier notify_service.NullNotifier
} }
var _ base.Notifier = &actionsNotifier{} var _ notify_service.Notifier = &actionsNotifier{}
// NewNotifier create a new actionsNotifier notifier // NewNotifier create a new actionsNotifier notifier
func NewNotifier() base.Notifier { func NewNotifier() notify_service.Notifier {
return &actionsNotifier{} return &actionsNotifier{}
} }
// NotifyNewIssue notifies issue created event // NewIssue notifies issue created event
func (n *actionsNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, _ []*user_model.User) { func (n *actionsNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, _ []*user_model.User) {
ctx = withMethod(ctx, "NotifyNewIssue") ctx = withMethod(ctx, "NewIssue")
if err := issue.LoadRepo(ctx); err != nil { if err := issue.LoadRepo(ctx); err != nil {
log.Error("issue.LoadRepo: %v", err) log.Error("issue.LoadRepo: %v", err)
return return
@ -53,12 +53,12 @@ func (n *actionsNotifier) NotifyNewIssue(ctx context.Context, issue *issues_mode
Issue: convert.ToAPIIssue(ctx, issue), Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(ctx, issue.Repo, permission), Repository: convert.ToRepo(ctx, issue.Repo, permission),
Sender: convert.ToUser(ctx, issue.Poster, nil), Sender: convert.ToUser(ctx, issue.Poster, nil),
}).Notify(withMethod(ctx, "NotifyNewIssue")) }).Notify(withMethod(ctx, "NewIssue"))
} }
// NotifyIssueChangeStatus notifies close or reopen issue to notifiers // IssueChangeStatus notifies close or reopen issue to notifiers
func (n *actionsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, _ *issues_model.Comment, isClosed bool) { func (n *actionsNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, _ *issues_model.Comment, isClosed bool) {
ctx = withMethod(ctx, "NotifyIssueChangeStatus") ctx = withMethod(ctx, "IssueChangeStatus")
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster) permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster)
if issue.IsPull { if issue.IsPull {
if err := issue.LoadPullRequest(ctx); err != nil { if err := issue.LoadPullRequest(ctx); err != nil {
@ -102,10 +102,10 @@ func (n *actionsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
Notify(ctx) Notify(ctx)
} }
func (n *actionsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, func (n *actionsNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
_, _ []*issues_model.Label, _, _ []*issues_model.Label,
) { ) {
ctx = withMethod(ctx, "NotifyIssueChangeLabels") ctx = withMethod(ctx, "IssueChangeLabels")
var err error var err error
if err = issue.LoadRepo(ctx); err != nil { if err = issue.LoadRepo(ctx); err != nil {
@ -153,11 +153,11 @@ func (n *actionsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use
Notify(ctx) Notify(ctx)
} }
// NotifyCreateIssueComment notifies comment on an issue to notifiers // CreateIssueComment notifies comment on an issue to notifiers
func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, func (n *actionsNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, _ []*user_model.User, issue *issues_model.Issue, comment *issues_model.Comment, _ []*user_model.User,
) { ) {
ctx = withMethod(ctx, "NotifyCreateIssueComment") ctx = withMethod(ctx, "CreateIssueComment")
permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer) permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer)
@ -193,8 +193,8 @@ func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us
Notify(ctx) Notify(ctx)
} }
func (n *actionsNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_model.PullRequest, _ []*user_model.User) { func (n *actionsNotifier) NewPullRequest(ctx context.Context, pull *issues_model.PullRequest, _ []*user_model.User) {
ctx = withMethod(ctx, "NotifyNewPullRequest") ctx = withMethod(ctx, "NewPullRequest")
if err := pull.LoadIssue(ctx); err != nil { if err := pull.LoadIssue(ctx); err != nil {
log.Error("pull.LoadIssue: %v", err) log.Error("pull.LoadIssue: %v", err)
@ -223,8 +223,8 @@ func (n *actionsNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues
Notify(ctx) Notify(ctx)
} }
func (n *actionsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { func (n *actionsNotifier) CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
ctx = withMethod(ctx, "NotifyCreateRepository") ctx = withMethod(ctx, "CreateRepository")
newNotifyInput(repo, doer, webhook_module.HookEventRepository).WithPayload(&api.RepositoryPayload{ newNotifyInput(repo, doer, webhook_module.HookEventRepository).WithPayload(&api.RepositoryPayload{
Action: api.HookRepoCreated, Action: api.HookRepoCreated,
@ -234,8 +234,8 @@ func (n *actionsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *u
}).Notify(ctx) }).Notify(ctx)
} }
func (n *actionsNotifier) NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) { func (n *actionsNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
ctx = withMethod(ctx, "NotifyForkRepository") ctx = withMethod(ctx, "ForkRepository")
oldPermission, _ := access_model.GetUserRepoPermission(ctx, oldRepo, doer) oldPermission, _ := access_model.GetUserRepoPermission(ctx, oldRepo, doer)
permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer) permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer)
@ -262,8 +262,8 @@ func (n *actionsNotifier) NotifyForkRepository(ctx context.Context, doer *user_m
} }
} }
func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, _ *issues_model.Comment, _ []*user_model.User) { func (n *actionsNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, _ *issues_model.Comment, _ []*user_model.User) {
ctx = withMethod(ctx, "NotifyPullRequestReview") ctx = withMethod(ctx, "PullRequestReview")
var reviewHookType webhook_module.HookEventType var reviewHookType webhook_module.HookEventType
@ -306,8 +306,8 @@ func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issue
}).Notify(ctx) }).Notify(ctx)
} }
func (*actionsNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { func (*actionsNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
ctx = withMethod(ctx, "NotifyMergePullRequest") ctx = withMethod(ctx, "MergePullRequest")
// Reload pull request information. // Reload pull request information.
if err := pr.LoadAttributes(ctx); err != nil { if err := pr.LoadAttributes(ctx); err != nil {
@ -347,8 +347,8 @@ func (*actionsNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_m
Notify(ctx) Notify(ctx)
} }
func (n *actionsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { func (n *actionsNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
ctx = withMethod(ctx, "NotifyPushCommits") ctx = withMethod(ctx, "PushCommits")
apiPusher := convert.ToUser(ctx, pusher, nil) apiPusher := convert.ToUser(ctx, pusher, nil)
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL()) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
@ -373,8 +373,8 @@ func (n *actionsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_mo
Notify(ctx) Notify(ctx)
} }
func (n *actionsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) { func (n *actionsNotifier) CreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
ctx = withMethod(ctx, "NotifyCreateRef") ctx = withMethod(ctx, "CreateRef")
apiPusher := convert.ToUser(ctx, pusher, nil) apiPusher := convert.ToUser(ctx, pusher, nil)
apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeNone}) apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeNone})
@ -391,8 +391,8 @@ func (n *actionsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_mode
Notify(ctx) Notify(ctx)
} }
func (n *actionsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) { func (n *actionsNotifier) DeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
ctx = withMethod(ctx, "NotifyDeleteRef") ctx = withMethod(ctx, "DeleteRef")
apiPusher := convert.ToUser(ctx, pusher, nil) apiPusher := convert.ToUser(ctx, pusher, nil)
apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeNone}) apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeNone})
@ -409,8 +409,8 @@ func (n *actionsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_mode
Notify(ctx) Notify(ctx)
} }
func (n *actionsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { func (n *actionsNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
ctx = withMethod(ctx, "NotifySyncPushCommits") ctx = withMethod(ctx, "SyncPushCommits")
apiPusher := convert.ToUser(ctx, pusher, nil) apiPusher := convert.ToUser(ctx, pusher, nil)
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(db.DefaultContext, repo.RepoPath(), repo.HTMLURL()) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(db.DefaultContext, repo.RepoPath(), repo.HTMLURL())
@ -436,48 +436,48 @@ func (n *actionsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *use
Notify(ctx) Notify(ctx)
} }
func (n *actionsNotifier) NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) { func (n *actionsNotifier) SyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
ctx = withMethod(ctx, "NotifySyncCreateRef") ctx = withMethod(ctx, "SyncCreateRef")
n.NotifyCreateRef(ctx, pusher, repo, refFullName, refID) n.CreateRef(ctx, pusher, repo, refFullName, refID)
} }
func (n *actionsNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) { func (n *actionsNotifier) SyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
ctx = withMethod(ctx, "NotifySyncDeleteRef") ctx = withMethod(ctx, "SyncDeleteRef")
n.NotifyDeleteRef(ctx, pusher, repo, refFullName) n.DeleteRef(ctx, pusher, repo, refFullName)
} }
func (n *actionsNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) { func (n *actionsNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) {
ctx = withMethod(ctx, "NotifyNewRelease") ctx = withMethod(ctx, "NewRelease")
notifyRelease(ctx, rel.Publisher, rel, api.HookReleasePublished) notifyRelease(ctx, rel.Publisher, rel, api.HookReleasePublished)
} }
func (n *actionsNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { func (n *actionsNotifier) UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
ctx = withMethod(ctx, "NotifyUpdateRelease") ctx = withMethod(ctx, "UpdateRelease")
notifyRelease(ctx, doer, rel, api.HookReleaseUpdated) notifyRelease(ctx, doer, rel, api.HookReleaseUpdated)
} }
func (n *actionsNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { func (n *actionsNotifier) DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
ctx = withMethod(ctx, "NotifyDeleteRelease") ctx = withMethod(ctx, "DeleteRelease")
notifyRelease(ctx, doer, rel, api.HookReleaseDeleted) notifyRelease(ctx, doer, rel, api.HookReleaseDeleted)
} }
func (n *actionsNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { func (n *actionsNotifier) PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
ctx = withMethod(ctx, "NotifyPackageCreate") ctx = withMethod(ctx, "PackageCreate")
notifyPackage(ctx, doer, pd, api.HookPackageCreated) notifyPackage(ctx, doer, pd, api.HookPackageCreated)
} }
func (n *actionsNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { func (n *actionsNotifier) PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
ctx = withMethod(ctx, "NotifyPackageDelete") ctx = withMethod(ctx, "PackageDelete")
notifyPackage(ctx, doer, pd, api.HookPackageDeleted) notifyPackage(ctx, doer, pd, api.HookPackageDeleted)
} }
func (n *actionsNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { func (n *actionsNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
ctx = withMethod(ctx, "NotifyAutoMergePullRequest") ctx = withMethod(ctx, "AutoMergePullRequest")
n.NotifyMergePullRequest(ctx, doer, pr) n.MergePullRequest(ctx, doer, pr)
} }
func (n *actionsNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { func (n *actionsNotifier) PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
ctx = withMethod(ctx, "NotifyPullRequestSynchronized") ctx = withMethod(ctx, "PullRequestSynchronized")
if err := pr.LoadIssue(ctx); err != nil { if err := pr.LoadIssue(ctx); err != nil {
log.Error("LoadAttributes: %v", err) log.Error("LoadAttributes: %v", err)
@ -501,8 +501,8 @@ func (n *actionsNotifier) NotifyPullRequestSynchronized(ctx context.Context, doe
Notify(ctx) Notify(ctx)
} }
func (n *actionsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) { func (n *actionsNotifier) PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
ctx = withMethod(ctx, "NotifyPullRequestChangeTargetBranch") ctx = withMethod(ctx, "PullRequestChangeTargetBranch")
if err := pr.LoadIssue(ctx); err != nil { if err := pr.LoadIssue(ctx); err != nil {
log.Error("LoadAttributes: %v", err) log.Error("LoadAttributes: %v", err)
@ -532,8 +532,8 @@ func (n *actionsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Contex
Notify(ctx) Notify(ctx)
} }
func (n *actionsNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { func (n *actionsNotifier) NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
ctx = withMethod(ctx, "NotifyNewWikiPage") ctx = withMethod(ctx, "NewWikiPage")
newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{ newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
Action: api.HookWikiCreated, Action: api.HookWikiCreated,
@ -544,8 +544,8 @@ func (n *actionsNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_mode
}).Notify(ctx) }).Notify(ctx)
} }
func (n *actionsNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { func (n *actionsNotifier) EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
ctx = withMethod(ctx, "NotifyEditWikiPage") ctx = withMethod(ctx, "EditWikiPage")
newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{ newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
Action: api.HookWikiEdited, Action: api.HookWikiEdited,
@ -556,8 +556,8 @@ func (n *actionsNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_mod
}).Notify(ctx) }).Notify(ctx)
} }
func (n *actionsNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) { func (n *actionsNotifier) DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
ctx = withMethod(ctx, "NotifyDeleteWikiPage") ctx = withMethod(ctx, "DeleteWikiPage")
newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{ newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
Action: api.HookWikiDeleted, Action: api.HookWikiDeleted,

View File

@ -14,8 +14,8 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/private" "code.gitea.io/gitea/modules/private"
notify_service "code.gitea.io/gitea/services/notify"
pull_service "code.gitea.io/gitea/services/pull" 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]) comment, err := pull_service.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i])
if err == nil && comment != nil { if err == nil && comment != nil {
notification.NotifyPullRequestPushCommits(ctx, pusher, pr, comment) notify_service.PullRequestPushCommits(ctx, pusher, pr, comment)
} }
notification.NotifyPullRequestSynchronized(ctx, pusher, pr) notify_service.PullRequestSynchronized(ctx, pusher, pr)
isForcePush := comment != nil && comment.IsForcePush isForcePush := comment != nil && comment.IsForcePush
results = append(results, private.HookProcReceiveRefResult{ results = append(results, private.HookProcReceiveRefResult{

View File

@ -16,30 +16,29 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify"
) )
type actionNotifier struct { type actionNotifier struct {
base.NullNotifier notify_service.NullNotifier
} }
var _ base.Notifier = &actionNotifier{} var _ notify_service.Notifier = &actionNotifier{}
func Init() error { func Init() error {
notification.RegisterNotifier(NewNotifier()) notify_service.RegisterNotifier(NewNotifier())
return nil return nil
} }
// NewNotifier create a new actionNotifier notifier // NewNotifier create a new actionNotifier notifier
func NewNotifier() base.Notifier { func NewNotifier() notify_service.Notifier {
return &actionNotifier{} return &actionNotifier{}
} }
func (a *actionNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { func (a *actionNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
if err := issue.LoadPoster(ctx); err != nil { if err := issue.LoadPoster(ctx); err != nil {
log.Error("issue.LoadPoster: %v", err) log.Error("issue.LoadPoster: %v", err)
return return
@ -63,8 +62,8 @@ func (a *actionNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model
} }
} }
// NotifyIssueChangeStatus notifies close or reopen issue to notifiers // IssueChangeStatus 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) { 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. // 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. // This object will be used to notify watchers in the end of function.
act := &activities_model.Action{ act := &activities_model.Action{
@ -96,8 +95,8 @@ func (a *actionNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user
} }
} }
// NotifyCreateIssueComment notifies comment on an issue to notifiers // CreateIssueComment notifies comment on an issue to notifiers
func (a *actionNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, 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, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) { ) {
act := &activities_model.Action{ act := &activities_model.Action{
@ -132,7 +131,7 @@ func (a *actionNotifier) NotifyCreateIssueComment(ctx context.Context, doer *use
} }
} }
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 { if err := pull.LoadIssue(ctx); err != nil {
log.Error("pull.LoadIssue: %v", err) log.Error("pull.LoadIssue: %v", err)
return return
@ -159,7 +158,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{ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID, ActUserID: doer.ID,
ActUser: doer, ActUser: doer,
@ -173,7 +172,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{ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID, ActUserID: doer.ID,
ActUser: doer, ActUser: doer,
@ -187,7 +186,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{ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID, ActUserID: doer.ID,
ActUser: doer, ActUser: doer,
@ -200,7 +199,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{ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID, ActUserID: doer.ID,
ActUser: doer, ActUser: doer,
@ -213,7 +212,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 { if err := review.LoadReviewer(ctx); err != nil {
log.Error("LoadReviewer '%d/%d': %v", review.ID, review.ReviewerID, err) log.Error("LoadReviewer '%d/%d': %v", review.ID, review.ReviewerID, err)
return return
@ -271,7 +270,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{ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID, ActUserID: doer.ID,
ActUser: doer, ActUser: doer,
@ -285,7 +284,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{ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID, ActUserID: doer.ID,
ActUser: doer, ActUser: doer,
@ -319,7 +318,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) data, err := json.Marshal(commits)
if err != nil { if err != nil {
log.Error("Marshal: %v", err) log.Error("Marshal: %v", err)
@ -352,10 +351,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, refFullName git.RefName, refID string) { func (a *actionNotifier) CreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
opType := activities_model.ActionCommitRepo opType := activities_model.ActionCommitRepo
if refFullName.IsTag() { if refFullName.IsTag() {
// has sent same action in `NotifyPushCommits`, so skip it. // has sent same action in `PushCommits`, so skip it.
return return
} }
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
@ -371,10 +370,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, refFullName git.RefName) { func (a *actionNotifier) DeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
opType := activities_model.ActionDeleteBranch opType := activities_model.ActionDeleteBranch
if refFullName.IsTag() { if refFullName.IsTag() {
// has sent same action in `NotifyPushCommits`, so skip it. // has sent same action in `PushCommits`, so skip it.
return return
} }
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
@ -390,7 +389,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) data, err := json.Marshal(commits)
if err != nil { if err != nil {
log.Error("json.Marshal: %v", err) log.Error("json.Marshal: %v", err)
@ -411,7 +410,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, refFullName git.RefName, refID string) { func (a *actionNotifier) SyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: repo.OwnerID, ActUserID: repo.OwnerID,
ActUser: repo.MustOwner(ctx), ActUser: repo.MustOwner(ctx),
@ -425,7 +424,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, refFullName git.RefName) { func (a *actionNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: repo.OwnerID, ActUserID: repo.OwnerID,
ActUser: repo.MustOwner(ctx), ActUser: repo.MustOwner(ctx),
@ -439,7 +438,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 { if err := rel.LoadAttributes(ctx); err != nil {
log.Error("LoadAttributes: %v", err) log.Error("LoadAttributes: %v", err)
return return

View File

@ -46,7 +46,7 @@ func TestRenameRepoAction(t *testing.T) {
} }
unittest.AssertNotExistsBean(t, actionBean) unittest.AssertNotExistsBean(t, actionBean)
NewNotifier().NotifyRenameRepository(db.DefaultContext, user, repo, oldRepoName) NewNotifier().RenameRepository(db.DefaultContext, user, repo, oldRepoName)
unittest.AssertExistsAndLoadBean(t, actionBean) unittest.AssertExistsAndLoadBean(t, actionBean)
unittest.CheckConsistencyFor(t, &activities_model.Action{}) unittest.CheckConsistencyFor(t, &activities_model.Action{})

View File

@ -7,12 +7,12 @@ import (
code_indexer "code.gitea.io/gitea/modules/indexer/code" code_indexer "code.gitea.io/gitea/modules/indexer/code"
issue_indexer "code.gitea.io/gitea/modules/indexer/issues" issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
stats_indexer "code.gitea.io/gitea/modules/indexer/stats" stats_indexer "code.gitea.io/gitea/modules/indexer/stats"
"code.gitea.io/gitea/modules/notification" notify_service "code.gitea.io/gitea/services/notify"
) )
// Init initialize the repo indexer // Init initialize the repo indexer
func Init() error { func Init() error {
notification.RegisterNotifier(NewNotifier()) notify_service.RegisterNotifier(NewNotifier())
issue_indexer.InitIssueIndexer(false) issue_indexer.InitIssueIndexer(false)
code_indexer.Init() code_indexer.Init()

View File

@ -13,37 +13,37 @@ import (
issue_indexer "code.gitea.io/gitea/modules/indexer/issues" issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
stats_indexer "code.gitea.io/gitea/modules/indexer/stats" stats_indexer "code.gitea.io/gitea/modules/indexer/stats"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
notify_service "code.gitea.io/gitea/services/notify"
) )
type indexerNotifier struct { type indexerNotifier struct {
base.NullNotifier notify_service.NullNotifier
} }
var _ base.Notifier = &indexerNotifier{} var _ notify_service.Notifier = &indexerNotifier{}
// NewNotifier create a new indexerNotifier notifier // NewNotifier create a new indexerNotifier notifier
func NewNotifier() base.Notifier { func NewNotifier() notify_service.Notifier {
return &indexerNotifier{} return &indexerNotifier{}
} }
func (r *indexerNotifier) NotifyAdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { func (r *indexerNotifier) AdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
r.NotifyMigrateRepository(ctx, doer, u, repo) r.MigrateRepository(ctx, doer, u, repo)
} }
func (r *indexerNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, func (r *indexerNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) { ) {
issue_indexer.UpdateIssueIndexer(issue.ID) issue_indexer.UpdateIssueIndexer(issue.ID)
} }
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.ID) issue_indexer.UpdateIssueIndexer(issue.ID)
} }
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) {
if err := pr.LoadIssue(ctx); err != nil { if err := pr.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err) log.Error("LoadIssue: %v", err)
return return
@ -51,7 +51,7 @@ func (r *indexerNotifier) NotifyNewPullRequest(ctx context.Context, pr *issues_m
issue_indexer.UpdateIssueIndexer(pr.Issue.ID) issue_indexer.UpdateIssueIndexer(pr.Issue.ID)
} }
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 err := c.LoadIssue(ctx); err != nil { if err := c.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err) log.Error("LoadIssue: %v", err)
return return
@ -59,7 +59,7 @@ func (r *indexerNotifier) NotifyUpdateComment(ctx context.Context, doer *user_mo
issue_indexer.UpdateIssueIndexer(c.Issue.ID) issue_indexer.UpdateIssueIndexer(c.Issue.ID)
} }
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 err := comment.LoadIssue(ctx); err != nil { if err := comment.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err) log.Error("LoadIssue: %v", err)
return return
@ -67,14 +67,14 @@ func (r *indexerNotifier) NotifyDeleteComment(ctx context.Context, doer *user_mo
issue_indexer.UpdateIssueIndexer(comment.Issue.ID) issue_indexer.UpdateIssueIndexer(comment.Issue.ID)
} }
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.ID) issue_indexer.DeleteRepoIssueIndexer(ctx, repo.ID)
if setting.Indexer.RepoIndexerEnabled { if setting.Indexer.RepoIndexerEnabled {
code_indexer.UpdateRepoIndexer(repo) 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.ID) issue_indexer.UpdateRepoIndexer(ctx, repo.ID)
if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty { if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty {
code_indexer.UpdateRepoIndexer(repo) code_indexer.UpdateRepoIndexer(repo)
@ -84,7 +84,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 !opts.RefFullName.IsBranch() { if !opts.RefFullName.IsBranch() {
return return
} }
@ -97,7 +97,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 !opts.RefFullName.IsBranch() { if !opts.RefFullName.IsBranch() {
return return
} }
@ -110,14 +110,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.ID) issue_indexer.UpdateIssueIndexer(issue.ID)
} }
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.ID) issue_indexer.UpdateIssueIndexer(issue.ID)
} }
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.ID) issue_indexer.UpdateIssueIndexer(issue.ID)
} }

View File

@ -13,7 +13,7 @@ import (
"code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification" notify_service "code.gitea.io/gitea/services/notify"
) )
// DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array // DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array
@ -54,7 +54,7 @@ func ToggleAssigneeWithNotify(ctx context.Context, issue *issues_model.Issue, do
return false, nil, err return false, nil, err
} }
notification.NotifyIssueChangeAssignee(ctx, doer, issue, assignee, removed, comment) notify_service.IssueChangeAssignee(ctx, doer, issue, assignee, removed, comment)
return removed, comment, err return removed, comment, err
} }
@ -72,7 +72,7 @@ func ReviewRequest(ctx context.Context, issue *issues_model.Issue, doer, reviewe
} }
if comment != nil { if comment != nil {
notification.NotifyPullRequestReviewRequest(ctx, doer, issue, reviewer, isAdd, comment) notify_service.PullRequestReviewRequest(ctx, doer, issue, reviewer, isAdd, comment)
} }
return comment, err return comment, err
@ -259,7 +259,7 @@ func TeamReviewRequest(ctx context.Context, issue *issues_model.Issue, doer *use
continue continue
} }
comment.AssigneeID = member.ID comment.AssigneeID = member.ID
notification.NotifyPullRequestReviewRequest(ctx, doer, issue, member, isAdd, comment) notify_service.PullRequestReviewRequest(ctx, doer, issue, member, isAdd, comment)
} }
return comment, err return comment, err

View File

@ -11,8 +11,8 @@ import (
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
notify_service "code.gitea.io/gitea/services/notify"
) )
// CreateRefComment creates a commit reference comment to issue. // CreateRefComment creates a commit reference comment to issue.
@ -63,7 +63,7 @@ func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_m
return nil, err return nil, err
} }
notification.NotifyCreateIssueComment(ctx, doer, repo, issue, comment, mentions) notify_service.CreateIssueComment(ctx, doer, repo, issue, comment, mentions)
return comment, nil return comment, nil
} }
@ -95,7 +95,7 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, doer *user_mode
} }
} }
notification.NotifyUpdateComment(ctx, doer, c, oldContent) notify_service.UpdateComment(ctx, doer, c, oldContent)
return nil return nil
} }
@ -109,7 +109,7 @@ func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_m
return err return err
} }
notification.NotifyDeleteComment(ctx, doer, comment) notify_service.DeleteComment(ctx, doer, comment)
return nil return nil
} }

View File

@ -7,7 +7,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification" notify_service "code.gitea.io/gitea/services/notify"
) )
// ChangeContent changes issue content, as the given user. // 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 return err
} }
notification.NotifyIssueChangeContent(db.DefaultContext, doer, issue, oldContent) notify_service.IssueChangeContent(db.DefaultContext, doer, issue, oldContent)
return nil return nil
} }

View File

@ -16,8 +16,8 @@ import (
system_model "code.gitea.io/gitea/models/system" system_model "code.gitea.io/gitea/models/system"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/storage"
notify_service "code.gitea.io/gitea/services/notify"
) )
// NewIssue creates new issue with labels for repository. // 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 return err
} }
notification.NotifyNewIssue(ctx, issue, mentions) notify_service.NewIssue(ctx, issue, mentions)
if len(issue.Labels) > 0 { if len(issue.Labels) > 0 {
notification.NotifyIssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil) notify_service.IssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil)
} }
if issue.Milestone != nil { if issue.Milestone != nil {
notification.NotifyIssueChangeMilestone(ctx, issue.Poster, issue, 0) notify_service.IssueChangeMilestone(ctx, issue.Poster, issue, 0)
} }
return nil return nil
@ -63,7 +63,7 @@ func ChangeTitle(ctx context.Context, issue *issues_model.Issue, doer *user_mode
} }
} }
notification.NotifyIssueChangeTitle(ctx, doer, issue, oldTitle) notify_service.IssueChangeTitle(ctx, doer, issue, oldTitle)
return nil return nil
} }
@ -77,7 +77,7 @@ func ChangeIssueRef(ctx context.Context, issue *issues_model.Issue, doer *user_m
return err return err
} }
notification.NotifyIssueChangeRef(ctx, doer, issue, oldRef) notify_service.IssueChangeRef(ctx, doer, issue, oldRef)
return nil return nil
} }
@ -166,7 +166,7 @@ func DeleteIssue(ctx context.Context, doer *user_model.User, gitRepo *git.Reposi
} }
} }
notification.NotifyDeleteIssue(ctx, doer, issue) notify_service.DeleteIssue(ctx, doer, issue)
return nil return nil
} }

View File

@ -8,7 +8,7 @@ import (
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access" access_model "code.gitea.io/gitea/models/perm/access"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification" notify_service "code.gitea.io/gitea/services/notify"
) )
// ClearLabels clears all of an issue's labels // ClearLabels clears all of an issue's labels
@ -17,7 +17,7 @@ func ClearLabels(issue *issues_model.Issue, doer *user_model.User) error {
return err return err
} }
notification.NotifyIssueClearLabels(db.DefaultContext, doer, issue) notify_service.IssueClearLabels(db.DefaultContext, doer, issue)
return nil return nil
} }
@ -28,7 +28,7 @@ func AddLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_mo
return err return err
} }
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, []*issues_model.Label{label}, nil) notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, []*issues_model.Label{label}, nil)
return nil return nil
} }
@ -38,7 +38,7 @@ func AddLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issue
return err return err
} }
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, nil) notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, labels, nil)
return nil return nil
} }
@ -73,7 +73,7 @@ func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues
return err return err
} }
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, nil, []*issues_model.Label{label}) notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, nil, []*issues_model.Label{label})
return nil return nil
} }
@ -88,6 +88,6 @@ func ReplaceLabels(issue *issues_model.Issue, doer *user_model.User, labels []*i
return err return err
} }
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, old) notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, labels, old)
return nil return nil
} }

View File

@ -10,7 +10,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification" notify_service "code.gitea.io/gitea/services/notify"
) )
func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) error { 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) return fmt.Errorf("Commit: %w", err)
} }
notification.NotifyIssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID) notify_service.IssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID)
return nil return nil
} }

View File

@ -9,7 +9,7 @@ import (
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification" notify_service "code.gitea.io/gitea/services/notify"
) )
// ChangeStatus changes issue status to open or closed. // ChangeStatus changes issue status to open or closed.
@ -30,7 +30,7 @@ func ChangeStatus(ctx context.Context, issue *issues_model.Issue, doer *user_mod
} }
} }
notification.NotifyIssueChangeStatus(ctx, doer, commitID, issue, comment, closed) notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, closed)
return nil return nil
} }

View File

@ -21,11 +21,11 @@ import (
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/queue"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/templates"
notify_service "code.gitea.io/gitea/services/notify"
ntlmssp "github.com/Azure/go-ntlmssp" ntlmssp "github.com/Azure/go-ntlmssp"
"github.com/jaytaylor/html2text" "github.com/jaytaylor/html2text"
@ -394,7 +394,7 @@ func NewContext(ctx context.Context) {
} }
if setting.Service.EnableNotifyMail { if setting.Service.EnableNotifyMail {
notification.RegisterNotifier(NewNotifier()) notify_service.RegisterNotifier(NewNotifier())
} }
switch setting.MailService.Protocol { switch setting.MailService.Protocol {

View File

@ -12,21 +12,21 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base" notify_service "code.gitea.io/gitea/services/notify"
) )
type mailNotifier struct { type mailNotifier struct {
base.NullNotifier notify_service.NullNotifier
} }
var _ base.Notifier = &mailNotifier{} var _ notify_service.Notifier = &mailNotifier{}
// NewNotifier create a new mailNotifier notifier // NewNotifier create a new mailNotifier notifier
func NewNotifier() base.Notifier { func NewNotifier() notify_service.Notifier {
return &mailNotifier{} 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, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) { ) {
var act activities_model.ActionType var act activities_model.ActionType
@ -47,13 +47,13 @@ func (m *mailNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_
} }
} }
func (m *mailNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) { func (m *mailNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
if err := MailParticipants(ctx, issue, issue.Poster, activities_model.ActionCreateIssue, mentions); err != nil { if err := MailParticipants(ctx, issue, issue.Poster, activities_model.ActionCreateIssue, mentions); err != nil {
log.Error("MailParticipants: %v", err) 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 var actionType activities_model.ActionType
if issue.IsPull { if issue.IsPull {
if isClosed { if isClosed {
@ -74,7 +74,7 @@ func (m *mailNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_m
} }
} }
func (m *mailNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) { func (m *mailNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
if err := issue.LoadPullRequest(ctx); err != nil { if err := issue.LoadPullRequest(ctx); err != nil {
log.Error("issue.LoadPullRequest: %v", err) log.Error("issue.LoadPullRequest: %v", err)
return return
@ -86,13 +86,13 @@ func (m *mailNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_mo
} }
} }
func (m *mailNotifier) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) { func (m *mailNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
if err := MailParticipants(ctx, pr.Issue, pr.Issue.Poster, activities_model.ActionCreatePullRequest, mentions); err != nil { if err := MailParticipants(ctx, pr.Issue, pr.Issue.Poster, activities_model.ActionCreatePullRequest, mentions); err != nil {
log.Error("MailParticipants: %v", err) 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 var act activities_model.ActionType
if comment.Type == issues_model.CommentTypeClose { if comment.Type == issues_model.CommentTypeClose {
act = activities_model.ActionCloseIssue act = activities_model.ActionCloseIssue
@ -106,13 +106,13 @@ func (m *mailNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_m
} }
} }
func (m *mailNotifier) NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) { func (m *mailNotifier) PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) {
if err := MailMentionsComment(ctx, pr, comment, mentions); err != nil { if err := MailMentionsComment(ctx, pr, comment, mentions); err != nil {
log.Error("MailMentionsComment: %v", err) 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 // mail only sent to added assignees and not self-assignee
if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() != user_model.EmailNotificationsDisabled { if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() != user_model.EmailNotificationsDisabled {
ct := fmt.Sprintf("Assigned #%d.", issue.Index) ct := fmt.Sprintf("Assigned #%d.", issue.Index)
@ -122,7 +122,7 @@ func (m *mailNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user
} }
} }
func (m *mailNotifier) NotifyPullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { func (m *mailNotifier) PullRequestReviewRequest(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 { if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() != user_model.EmailNotificationsDisabled {
ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL()) ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL())
if err := 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 {
@ -131,7 +131,7 @@ func (m *mailNotifier) NotifyPullRequestReviewRequest(ctx context.Context, doer
} }
} }
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 { if err := pr.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err) log.Error("LoadIssue: %v", err)
return return
@ -141,7 +141,7 @@ func (m *mailNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_mo
} }
} }
func (m *mailNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { func (m *mailNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
if err := pr.LoadIssue(ctx); err != nil { if err := pr.LoadIssue(ctx); err != nil {
log.Error("pr.LoadIssue: %v", err) log.Error("pr.LoadIssue: %v", err)
return return
@ -151,7 +151,7 @@ func (m *mailNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *use
} }
} }
func (m *mailNotifier) NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) { func (m *mailNotifier) PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
var err error var err error
if err = comment.LoadIssue(ctx); err != nil { if err = comment.LoadIssue(ctx); err != nil {
log.Error("comment.LoadIssue: %v", err) log.Error("comment.LoadIssue: %v", err)
@ -172,16 +172,16 @@ func (m *mailNotifier) NotifyPullRequestPushCommits(ctx context.Context, doer *u
if err := comment.LoadPushCommits(ctx); err != nil { if err := comment.LoadPushCommits(ctx); err != nil {
log.Error("comment.LoadPushCommits: %v", err) log.Error("comment.LoadPushCommits: %v", err)
} }
m.NotifyCreateIssueComment(ctx, doer, comment.Issue.Repo, comment.Issue, comment, nil) m.CreateIssueComment(ctx, doer, comment.Issue.Repo, comment.Issue, comment, nil)
} }
func (m *mailNotifier) NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) { func (m *mailNotifier) PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
if err := MailParticipantsComment(ctx, comment, activities_model.ActionPullReviewDismissed, review.Issue, nil); err != nil { if err := MailParticipantsComment(ctx, comment, activities_model.ActionPullReviewDismissed, review.Issue, nil); err != nil {
log.Error("MailParticipantsComment: %v", err) 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 { if err := rel.LoadAttributes(ctx); err != nil {
log.Error("LoadAttributes: %v", err) log.Error("LoadAttributes: %v", err)
return return
@ -194,7 +194,7 @@ func (m *mailNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Rel
MailNewRelease(ctx, rel) MailNewRelease(ctx, rel)
} }
func (m *mailNotifier) NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) { func (m *mailNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) {
if err := SendRepoTransferNotifyMail(ctx, doer, newOwner, repo); err != nil { if err := SendRepoTransferNotifyMail(ctx, doer, newOwner, repo); err != nil {
log.Error("SendRepoTransferNotifyMail: %v", err) log.Error("SendRepoTransferNotifyMail: %v", err)
} }

View File

@ -16,13 +16,13 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/proxy" "code.gitea.io/gitea/modules/proxy"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify"
) )
// gitShortEmptySha Git short empty SHA // gitShortEmptySha Git short empty SHA
@ -479,18 +479,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) log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err)
continue continue
} }
notification.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ notify_service.SyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{
RefFullName: result.refName, RefFullName: result.refName,
OldCommitID: git.EmptySHA, OldCommitID: git.EmptySHA,
NewCommitID: commitID, NewCommitID: commitID,
}, repo_module.NewPushCommits()) }, repo_module.NewPushCommits())
notification.NotifySyncCreateRef(ctx, m.Repo.MustOwner(ctx), m.Repo, result.refName, commitID) notify_service.SyncCreateRef(ctx, m.Repo.MustOwner(ctx), m.Repo, result.refName, commitID)
continue continue
} }
// Delete reference // Delete reference
if result.newCommitID == gitShortEmptySha { if result.newCommitID == gitShortEmptySha {
notification.NotifySyncDeleteRef(ctx, m.Repo.MustOwner(ctx), m.Repo, result.refName) notify_service.SyncDeleteRef(ctx, m.Repo.MustOwner(ctx), m.Repo, result.refName)
continue continue
} }
@ -525,7 +525,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
theCommits.CompareURL = m.Repo.ComposeCompareURL(oldCommitID, newCommitID) theCommits.CompareURL = m.Repo.ComposeCompareURL(oldCommitID, newCommitID)
notification.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{ notify_service.SyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{
RefFullName: result.refName, RefFullName: result.refName,
OldCommitID: oldCommitID, OldCommitID: oldCommitID,
NewCommitID: newCommitID, NewCommitID: newCommitID,

View File

@ -8,25 +8,24 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/repository"
notify_service "code.gitea.io/gitea/services/notify"
) )
func init() { func init() {
notification.RegisterNotifier(&mirrorNotifier{}) notify_service.RegisterNotifier(&mirrorNotifier{})
} }
type mirrorNotifier struct { type mirrorNotifier struct {
base.NullNotifier notify_service.NullNotifier
} }
var _ base.Notifier = &mirrorNotifier{} var _ notify_service.Notifier = &mirrorNotifier{}
func (m *mirrorNotifier) NotifyPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) { func (m *mirrorNotifier) PushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
syncPushMirrorWithSyncOnCommit(ctx, repo.ID) 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) syncPushMirrorWithSyncOnCommit(ctx, repo.ID)
} }

View File

@ -0,0 +1,75 @@
// 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/git"
"code.gitea.io/gitea/modules/repository"
)
// Notifier defines an interface to notify receiver
type Notifier interface {
Run()
AdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository)
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)
RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository)
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)
PullRequestReviewRequest(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, refFullName git.RefName, refID string)
DeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName)
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, refFullName git.RefName, refID string)
SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName)
PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor)
PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor)
}

362
services/notify/notify.go Normal file
View File

@ -0,0 +1,362 @@
// 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/git"
"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) {
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.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) {
if err := review.LoadReviewer(ctx); err != nil {
log.Error("%v", err)
return
}
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) {
if err := comment.LoadPoster(ctx); err != nil {
log.Error("LoadPoster: %v", err)
return
}
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)
}
}
// PullRequestReviewRequest notifies Request Review change
func PullRequestReviewRequest(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.PullRequestReviewRequest(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)
}
}
// AdoptRepository notifies the adoption of a repository to notifiers
func AdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
for _, notifier := range notifiers {
notifier.AdoptRepository(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, refFullName git.RefName, refID string) {
for _, notifier := range notifiers {
notifier.CreateRef(ctx, pusher, repo, refFullName, refID)
}
}
// DeleteRef notifies branch or tag deletion to notifiers
func DeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
for _, notifier := range notifiers {
notifier.DeleteRef(ctx, pusher, repo, 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, refFullName git.RefName, refID string) {
for _, notifier := range notifiers {
notifier.SyncCreateRef(ctx, pusher, repo, refFullName, refID)
}
}
// SyncDeleteRef notifies branch or tag deletion to notifiers
func SyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
for _, notifier := range notifiers {
notifier.SyncDeleteRef(ctx, pusher, repo, 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)
}
}

206
services/notify/null.go Normal file
View File

@ -0,0 +1,206 @@
// 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/git"
"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) {
}
// PullRequestReviewRequest places a place holder function
func (*NullNotifier) PullRequestReviewRequest(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) {
}
// AdoptRepository places a place holder function
func (*NullNotifier) AdoptRepository(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, refFullName git.RefName, refID string) {
}
// DeleteRef notifies branch or tag deletion to notifiers
func (*NullNotifier) DeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
}
// 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, refFullName git.RefName, refID string) {
}
// SyncDeleteRef places a place holder function
func (*NullNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
}
// 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) {
}

View File

@ -18,11 +18,11 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify"
) )
var ( var (
@ -113,7 +113,7 @@ func createPackageAndAddFile(pvci *PackageCreationInfo, pfci *PackageFileCreatio
return nil, nil, err return nil, nil, err
} }
notification.NotifyPackageCreate(db.DefaultContext, pvci.Creator, pd) notify_service.PackageCreate(db.DefaultContext, pvci.Creator, pd)
} }
return pv, pf, nil return pv, pf, nil
@ -489,7 +489,7 @@ func RemovePackageVersion(doer *user_model.User, pv *packages_model.PackageVersi
return err return err
} }
notification.NotifyPackageDelete(db.DefaultContext, doer, pd) notify_service.PackageDelete(db.DefaultContext, doer, pd)
return nil return nil
} }
@ -529,7 +529,7 @@ func RemovePackageFileAndVersionIfUnreferenced(doer *user_model.User, pf *packag
} }
if pd != nil { if pd != nil {
notification.NotifyPackageDelete(db.DefaultContext, doer, pd) notify_service.PackageDelete(db.DefaultContext, doer, pd)
} }
return nil return nil

View File

@ -22,11 +22,11 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/queue"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
asymkey_service "code.gitea.io/gitea/services/asymkey" asymkey_service "code.gitea.io/gitea/services/asymkey"
notify_service "code.gitea.io/gitea/services/notify"
) )
// prPatchCheckerQueue represents a queue to handle update pull request tests // prPatchCheckerQueue represents a queue to handle update pull request tests
@ -295,7 +295,7 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool {
return false return false
} }
notification.NotifyMergePullRequest(ctx, merger, pr) notify_service.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()) 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 return true

View File

@ -25,12 +25,12 @@ import (
"code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/references" "code.gitea.io/gitea/modules/references"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
issue_service "code.gitea.io/gitea/services/issue" issue_service "code.gitea.io/gitea/services/issue"
notify_service "code.gitea.io/gitea/services/notify"
) )
// getMergeMessage composes the message used when merging a pull request. // getMergeMessage composes the message used when merging a pull request.
@ -206,9 +206,9 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
} }
if wasAutoMerged { if wasAutoMerged {
notification.NotifyAutoMergePullRequest(ctx, doer, pr) notify_service.AutoMergePullRequest(ctx, doer, pr)
} else { } else {
notification.NotifyMergePullRequest(ctx, doer, pr) notify_service.MergePullRequest(ctx, doer, pr)
} }
// Reset cached commit count // Reset cached commit count
@ -521,7 +521,7 @@ func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGit
return err return err
} }
notification.NotifyMergePullRequest(baseGitRepo.Ctx, doer, pr) notify_service.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) 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 return nil
} }

View File

@ -25,12 +25,12 @@ import (
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/sync" "code.gitea.io/gitea/modules/sync"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
issue_service "code.gitea.io/gitea/services/issue" issue_service "code.gitea.io/gitea/services/issue"
notify_service "code.gitea.io/gitea/services/notify"
) )
// TODO: use clustered lock (unique queue? or *abuse* cache) // TODO: use clustered lock (unique queue? or *abuse* cache)
@ -145,12 +145,12 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss
return err return err
} }
notification.NotifyNewPullRequest(ctx, pr, mentions) notify_service.NewPullRequest(ctx, pr, mentions)
if len(issue.Labels) > 0 { if len(issue.Labels) > 0 {
notification.NotifyIssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil) notify_service.IssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil)
} }
if issue.Milestone != nil { if issue.Milestone != nil {
notification.NotifyIssueChangeMilestone(ctx, issue.Poster, issue, 0) notify_service.IssueChangeMilestone(ctx, issue.Poster, issue, 0)
} }
if len(assigneeIDs) > 0 { if len(assigneeIDs) > 0 {
for _, assigneeID := range assigneeIDs { for _, assigneeID := range assigneeIDs {
@ -158,7 +158,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss
if err != nil { if err != nil {
return ErrDependenciesLeft return ErrDependenciesLeft
} }
notification.NotifyIssueChangeAssignee(ctx, issue.Poster, issue, assignee, false, assigneeCommentMap[assigneeID]) notify_service.IssueChangeAssignee(ctx, issue.Poster, issue, assignee, false, assigneeCommentMap[assigneeID])
} }
} }
@ -315,7 +315,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
AddToTaskQueue(ctx, pr) AddToTaskQueue(ctx, pr)
comment, err := CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID) comment, err := CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID)
if err == nil && comment != nil { if err == nil && comment != nil {
notification.NotifyPullRequestPushCommits(ctx, doer, pr, comment) notify_service.PullRequestPushCommits(ctx, doer, pr, comment)
} }
} }
@ -365,7 +365,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
} }
} }
notification.NotifyPullRequestSynchronized(ctx, doer, pr) notify_service.PullRequestSynchronized(ctx, doer, pr)
} }
} }
} }

View File

@ -17,9 +17,9 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify"
) )
var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines?`) var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines?`)
@ -113,7 +113,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
return nil, err return nil, err
} }
notification.NotifyCreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions) notify_service.CreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions)
return comment, nil return comment, nil
} }
@ -298,7 +298,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
return nil, nil, err return nil, nil, err
} }
notification.NotifyPullRequestReview(ctx, pr, review, comm, mentions) notify_service.PullRequestReview(ctx, pr, review, comm, mentions)
for _, lines := range review.CodeComments { for _, lines := range review.CodeComments {
for _, comments := range lines { for _, comments := range lines {
@ -307,7 +307,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
notification.NotifyPullRequestCodeComment(ctx, pr, codeComment, mentions) notify_service.PullRequestCodeComment(ctx, pr, codeComment, mentions)
} }
} }
} }
@ -355,7 +355,7 @@ func DismissApprovalReviews(ctx context.Context, doer *user_model.User, pull *is
comment.Poster = doer comment.Poster = doer
comment.Issue = review.Issue comment.Issue = review.Issue
notification.NotifyPullReviewDismiss(ctx, doer, review, comment) notify_service.PullReviewDismiss(ctx, doer, review, comment)
} }
return nil return nil
}) })
@ -426,7 +426,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
comment.Poster = doer comment.Poster = doer
comment.Issue = review.Issue comment.Issue = review.Issue
notification.NotifyPullReviewDismiss(ctx, doer, review, comment) notify_service.PullReviewDismiss(ctx, doer, review, comment)
return comment, nil return comment, nil
} }

View File

@ -17,11 +17,11 @@ import (
"code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify"
) )
func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) { func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) {
@ -81,14 +81,14 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel
commits.CompareURL = rel.Repo.ComposeCompareURL(git.EmptySHA, commit.ID.String()) commits.CompareURL = rel.Repo.ComposeCompareURL(git.EmptySHA, commit.ID.String())
refFullName := git.RefNameFromTag(rel.TagName) refFullName := git.RefNameFromTag(rel.TagName)
notification.NotifyPushCommits( notify_service.PushCommits(
ctx, rel.Publisher, rel.Repo, ctx, rel.Publisher, rel.Repo,
&repository.PushUpdateOptions{ &repository.PushUpdateOptions{
RefFullName: refFullName, RefFullName: refFullName,
OldCommitID: git.EmptySHA, OldCommitID: git.EmptySHA,
NewCommitID: commit.ID.String(), NewCommitID: commit.ID.String(),
}, commits) }, commits)
notification.NotifyCreateRef(ctx, rel.Publisher, rel.Repo, refFullName, commit.ID.String()) notify_service.CreateRef(ctx, rel.Publisher, rel.Repo, refFullName, commit.ID.String())
rel.CreatedUnix = timeutil.TimeStampNow() rel.CreatedUnix = timeutil.TimeStampNow()
} }
commit, err := gitRepo.GetTagCommit(rel.TagName) commit, err := gitRepo.GetTagCommit(rel.TagName)
@ -139,7 +139,7 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU
} }
if !rel.IsDraft { if !rel.IsDraft {
notification.NotifyNewRelease(gitRepo.Ctx, rel) notify_service.NewRelease(gitRepo.Ctx, rel)
} }
return nil return nil
@ -279,12 +279,12 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
} }
if !isCreated { if !isCreated {
notification.NotifyUpdateRelease(gitRepo.Ctx, doer, rel) notify_service.UpdateRelease(gitRepo.Ctx, doer, rel)
return nil return nil
} }
if !rel.IsDraft { if !rel.IsDraft {
notification.NotifyNewRelease(gitRepo.Ctx, rel) notify_service.NewRelease(gitRepo.Ctx, rel)
} }
return nil return nil
@ -325,14 +325,14 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
} }
refName := git.RefNameFromTag(rel.TagName) refName := git.RefNameFromTag(rel.TagName)
notification.NotifyPushCommits( notify_service.PushCommits(
ctx, doer, repo, ctx, doer, repo,
&repository.PushUpdateOptions{ &repository.PushUpdateOptions{
RefFullName: refName, RefFullName: refName,
OldCommitID: rel.Sha1, OldCommitID: rel.Sha1,
NewCommitID: git.EmptySHA, NewCommitID: git.EmptySHA,
}, repository.NewPushCommits()) }, repository.NewPushCommits())
notification.NotifyDeleteRef(ctx, doer, repo, refName) notify_service.DeleteRef(ctx, doer, repo, refName)
if err := repo_model.DeleteReleaseByID(ctx, id); err != nil { if err := repo_model.DeleteReleaseByID(ctx, id); err != nil {
return fmt.Errorf("DeleteReleaseByID: %w", err) return fmt.Errorf("DeleteReleaseByID: %w", err)
@ -361,7 +361,7 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
} }
} }
notification.NotifyDeleteRelease(ctx, doer, rel) notify_service.DeleteRelease(ctx, doer, rel)
return nil return nil
} }

View File

@ -18,10 +18,10 @@ import (
"code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify"
"github.com/gobwas/glob" "github.com/gobwas/glob"
) )
@ -104,7 +104,7 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts repo_mo
return nil, err return nil, err
} }
notification.NotifyAdoptRepository(ctx, doer, u, repo) notify_service.AdoptRepository(ctx, doer, u, repo)
return repo, nil return repo, nil
} }

View File

@ -18,10 +18,10 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/queue"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify"
files_service "code.gitea.io/gitea/services/repository/files" files_service "code.gitea.io/gitea/services/repository/files"
"xorm.io/builder" "xorm.io/builder"
@ -301,8 +301,8 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
return "", err return "", err
} }
notification.NotifyDeleteRef(ctx, doer, repo, git.RefNameFromBranch(from)) notify_service.DeleteRef(ctx, doer, repo, git.RefNameFromBranch(from))
notification.NotifyCreateRef(ctx, doer, repo, refNameTo, refID) notify_service.CreateRef(ctx, doer, repo, refNameTo, refID)
return "", nil return "", nil
} }

View File

@ -15,10 +15,10 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify"
) )
// ErrForkAlreadyExist represents a "ForkAlreadyExist" kind of error. // ErrForkAlreadyExist represents a "ForkAlreadyExist" kind of error.
@ -191,7 +191,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
} }
} }
notification.NotifyForkRepository(ctx, doer, opts.BaseRepo, repo) notify_service.ForkRepository(ctx, doer, opts.BaseRepo, repo)
return repo, nil return repo, nil
} }

View File

@ -18,13 +18,13 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/queue"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
issue_service "code.gitea.io/gitea/services/issue" issue_service "code.gitea.io/gitea/services/issue"
notify_service "code.gitea.io/gitea/services/notify"
pull_service "code.gitea.io/gitea/services/pull" pull_service "code.gitea.io/gitea/services/pull"
) )
@ -119,7 +119,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
} }
tagName := opts.RefFullName.TagName() tagName := opts.RefFullName.TagName()
if opts.IsDelRef() { if opts.IsDelRef() {
notification.NotifyPushCommits( notify_service.PushCommits(
ctx, pusher, repo, ctx, pusher, repo,
&repo_module.PushUpdateOptions{ &repo_module.PushUpdateOptions{
RefFullName: git.RefNameFromTag(tagName), RefFullName: git.RefNameFromTag(tagName),
@ -128,7 +128,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
}, repo_module.NewPushCommits()) }, repo_module.NewPushCommits())
delTags = append(delTags, tagName) delTags = append(delTags, tagName)
notification.NotifyDeleteRef(ctx, pusher, repo, opts.RefFullName) notify_service.DeleteRef(ctx, pusher, repo, opts.RefFullName)
} else { // is new tag } else { // is new tag
newCommit, err := gitRepo.GetCommit(opts.NewCommitID) newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
if err != nil { if err != nil {
@ -139,7 +139,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
commits.HeadCommit = repo_module.CommitToPushCommit(newCommit) commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
commits.CompareURL = repo.ComposeCompareURL(git.EmptySHA, opts.NewCommitID) commits.CompareURL = repo.ComposeCompareURL(git.EmptySHA, opts.NewCommitID)
notification.NotifyPushCommits( notify_service.PushCommits(
ctx, pusher, repo, ctx, pusher, repo,
&repo_module.PushUpdateOptions{ &repo_module.PushUpdateOptions{
RefFullName: opts.RefFullName, RefFullName: opts.RefFullName,
@ -148,7 +148,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
}, commits) }, commits)
addTags = append(addTags, tagName) addTags = append(addTags, tagName)
notification.NotifyCreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID) notify_service.CreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID)
} }
} else if opts.RefFullName.IsBranch() { } else if opts.RefFullName.IsBranch() {
if pusher == nil || pusher.ID != opts.PusherID { if pusher == nil || pusher.ID != opts.PusherID {
@ -197,7 +197,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
if err != nil { if err != nil {
return fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err) return fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err)
} }
notification.NotifyCreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID) notify_service.CreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID)
} else { } else {
l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID) l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID)
if err != nil { if err != nil {
@ -261,14 +261,14 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
return fmt.Errorf("git_model.UpdateBranch %s:%s failed: %v", repo.FullName(), branch, err) return fmt.Errorf("git_model.UpdateBranch %s:%s failed: %v", repo.FullName(), branch, err)
} }
notification.NotifyPushCommits(ctx, pusher, repo, opts, commits) notify_service.PushCommits(ctx, pusher, repo, opts, commits)
// Cache for big repository // Cache for big repository
if err := CacheRef(graceful.GetManager().HammerContext(), repo, gitRepo, opts.RefFullName); err != nil { if err := CacheRef(graceful.GetManager().HammerContext(), repo, gitRepo, opts.RefFullName); err != nil {
log.Error("repo_module.CacheRef %s/%s failed: %v", repo.ID, branch, err) log.Error("repo_module.CacheRef %s/%s failed: %v", repo.ID, branch, err)
} }
} else { } else {
notification.NotifyDeleteRef(ctx, pusher, repo, opts.RefFullName) notify_service.DeleteRef(ctx, pusher, repo, opts.RefFullName)
if err = pull_service.CloseBranchPulls(ctx, pusher, repo.ID, branch); err != nil { if err = pull_service.CloseBranchPulls(ctx, pusher, repo.ID, branch); err != nil {
// close all related pulls // close all related pulls
log.Error("close related pull request failed: %v", err) log.Error("close related pull request failed: %v", err)

View File

@ -19,10 +19,10 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
notify_service "code.gitea.io/gitea/services/notify"
pull_service "code.gitea.io/gitea/services/pull" pull_service "code.gitea.io/gitea/services/pull"
) )
@ -47,7 +47,7 @@ func CreateRepository(ctx context.Context, doer, owner *user_model.User, opts re
return nil, err return nil, err
} }
notification.NotifyCreateRepository(ctx, doer, owner, repo) notify_service.CreateRepository(ctx, doer, owner, repo)
return repo, nil return repo, nil
} }
@ -60,7 +60,7 @@ func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_mod
if notify { if notify {
// If the repo itself has webhooks, we need to trigger them before deleting it... // If the repo itself has webhooks, we need to trigger them before deleting it...
notification.NotifyDeleteRepository(ctx, doer, repo) notify_service.DeleteRepository(ctx, doer, repo)
} }
if err := models.DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil { if err := models.DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil {

View File

@ -11,8 +11,8 @@ import (
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
notify_service "code.gitea.io/gitea/services/notify"
) )
// GenerateIssueLabels generates issue labels from a template repository // GenerateIssueLabels generates issue labels from a template repository
@ -130,7 +130,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
return nil, err return nil, err
} }
notification.NotifyCreateRepository(ctx, doer, owner, generateRepo) notify_service.CreateRepository(ctx, doer, owner, generateRepo)
return generateRepo, nil return generateRepo, nil
} }

View File

@ -14,9 +14,9 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/sync" "code.gitea.io/gitea/modules/sync"
notify_service "code.gitea.io/gitea/services/notify"
) )
// repoWorkingPool represents a working pool to order the parallel changes to the same repository // 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_service.TransferRepository(ctx, doer, repo, oldOwner.Name)
return nil return nil
} }
@ -77,7 +77,7 @@ func ChangeRepositoryName(ctx context.Context, doer *user_model.User, repo *repo
repoWorkingPool.CheckOut(fmt.Sprint(repo.ID)) repoWorkingPool.CheckOut(fmt.Sprint(repo.ID))
repo.Name = newRepoName repo.Name = newRepoName
notification.NotifyRenameRepository(ctx, doer, repo, oldRepoName) notify_service.RenameRepository(ctx, doer, repo, oldRepoName)
return nil 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 // notify users who are able to accept / reject transfer
notification.NotifyRepoPendingTransfer(ctx, doer, newOwner, repo) notify_service.RepoPendingTransfer(ctx, doer, newOwner, repo)
return nil return nil
} }

View File

@ -14,9 +14,9 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/feed" "code.gitea.io/gitea/services/feed"
notify_service "code.gitea.io/gitea/services/notify"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -25,7 +25,7 @@ var notifySync sync.Once
func registerNotifier() { func registerNotifier() {
notifySync.Do(func() { notifySync.Do(func() {
notification.RegisterNotifier(feed.NewNotifier()) notify_service.RegisterNotifier(feed.NewNotifier())
}) })
} }

View File

@ -17,12 +17,12 @@ import (
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/migration" "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/migrations" "code.gitea.io/gitea/services/migrations"
notify_service "code.gitea.io/gitea/services/notify"
) )
func handleCreateError(owner *user_model.User, err error) error { func handleCreateError(owner *user_model.User, err error) error {
@ -50,7 +50,7 @@ func runMigrateTask(t *admin_model.Task) (err error) {
if err == nil { if err == nil {
err = admin_model.FinishMigrateTask(t) err = admin_model.FinishMigrateTask(t)
if err == nil { if err == nil {
notification.NotifyMigrateRepository(db.DefaultContext, t.Doer, t.Owner, t.Repo) notify_service.MigrateRepository(db.DefaultContext, t.Doer, t.Owner, t.Repo)
return return
} }

View File

@ -14,14 +14,13 @@ import (
"code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/queue"
notify_service "code.gitea.io/gitea/services/notify"
) )
type ( type (
notificationService struct { notificationService struct {
base.NullNotifier notify_service.NullNotifier
issueQueue *queue.WorkerPoolQueue[issueNotificationOpts] issueQueue *queue.WorkerPoolQueue[issueNotificationOpts]
} }
@ -34,15 +33,15 @@ type (
) )
func Init() error { func Init() error {
notification.RegisterNotifier(NewNotifier()) notify_service.RegisterNotifier(NewNotifier())
return nil return nil
} }
var _ base.Notifier = &notificationService{} var _ notify_service.Notifier = &notificationService{}
// NewNotifier create a new notificationService notifier // NewNotifier create a new notificationService notifier
func NewNotifier() base.Notifier { func NewNotifier() notify_service.Notifier {
ns := &notificationService{} ns := &notificationService{}
ns.issueQueue = queue.CreateSimpleQueue(graceful.GetManager().ShutdownContext(), "notification-service", handler) ns.issueQueue = queue.CreateSimpleQueue(graceful.GetManager().ShutdownContext(), "notification-service", handler)
if ns.issueQueue == nil { if ns.issueQueue == nil {
@ -64,7 +63,7 @@ func (ns *notificationService) Run() {
go graceful.GetManager().RunWithCancel(ns.issueQueue) // TODO: using "go" here doesn't seem right, just leave it as old code go graceful.GetManager().RunWithCancel(ns.issueQueue) // TODO: using "go" here doesn't seem right, just leave it as old code
} }
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, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) { ) {
opts := issueNotificationOpts{ opts := issueNotificationOpts{
@ -88,7 +87,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{ _ = ns.issueQueue.Push(issueNotificationOpts{
IssueID: issue.ID, IssueID: issue.ID,
NotificationAuthorID: issue.Poster.ID, NotificationAuthorID: issue.Poster.ID,
@ -102,7 +101,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{ _ = ns.issueQueue.Push(issueNotificationOpts{
IssueID: issue.ID, IssueID: issue.ID,
NotificationAuthorID: doer.ID, NotificationAuthorID: doer.ID,
@ -110,7 +109,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 { if err := issue.LoadPullRequest(ctx); err != nil {
log.Error("issue.LoadPullRequest: %v", err) log.Error("issue.LoadPullRequest: %v", err)
return return
@ -123,18 +122,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{ _ = ns.issueQueue.Push(issueNotificationOpts{
IssueID: pr.Issue.ID, IssueID: pr.Issue.ID,
NotificationAuthorID: doer.ID, NotificationAuthorID: doer.ID,
}) })
} }
func (ns *notificationService) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) { func (ns *notificationService) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
ns.NotifyMergePullRequest(ctx, doer, pr) 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 { if err := pr.LoadIssue(ctx); err != nil {
log.Error("Unable to load issue: %d for pr: %d: Error: %v", pr.IssueID, pr.ID, err) log.Error("Unable to load issue: %d for pr: %d: Error: %v", pr.IssueID, pr.ID, err)
return return
@ -169,7 +168,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{ opts := issueNotificationOpts{
IssueID: pr.Issue.ID, IssueID: pr.Issue.ID,
NotificationAuthorID: r.Reviewer.ID, NotificationAuthorID: r.Reviewer.ID,
@ -191,7 +190,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 { for _, mention := range mentions {
_ = ns.issueQueue.Push(issueNotificationOpts{ _ = ns.issueQueue.Push(issueNotificationOpts{
IssueID: pr.Issue.ID, IssueID: pr.Issue.ID,
@ -202,7 +201,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{ opts := issueNotificationOpts{
IssueID: pr.IssueID, IssueID: pr.IssueID,
NotificationAuthorID: doer.ID, NotificationAuthorID: doer.ID,
@ -211,7 +210,7 @@ func (ns *notificationService) NotifyPullRequestPushCommits(ctx context.Context,
_ = ns.issueQueue.Push(opts) _ = 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{ opts := issueNotificationOpts{
IssueID: review.IssueID, IssueID: review.IssueID,
NotificationAuthorID: doer.ID, NotificationAuthorID: doer.ID,
@ -220,7 +219,7 @@ func (ns *notificationService) NotifyPullReviewDismiss(ctx context.Context, doer
_ = ns.issueQueue.Push(opts) _ = 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 { if !removed && doer.ID != assignee.ID {
opts := issueNotificationOpts{ opts := issueNotificationOpts{
IssueID: issue.ID, IssueID: issue.ID,
@ -236,7 +235,7 @@ func (ns *notificationService) NotifyIssueChangeAssignee(ctx context.Context, do
} }
} }
func (ns *notificationService) NotifyPullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { func (ns *notificationService) PullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
if isRequest { if isRequest {
opts := issueNotificationOpts{ opts := issueNotificationOpts{
IssueID: issue.ID, IssueID: issue.ID,
@ -252,7 +251,7 @@ func (ns *notificationService) NotifyPullRequestReviewRequest(ctx context.Contex
} }
} }
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 { err := db.WithTx(ctx, func(ctx context.Context) error {
return activities_model.CreateRepoTransferNotification(ctx, doer, newOwner, repo) return activities_model.CreateRepoTransferNotification(ctx, doer, newOwner, repo)
}) })

View File

@ -14,31 +14,30 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
webhook_module "code.gitea.io/gitea/modules/webhook" webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/convert"
notify_service "code.gitea.io/gitea/services/notify"
) )
func init() { func init() {
notification.RegisterNotifier(&webhookNotifier{}) notify_service.RegisterNotifier(&webhookNotifier{})
} }
type webhookNotifier struct { type webhookNotifier struct {
base.NullNotifier notify_service.NullNotifier
} }
var _ base.Notifier = &webhookNotifier{} var _ notify_service.Notifier = &webhookNotifier{}
// NewNotifier create a new webhookNotifier notifier // NewNotifier create a new webhookNotifier notifier
func NewNotifier() base.Notifier { func NewNotifier() notify_service.Notifier {
return &webhookNotifier{} 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 { if err := issue.LoadPoster(ctx); err != nil {
log.Error("LoadPoster: %v", err) log.Error("LoadPoster: %v", err)
return return
@ -78,7 +77,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) {
oldPermission, _ := access_model.GetUserRepoPermission(ctx, oldRepo, doer) oldPermission, _ := access_model.GetUserRepoPermission(ctx, oldRepo, doer)
permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer) permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer)
@ -106,7 +105,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. // Add to hook queue for created repo after session commit.
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{ if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated, Action: api.HookRepoCreated,
@ -118,7 +117,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{ if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoDeleted, Action: api.HookRepoDeleted,
Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}),
@ -129,7 +128,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. // Add to hook queue for created repo after session commit.
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{ if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated, Action: api.HookRepoCreated,
@ -141,7 +140,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 { if issue.IsPull {
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, doer) permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
@ -186,7 +185,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) {
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster) permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster)
var err error var err error
if issue.IsPull { if issue.IsPull {
@ -226,7 +225,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) {
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster) permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster)
var err error var err error
if issue.IsPull { if issue.IsPull {
@ -268,7 +267,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 { if err := issue.LoadRepo(ctx); err != nil {
log.Error("issue.LoadRepo: %v", err) log.Error("issue.LoadRepo: %v", err)
return return
@ -290,7 +289,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 { if err := pull.LoadIssue(ctx); err != nil {
log.Error("pull.LoadIssue: %v", err) log.Error("pull.LoadIssue: %v", err)
return return
@ -316,7 +315,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 { if err := issue.LoadRepo(ctx); err != nil {
log.Error("LoadRepo: %v", err) log.Error("LoadRepo: %v", err)
return return
@ -360,7 +359,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 { if err := c.LoadPoster(ctx); err != nil {
log.Error("LoadPoster: %v", err) log.Error("LoadPoster: %v", err)
return return
@ -400,7 +399,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, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) { ) {
var eventType webhook_module.HookEventType var eventType webhook_module.HookEventType
@ -423,7 +422,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 var err error
if err = comment.LoadPoster(ctx); err != nil { if err = comment.LoadPoster(ctx); err != nil {
@ -460,7 +459,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. // Add to hook queue for created wiki page.
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{ if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{
Action: api.HookWikiCreated, Action: api.HookWikiCreated,
@ -473,7 +472,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. // Add to hook queue for edit wiki page.
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{ if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{
Action: api.HookWikiEdited, Action: api.HookWikiEdited,
@ -486,7 +485,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. // Add to hook queue for edit wiki page.
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{ if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{
Action: api.HookWikiDeleted, Action: api.HookWikiDeleted,
@ -498,7 +497,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, addedLabels, removedLabels []*issues_model.Label,
) { ) {
var err error var err error
@ -544,7 +543,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 hookAction api.HookIssueAction
var err error var err error
if issue.MilestoneID > 0 { if issue.MilestoneID > 0 {
@ -586,7 +585,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) apiPusher := convert.ToUser(ctx, pusher, nil)
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL()) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
if err != nil { if err != nil {
@ -610,12 +609,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) { func (m *webhookNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
// just redirect to the NotifyMergePullRequest // just redirect to the MergePullRequest
m.NotifyMergePullRequest(ctx, doer, pr) 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. // Reload pull request information.
if err := pr.LoadAttributes(ctx); err != nil { if err := pr.LoadAttributes(ctx); err != nil {
log.Error("LoadAttributes: %v", err) log.Error("LoadAttributes: %v", err)
@ -652,7 +651,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 { if err := pr.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err) log.Error("LoadIssue: %v", err)
return return
@ -677,7 +676,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 var reviewHookType webhook_module.HookEventType
switch review.Type { switch review.Type {
@ -718,9 +717,9 @@ func (m *webhookNotifier) NotifyPullRequestReview(ctx context.Context, pr *issue
} }
} }
func (m *webhookNotifier) NotifyPullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) { func (m *webhookNotifier) PullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
if !issue.IsPull { if !issue.IsPull {
log.Warn("NotifyPullRequestReviewRequest: issue is not a pull request: %v", issue.ID) log.Warn("PullRequestReviewRequest: issue is not a pull request: %v", issue.ID)
return return
} }
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, doer) permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
@ -746,7 +745,7 @@ func (m *webhookNotifier) NotifyPullRequestReviewRequest(ctx context.Context, do
} }
} }
func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) { func (m *webhookNotifier) CreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
apiPusher := convert.ToUser(ctx, pusher, nil) apiPusher := convert.ToUser(ctx, pusher, nil)
apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeNone}) apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeNone})
refName := refFullName.ShortName() refName := refFullName.ShortName()
@ -762,7 +761,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 { if err := pr.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err) log.Error("LoadIssue: %v", err)
return return
@ -783,7 +782,7 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(ctx context.Context, doe
} }
} }
func (m *webhookNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) { func (m *webhookNotifier) DeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
apiPusher := convert.ToUser(ctx, pusher, nil) apiPusher := convert.ToUser(ctx, pusher, nil)
apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}) apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner})
refName := refFullName.ShortName() refName := refFullName.ShortName()
@ -816,19 +815,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) 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) 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) 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) apiPusher := convert.ToUser(ctx, pusher, nil)
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL()) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
if err != nil { if err != nil {
@ -852,19 +851,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, refFullName git.RefName, refID string) { func (m *webhookNotifier) SyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
m.NotifyCreateRef(ctx, pusher, repo, refFullName, refID) m.CreateRef(ctx, pusher, repo, refFullName, refID)
} }
func (m *webhookNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) { func (m *webhookNotifier) SyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
m.NotifyDeleteRef(ctx, pusher, repo, refFullName) m.DeleteRef(ctx, pusher, repo, 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) 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) notifyPackage(ctx, doer, pd, api.HookPackageDeleted)
} }