|
|
@ -14,8 +14,6 @@ import (
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
"code.gitea.io/gitea/modules/notification"
|
|
|
|
"code.gitea.io/gitea/modules/notification"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"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.
|
|
|
|
// CommitRepoActionOptions represent options of a new commit action.
|
|
|
@ -113,81 +111,23 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
|
|
|
|
return fmt.Errorf("NotifyWatchers: %v", err)
|
|
|
|
return fmt.Errorf("NotifyWatchers: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
apiPusher := pusher.APIFormat()
|
|
|
|
var isHookEventPush = true
|
|
|
|
apiRepo := repo.APIFormat(models.AccessModeNone)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var shaSum string
|
|
|
|
|
|
|
|
var isHookEventPush = false
|
|
|
|
|
|
|
|
switch opType {
|
|
|
|
switch opType {
|
|
|
|
case models.ActionCommitRepo: // Push
|
|
|
|
case models.ActionCommitRepo: // Push
|
|
|
|
isHookEventPush = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isNewBranch {
|
|
|
|
if isNewBranch {
|
|
|
|
gitRepo, err := git.OpenRepository(repo.RepoPath())
|
|
|
|
notification.NotifyCreateRef(pusher, repo, "branch", opts.RefFullName)
|
|
|
|
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)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case models.ActionDeleteBranch: // Delete Branch
|
|
|
|
case models.ActionDeleteBranch: // Delete Branch
|
|
|
|
isHookEventPush = true
|
|
|
|
notification.NotifyDeleteRef(pusher, repo, "branch", opts.RefFullName)
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case models.ActionPushTag: // Create
|
|
|
|
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
|
|
|
|
case models.ActionDeleteTag: // Delete Tag
|
|
|
|
isHookEventPush = true
|
|
|
|
notification.NotifyDeleteRef(pusher, repo, "tag", opts.RefFullName)
|
|
|
|
|
|
|
|
default:
|
|
|
|
if err = webhook.PrepareWebhooks(repo, models.HookEventDelete, &api.DeletePayload{
|
|
|
|
isHookEventPush = false
|
|
|
|
Ref: refName,
|
|
|
|
|
|
|
|
RefType: "tag",
|
|
|
|
|
|
|
|
PusherType: api.PusherTypeUser,
|
|
|
|
|
|
|
|
Repo: apiRepo,
|
|
|
|
|
|
|
|
Sender: apiPusher,
|
|
|
|
|
|
|
|
}); err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("PrepareWebhooks.(delete tag): %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if isHookEventPush {
|
|
|
|
if isHookEventPush {
|
|
|
|