-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add notification interface and refactor UI notifications #5085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2018 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package base | ||
|
||
import ( | ||
"code.gitea.io/git" | ||
"code.gitea.io/gitea/models" | ||
) | ||
|
||
// Notifier defines an interface to notify receiver | ||
type Notifier interface { | ||
Run() | ||
|
||
NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) | ||
NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) | ||
NotifyDeleteRepository(doer *models.User, repo *models.Repository) | ||
NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) | ||
|
||
NotifyNewIssue(*models.Issue) | ||
NotifyIssueChangeStatus(*models.User, *models.Issue, bool) | ||
NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) | ||
NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) | ||
NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) | ||
NotifyIssueClearLabels(doer *models.User, issue *models.Issue) | ||
NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) | ||
NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, | ||
addedLabels []*models.Label, removedLabels []*models.Label) | ||
|
||
NotifyNewPullRequest(*models.PullRequest) | ||
NotifyMergePullRequest(*models.PullRequest, *models.User, *git.Repository) | ||
NotifyPullRequestReview(*models.PullRequest, *models.Review, *models.Comment) | ||
|
||
NotifyCreateIssueComment(*models.User, *models.Repository, | ||
*models.Issue, *models.Comment) | ||
NotifyUpdateComment(*models.User, *models.Comment, string) | ||
NotifyDeleteComment(*models.User, *models.Comment) | ||
|
||
NotifyNewRelease(rel *models.Release) | ||
NotifyUpdateRelease(doer *models.User, rel *models.Release) | ||
NotifyDeleteRelease(doer *models.User, rel *models.Release) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,175 @@ | ||
// Copyright 2016 The Gitea Authors. All rights reserved. | ||
// Copyright 2018 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package notification | ||
|
||
import ( | ||
"code.gitea.io/git" | ||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/notification/base" | ||
"code.gitea.io/gitea/modules/notification/ui" | ||
) | ||
|
||
type ( | ||
notificationService struct { | ||
issueQueue chan issueNotificationOpts | ||
var ( | ||
notifiers []base.Notifier | ||
) | ||
|
||
// RegisterNotifier providers method to receive notify messages | ||
func RegisterNotifier(notifier base.Notifier) { | ||
go notifier.Run() | ||
notifiers = append(notifiers, notifier) | ||
} | ||
|
||
func init() { | ||
RegisterNotifier(ui.NewNotifier()) | ||
} | ||
|
||
// NotifyCreateIssueComment notifies issue comment related message to notifiers | ||
func NotifyCreateIssueComment(doer *models.User, repo *models.Repository, | ||
issue *models.Issue, comment *models.Comment) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyCreateIssueComment(doer, repo, issue, comment) | ||
} | ||
} | ||
|
||
issueNotificationOpts struct { | ||
issue *models.Issue | ||
notificationAuthorID int64 | ||
// NotifyNewIssue notifies new issue to notifiers | ||
func NotifyNewIssue(issue *models.Issue) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyNewIssue(issue) | ||
} | ||
) | ||
} | ||
|
||
var ( | ||
// Service is the notification service | ||
Service = ¬ificationService{ | ||
issueQueue: make(chan issueNotificationOpts, 100), | ||
// NotifyIssueChangeStatus notifies close or reopen issue to notifiers | ||
func NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, closeOrReopen bool) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyIssueChangeStatus(doer, issue, closeOrReopen) | ||
} | ||
) | ||
} | ||
|
||
func init() { | ||
go Service.Run() | ||
// NotifyMergePullRequest notifies merge pull request to notifiers | ||
func NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyMergePullRequest(pr, doer, baseGitRepo) | ||
jonasfranz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
// NotifyNewPullRequest notifies new pull request to notifiers | ||
func NotifyNewPullRequest(pr *models.PullRequest) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyNewPullRequest(pr) | ||
} | ||
} | ||
|
||
// NotifyPullRequestReview notifies new pull request review | ||
func NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyPullRequestReview(pr, review, comment) | ||
} | ||
} | ||
|
||
// NotifyUpdateComment notifies update comment to notifiers | ||
func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyUpdateComment(doer, c, oldContent) | ||
} | ||
} | ||
|
||
// NotifyDeleteComment notifies delete comment to notifiers | ||
func NotifyDeleteComment(doer *models.User, c *models.Comment) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyDeleteComment(doer, c) | ||
} | ||
} | ||
|
||
// NotifyDeleteRepository notifies delete repository to notifiers | ||
func NotifyDeleteRepository(doer *models.User, repo *models.Repository) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyDeleteRepository(doer, repo) | ||
} | ||
} | ||
|
||
// NotifyForkRepository notifies fork repository to notifiers | ||
func NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyForkRepository(doer, oldRepo, repo) | ||
} | ||
} | ||
|
||
// NotifyNewRelease notifies new release to notifiers | ||
func NotifyNewRelease(rel *models.Release) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyNewRelease(rel) | ||
} | ||
} | ||
|
||
// NotifyUpdateRelease notifies update release to notifiers | ||
func NotifyUpdateRelease(doer *models.User, rel *models.Release) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyUpdateRelease(doer, rel) | ||
} | ||
} | ||
|
||
// NotifyDeleteRelease notifies delete release to notifiers | ||
func NotifyDeleteRelease(doer *models.User, rel *models.Release) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyDeleteRelease(doer, rel) | ||
} | ||
} | ||
|
||
// NotifyIssueChangeMilestone notifies change milestone to notifiers | ||
func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyIssueChangeMilestone(doer, issue) | ||
} | ||
} | ||
|
||
// NotifyIssueChangeContent notifies change content to notifiers | ||
func NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyIssueChangeContent(doer, issue, oldContent) | ||
} | ||
} | ||
|
||
// NotifyIssueChangeAssignee notifies change content to notifiers | ||
func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyIssueChangeAssignee(doer, issue, removed) | ||
} | ||
} | ||
|
||
// NotifyIssueClearLabels notifies clear labels to notifiers | ||
func NotifyIssueClearLabels(doer *models.User, issue *models.Issue) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyIssueClearLabels(doer, issue) | ||
} | ||
} | ||
|
||
// NotifyIssueChangeTitle notifies change title to notifiers | ||
func NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyIssueChangeTitle(doer, issue, oldTitle) | ||
} | ||
} | ||
|
||
// NotifyIssueChangeLabels notifies change labels to notifiers | ||
func NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, | ||
addedLabels []*models.Label, removedLabels []*models.Label) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels) | ||
} | ||
} | ||
|
||
func (ns *notificationService) Run() { | ||
for { | ||
select { | ||
case opts := <-ns.issueQueue: | ||
if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil { | ||
log.Error(4, "Was unable to create issue notification: %v", err) | ||
} | ||
} | ||
// NotifyCreateRepository notifies create repository to notifiers | ||
func NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyCreateRepository(doer, u, repo) | ||
} | ||
} | ||
|
||
func (ns *notificationService) NotifyIssue(issue *models.Issue, notificationAuthorID int64) { | ||
ns.issueQueue <- issueNotificationOpts{ | ||
issue, | ||
notificationAuthorID, | ||
// NotifyMigrateRepository notifies create repository to notifiers | ||
func NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { | ||
for _, notifier := range notifiers { | ||
notifier.NotifyMigrateRepository(doer, u, repo) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.