diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-03 14:59:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-03 14:59:26 +0800 |
commit | 022d2d8beb6297016ed26b0090c6a4a4ac404437 (patch) | |
tree | aa6ca5fa9415661d02e97b66251166d456efa18e /modules/notification/webhook | |
parent | fe7a6d9bfcbcf53bfe2d24f4d8e7463c897b9389 (diff) | |
download | gitea-022d2d8beb6297016ed26b0090c6a4a4ac404437.tar.gz gitea-022d2d8beb6297016ed26b0090c6a4a4ac404437.zip |
Move push commits events to notification (#8783)
* Move push commits events to notification
* Update modules/notification/base/null.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
Diffstat (limited to 'modules/notification/webhook')
-rw-r--r-- | modules/notification/webhook/webhook.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go index a969ad74f7..13d33e1011 100644 --- a/modules/notification/webhook/webhook.go +++ b/modules/notification/webhook/webhook.go @@ -8,6 +8,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification/base" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" webhook_module "code.gitea.io/gitea/modules/webhook" ) @@ -461,3 +462,25 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *m log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) } } + +func (m *webhookNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *models.PushCommits) { + apiPusher := pusher.APIFormat() + apiCommits, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL()) + if err != nil { + log.Error("commits.ToAPIPayloadCommits failed: %v", err) + return + } + + if err := webhook_module.PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{ + Ref: refName, + Before: oldCommitID, + After: newCommitID, + CompareURL: setting.AppURL + commits.CompareURL, + Commits: apiCommits, + Repo: repo.APIFormat(models.AccessModeOwner), + Pusher: apiPusher, + Sender: apiPusher, + }); err != nil { + log.Error("PrepareWebhooks: %v", err) + } +} |