diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-12-08 10:23:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-08 03:23:18 +0100 |
commit | ab22ab4a37110e989e2060fb088798e783dfcec7 (patch) | |
tree | acca9917b903b349b8806bf76f27c6b18a55463e /modules/notification | |
parent | 682f0b046066ee64f9a6c8881377b304db3e6f9d (diff) | |
download | gitea-ab22ab4a37110e989e2060fb088798e783dfcec7.tar.gz gitea-ab22ab4a37110e989e2060fb088798e783dfcec7.zip |
Refactor push update (#13381)
* Refactor Push update
* Remove the push_test since the function has been removed.
* Use default branch setting instead master
Diffstat (limited to 'modules/notification')
-rw-r--r-- | modules/notification/action/action.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go index 13c2ca81da..75d2aa3019 100644 --- a/modules/notification/action/action.go +++ b/modules/notification/action/action.go @@ -275,6 +275,75 @@ func (*actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mode } } +func (a *actionNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { + data, err := json.Marshal(commits) + if err != nil { + log.Error("Marshal: %v", err) + return + } + + opType := models.ActionCommitRepo + + // Check it's tag push or branch. + if opts.IsTag() { + opType = models.ActionPushTag + if opts.IsDelRef() { + opType = models.ActionDeleteTag + } + } else if opts.IsDelRef() { + opType = models.ActionDeleteBranch + } + + if err = models.NotifyWatchers(&models.Action{ + ActUserID: pusher.ID, + ActUser: pusher, + OpType: opType, + Content: string(data), + RepoID: repo.ID, + Repo: repo, + RefName: opts.RefFullName, + IsPrivate: repo.IsPrivate, + }); err != nil { + log.Error("notifyWatchers: %v", err) + } +} + +func (a *actionNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) { + opType := models.ActionCommitRepo + if refType == "tag" { + opType = models.ActionPushTag + } + if err := models.NotifyWatchers(&models.Action{ + ActUserID: doer.ID, + ActUser: doer, + OpType: opType, + RepoID: repo.ID, + Repo: repo, + IsPrivate: repo.IsPrivate, + RefName: refFullName, + }); err != nil { + log.Error("notifyWatchers: %v", err) + } +} + +func (a *actionNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) { + opType := models.ActionDeleteBranch + if refType == "tag" { + opType = models.ActionDeleteTag + } + if err := models.NotifyWatchers(&models.Action{ + ActUserID: doer.ID, + ActUser: doer, + OpType: opType, + RepoID: repo.ID, + Repo: repo, + IsPrivate: repo.IsPrivate, + RefName: refFullName, + }); err != nil { + log.Error("notifyWatchers: %v", err) + } +} + func (a *actionNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { data, err := json.Marshal(commits) if err != nil { |