summaryrefslogtreecommitdiffstats
path: root/modules/notification
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-11-15 16:06:11 +0800
committerGitHub <noreply@github.com>2019-11-15 16:06:11 +0800
commit21ae9838e04233bbf9930d368d935fd1f9b68c34 (patch)
tree610abb6f1ec2df235d469276b36f6d26e00e4653 /modules/notification
parentb30d744e0986dcf716d4f57dac8c72a494bb226b (diff)
downloadgitea-21ae9838e04233bbf9930d368d935fd1f9b68c34.tar.gz
gitea-21ae9838e04233bbf9930d368d935fd1f9b68c34.zip
Move transfer repository and rename repository on a service package and start action notification (#8573)
* move transfer repository and rename repository on a service package and start action notification * remove unused codes * fix lint * fix bugs * fix test * fix test * fix test * fix lint * update go mod and sum
Diffstat (limited to 'modules/notification')
-rw-r--r--modules/notification/action/action.go25
-rw-r--r--modules/notification/base/notifier.go3
-rw-r--r--modules/notification/base/null.go28
-rw-r--r--modules/notification/notification.go49
4 files changed, 66 insertions, 39 deletions
diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go
index d4be1e4304..dd4dc0ae32 100644
--- a/modules/notification/action/action.go
+++ b/modules/notification/action/action.go
@@ -6,6 +6,7 @@ package action
import (
"fmt"
+ "path"
"strings"
"code.gitea.io/gitea/models"
@@ -77,7 +78,9 @@ func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest) {
}
}
-func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
+func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) {
+ log.Trace("action.ChangeRepositoryName: %s/%s", doer.Name, repo.Name)
+
if err := models.NotifyWatchers(&models.Action{
ActUserID: doer.ID,
ActUser: doer,
@@ -85,11 +88,23 @@ func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models.
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
- Content: oldName,
+ Content: oldRepoName,
}); err != nil {
- log.Error("notify watchers: %v", err)
- } else {
- log.Trace("action.renameRepoAction: %s/%s", doer.Name, repo.Name)
+ log.Error("NotifyWatchers: %v", err)
+ }
+}
+
+func (a *actionNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) {
+ if err := models.NotifyWatchers(&models.Action{
+ ActUserID: doer.ID,
+ ActUser: doer,
+ OpType: models.ActionTransferRepo,
+ RepoID: repo.ID,
+ Repo: repo,
+ IsPrivate: repo.IsPrivate,
+ Content: path.Join(oldOwnerName, repo.Name),
+ }); err != nil {
+ log.Error("NotifyWatchers: %v", err)
}
}
diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go
index 9510afc978..1935c30557 100644
--- a/modules/notification/base/notifier.go
+++ b/modules/notification/base/notifier.go
@@ -17,7 +17,8 @@ type Notifier interface {
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)
- NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string)
+ NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string)
+ NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string)
NotifyNewIssue(*models.Issue)
NotifyIssueChangeStatus(*models.User, *models.Issue, bool)
diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go
index 2341b8d2a7..b9ecaed425 100644
--- a/modules/notification/base/null.go
+++ b/modules/notification/base/null.go
@@ -58,18 +58,6 @@ func (*NullNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, o
func (*NullNotifier) NotifyDeleteComment(doer *models.User, c *models.Comment) {
}
-// NotifyDeleteRepository places a place holder function
-func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
-}
-
-// NotifyForkRepository places a place holder function
-func (*NullNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
-}
-
-// NotifyRenameRepository places a place holder function
-func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
-}
-
// NotifyNewRelease places a place holder function
func (*NullNotifier) NotifyNewRelease(rel *models.Release) {
}
@@ -111,6 +99,14 @@ func (*NullNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Is
func (*NullNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
}
+// NotifyDeleteRepository places a place holder function
+func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
+}
+
+// NotifyForkRepository places a place holder function
+func (*NullNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
+}
+
// NotifyMigrateRepository places a place holder function
func (*NullNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
}
@@ -126,3 +122,11 @@ func (*NullNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository,
// NotifyDeleteRef notifies branch or tag deleteion to notifiers
func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
}
+
+// NotifyRenameRepository places a place holder function
+func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) {
+}
+
+// NotifyTransferRepository places a place holder function
+func (*NullNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) {
+}
diff --git a/modules/notification/notification.go b/modules/notification/notification.go
index fdfcc62ffe..fa0b280e71 100644
--- a/modules/notification/notification.go
+++ b/modules/notification/notification.go
@@ -101,27 +101,6 @@ func NotifyDeleteComment(doer *models.User, c *models.Comment) {
}
}
-// 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)
- }
-}
-
-// NotifyRenameRepository notifies repository renamed
-func NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
- for _, notifier := range notifiers {
- notifier.NotifyRenameRepository(doer, repo, oldName)
- }
-}
-
// NotifyNewRelease notifies new release to notifiers
func NotifyNewRelease(rel *models.Release) {
for _, notifier := range notifiers {
@@ -200,6 +179,34 @@ func NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Rep
}
}
+// NotifyTransferRepository notifies create repository to notifiers
+func NotifyTransferRepository(doer *models.User, repo *models.Repository, newOwnerName string) {
+ for _, notifier := range notifiers {
+ notifier.NotifyTransferRepository(doer, repo, newOwnerName)
+ }
+}
+
+// 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)
+ }
+}
+
+// NotifyRenameRepository notifies repository renamed
+func NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
+ for _, notifier := range notifiers {
+ notifier.NotifyRenameRepository(doer, repo, oldName)
+ }
+}
+
// NotifyPushCommits notifies commits pushed to notifiers
func NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *models.PushCommits) {
for _, notifier := range notifiers {