diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-06 14:43:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-06 14:43:03 +0800 |
commit | 8a84d82d5341ff6572e7c77f5779e2583ed45c25 (patch) | |
tree | 8cd399ebff88f2e10a76a01c117834b25a0c699f /modules/repofiles | |
parent | 36b8c081f6b9b642bc068158b3a893d027d06ba8 (diff) | |
download | gitea-8a84d82d5341ff6572e7c77f5779e2583ed45c25.tar.gz gitea-8a84d82d5341ff6572e7c77f5779e2583ed45c25.zip |
Move repofiles webhooks to notification (#8807)
Diffstat (limited to 'modules/repofiles')
-rw-r--r-- | modules/repofiles/action.go | 74 |
1 files changed, 7 insertions, 67 deletions
diff --git a/modules/repofiles/action.go b/modules/repofiles/action.go index e5f6bf8718..996363863d 100644 --- a/modules/repofiles/action.go +++ b/modules/repofiles/action.go @@ -14,8 +14,6 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" - api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/webhook" ) // CommitRepoActionOptions represent options of a new commit action. @@ -113,81 +111,23 @@ func CommitRepoAction(opts CommitRepoActionOptions) error { return fmt.Errorf("NotifyWatchers: %v", err) } - apiPusher := pusher.APIFormat() - apiRepo := repo.APIFormat(models.AccessModeNone) - - var shaSum string - var isHookEventPush = false + var isHookEventPush = true switch opType { case models.ActionCommitRepo: // Push - isHookEventPush = true - if isNewBranch { - gitRepo, err := git.OpenRepository(repo.RepoPath()) - if err != nil { - log.Error("OpenRepository[%s]: %v", repo.RepoPath(), err) - } - - shaSum, err = gitRepo.GetBranchCommitID(refName) - if err != nil { - log.Error("GetBranchCommitID[%s]: %v", opts.RefFullName, err) - } - if err = webhook.PrepareWebhooks(repo, models.HookEventCreate, &api.CreatePayload{ - Ref: refName, - Sha: shaSum, - RefType: "branch", - Repo: apiRepo, - Sender: apiPusher, - }); err != nil { - return fmt.Errorf("PrepareWebhooks: %v", err) - } + notification.NotifyCreateRef(pusher, repo, "branch", opts.RefFullName) } case models.ActionDeleteBranch: // Delete Branch - isHookEventPush = true - - if err = webhook.PrepareWebhooks(repo, models.HookEventDelete, &api.DeletePayload{ - Ref: refName, - RefType: "branch", - PusherType: api.PusherTypeUser, - Repo: apiRepo, - Sender: apiPusher, - }); err != nil { - return fmt.Errorf("PrepareWebhooks.(delete branch): %v", err) - } + notification.NotifyDeleteRef(pusher, repo, "branch", opts.RefFullName) case models.ActionPushTag: // Create - isHookEventPush = true + notification.NotifyCreateRef(pusher, repo, "tag", opts.RefFullName) - gitRepo, err := git.OpenRepository(repo.RepoPath()) - if err != nil { - log.Error("OpenRepository[%s]: %v", repo.RepoPath(), err) - } - shaSum, err = gitRepo.GetTagCommitID(refName) - if err != nil { - log.Error("GetTagCommitID[%s]: %v", opts.RefFullName, err) - } - if err = webhook.PrepareWebhooks(repo, models.HookEventCreate, &api.CreatePayload{ - Ref: refName, - Sha: shaSum, - RefType: "tag", - Repo: apiRepo, - Sender: apiPusher, - }); err != nil { - return fmt.Errorf("PrepareWebhooks: %v", err) - } case models.ActionDeleteTag: // Delete Tag - isHookEventPush = true - - if err = webhook.PrepareWebhooks(repo, models.HookEventDelete, &api.DeletePayload{ - Ref: refName, - RefType: "tag", - PusherType: api.PusherTypeUser, - Repo: apiRepo, - Sender: apiPusher, - }); err != nil { - return fmt.Errorf("PrepareWebhooks.(delete tag): %v", err) - } + notification.NotifyDeleteRef(pusher, repo, "tag", opts.RefFullName) + default: + isHookEventPush = false } if isHookEventPush { |