aboutsummaryrefslogtreecommitdiffstats
path: root/modules/notification/webhook/webhook.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-11-06 14:43:03 +0800
committerGitHub <noreply@github.com>2019-11-06 14:43:03 +0800
commit8a84d82d5341ff6572e7c77f5779e2583ed45c25 (patch)
tree8cd399ebff88f2e10a76a01c117834b25a0c699f /modules/notification/webhook/webhook.go
parent36b8c081f6b9b642bc068158b3a893d027d06ba8 (diff)
downloadgitea-8a84d82d5341ff6572e7c77f5779e2583ed45c25.tar.gz
gitea-8a84d82d5341ff6572e7c77f5779e2583ed45c25.zip
Move repofiles webhooks to notification (#8807)
Diffstat (limited to 'modules/notification/webhook/webhook.go')
-rw-r--r--modules/notification/webhook/webhook.go47
1 files changed, 46 insertions, 1 deletions
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go
index 39c63edb05..6eb03d3ebc 100644
--- a/modules/notification/webhook/webhook.go
+++ b/modules/notification/webhook/webhook.go
@@ -6,6 +6,7 @@ package webhook
import (
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/setting"
@@ -562,6 +563,34 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
}
}
+func (m *webhookNotifier) NotifyCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
+ apiPusher := pusher.APIFormat()
+ apiRepo := repo.APIFormat(models.AccessModeNone)
+ refName := git.RefEndName(refFullName)
+
+ gitRepo, err := git.OpenRepository(repo.RepoPath())
+ if err != nil {
+ log.Error("OpenRepository[%s]: %v", repo.RepoPath(), err)
+ return
+ }
+
+ shaSum, err := gitRepo.GetBranchCommitID(refName)
+ if err != nil {
+ log.Error("GetBranchCommitID[%s]: %v", refFullName, err)
+ return
+ }
+
+ if err = webhook_module.PrepareWebhooks(repo, models.HookEventCreate, &api.CreatePayload{
+ Ref: refName,
+ Sha: shaSum,
+ RefType: refType,
+ Repo: apiRepo,
+ Sender: apiPusher,
+ }); err != nil {
+ log.Error("PrepareWebhooks: %v", err)
+ }
+}
+
func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {
if err := pr.LoadIssue(); err != nil {
log.Error("pr.LoadIssue: %v", err)
@@ -572,7 +601,7 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *m
return
}
- if err := webhook.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
+ if err := webhook_module.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
Action: api.HookIssueSynchronized,
Index: pr.Issue.Index,
PullRequest: pr.Issue.PullRequest.APIFormat(),
@@ -582,3 +611,19 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *m
log.Error("PrepareWebhooks [pull_id: %v]: %v", pr.ID, err)
}
}
+
+func (m *webhookNotifier) NotifyDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
+ apiPusher := pusher.APIFormat()
+ apiRepo := repo.APIFormat(models.AccessModeNone)
+ refName := git.RefEndName(refFullName)
+
+ if err := webhook_module.PrepareWebhooks(repo, models.HookEventDelete, &api.DeletePayload{
+ Ref: refName,
+ RefType: "branch",
+ PusherType: api.PusherTypeUser,
+ Repo: apiRepo,
+ Sender: apiPusher,
+ }); err != nil {
+ log.Error("PrepareWebhooks.(delete branch): %v", err)
+ }
+}