2019-11-03 15:59:09 -05:00
|
|
|
// Copyright 2019 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 action
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
"code.gitea.io/gitea/modules/notification/base"
|
|
|
|
)
|
|
|
|
|
|
|
|
type actionNotifier struct {
|
|
|
|
base.NullNotifier
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ base.Notifier = &actionNotifier{}
|
|
|
|
)
|
|
|
|
|
2019-11-08 15:54:50 -05:00
|
|
|
// NewNotifier create a new actionNotifier notifier
|
2019-11-03 15:59:09 -05:00
|
|
|
func NewNotifier() base.Notifier {
|
|
|
|
return &actionNotifier{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *actionNotifier) NotifyNewIssue(issue *models.Issue) {
|
|
|
|
if err := issue.LoadPoster(); err != nil {
|
|
|
|
log.Error("issue.LoadPoster: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := issue.LoadRepo(); err != nil {
|
|
|
|
log.Error("issue.LoadRepo: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
repo := issue.Repo
|
|
|
|
|
|
|
|
if err := models.NotifyWatchers(&models.Action{
|
|
|
|
ActUserID: issue.Poster.ID,
|
|
|
|
ActUser: issue.Poster,
|
|
|
|
OpType: models.ActionCreateIssue,
|
|
|
|
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
|
|
|
|
RepoID: repo.ID,
|
|
|
|
Repo: repo,
|
|
|
|
IsPrivate: repo.IsPrivate,
|
|
|
|
}); err != nil {
|
|
|
|
log.Error("NotifyWatchers: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest) {
|
|
|
|
if err := pull.LoadIssue(); err != nil {
|
|
|
|
log.Error("pull.LoadIssue: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := pull.Issue.LoadRepo(); err != nil {
|
|
|
|
log.Error("pull.Issue.LoadRepo: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := pull.Issue.LoadPoster(); err != nil {
|
|
|
|
log.Error("pull.Issue.LoadPoster: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := models.NotifyWatchers(&models.Action{
|
|
|
|
ActUserID: pull.Issue.Poster.ID,
|
|
|
|
ActUser: pull.Issue.Poster,
|
|
|
|
OpType: models.ActionCreatePullRequest,
|
|
|
|
Content: fmt.Sprintf("%d|%s", pull.Issue.Index, pull.Issue.Title),
|
|
|
|
RepoID: pull.Issue.Repo.ID,
|
|
|
|
Repo: pull.Issue.Repo,
|
|
|
|
IsPrivate: pull.Issue.Repo.IsPrivate,
|
|
|
|
}); err != nil {
|
|
|
|
log.Error("NotifyWatchers: %v", err)
|
|
|
|
}
|
|
|
|
}
|
2019-11-08 15:54:50 -05:00
|
|
|
|
|
|
|
func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
|
|
|
|
if err := models.NotifyWatchers(&models.Action{
|
|
|
|
ActUserID: doer.ID,
|
|
|
|
ActUser: doer,
|
|
|
|
OpType: models.ActionRenameRepo,
|
|
|
|
RepoID: repo.ID,
|
|
|
|
Repo: repo,
|
|
|
|
IsPrivate: repo.IsPrivate,
|
|
|
|
Content: oldName,
|
|
|
|
}); err != nil {
|
|
|
|
log.Error("notify watchers: %v", err)
|
|
|
|
} else {
|
|
|
|
log.Trace("action.renameRepoAction: %s/%s", doer.Name, repo.Name)
|
|
|
|
}
|
|
|
|
}
|