|
|
|
@ -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 { |
|
|
|
|