aboutsummaryrefslogtreecommitdiffstats
path: root/modules/notification/action
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-11-24 13:16:59 +0800
committertechknowlogick <techknowlogick@gitea.io>2019-11-24 00:16:59 -0500
commit8ab35eefc4ff5db3f2f0a62f6f0272eae9be0585 (patch)
tree5249bcee68fb96652adc8f7dd46b604cbf15cd5e /modules/notification/action
parente3f22ad2cca094cba057683f35f8536e3f71a582 (diff)
downloadgitea-8ab35eefc4ff5db3f2f0a62f6f0272eae9be0585.tar.gz
gitea-8ab35eefc4ff5db3f2f0a62f6f0272eae9be0585.zip
Move mirror sync actions to notification (#9022)
* Move mirror sync actions to notification * fix lint
Diffstat (limited to 'modules/notification/action')
-rw-r--r--modules/notification/action/action.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go
index 70ab9975b2..9caeb5aac0 100644
--- a/modules/notification/action/action.go
+++ b/modules/notification/action/action.go
@@ -5,6 +5,7 @@
package action
import (
+ "encoding/json"
"fmt"
"path"
"strings"
@@ -206,3 +207,52 @@ func (*actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mode
log.Error("NotifyWatchers [%d]: %v", pr.ID, err)
}
}
+
+func (a *actionNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *models.PushCommits) {
+ data, err := json.Marshal(commits)
+ if err != nil {
+ log.Error("json.Marshal: %v", err)
+ return
+ }
+
+ if err := models.NotifyWatchers(&models.Action{
+ ActUserID: repo.OwnerID,
+ ActUser: repo.MustOwner(),
+ OpType: models.ActionMirrorSyncPush,
+ RepoID: repo.ID,
+ Repo: repo,
+ IsPrivate: repo.IsPrivate,
+ RefName: refName,
+ Content: string(data),
+ }); err != nil {
+ log.Error("notifyWatchers: %v", err)
+ }
+}
+
+func (a *actionNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
+ if err := models.NotifyWatchers(&models.Action{
+ ActUserID: repo.OwnerID,
+ ActUser: repo.MustOwner(),
+ OpType: models.ActionMirrorSyncCreate,
+ RepoID: repo.ID,
+ Repo: repo,
+ IsPrivate: repo.IsPrivate,
+ RefName: refFullName,
+ }); err != nil {
+ log.Error("notifyWatchers: %v", err)
+ }
+}
+
+func (a *actionNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
+ if err := models.NotifyWatchers(&models.Action{
+ ActUserID: repo.OwnerID,
+ ActUser: repo.MustOwner(),
+ OpType: models.ActionMirrorSyncCreate,
+ RepoID: repo.ID,
+ Repo: repo,
+ IsPrivate: repo.IsPrivate,
+ RefName: refFullName,
+ }); err != nil {
+ log.Error("notifyWatchers: %v", err)
+ }
+}