Skip to content

Commit

Permalink
CreateBranch-hook has shasum. Use the full ref for fetching shasum
Browse files Browse the repository at this point in the history
  • Loading branch information
bkcsoft committed Nov 29, 2016
1 parent 55bd3ed commit 5e7b220
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {

apiPusher := pusher.APIFormat()
apiRepo := repo.APIFormat(nil)

var shaSum string
switch opType {
case ActionCommitRepo: // Push
if err = PrepareWebhooks(repo, HookEventPush, &api.PushPayload{
Expand All @@ -556,16 +558,32 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
}

if isNewBranch {
gitRepo, err := git.OpenRepository(repo.RepoPath())
if err != nil {
log.Error(4, "OpenRepository[%s]: %v", repo.RepoPath(), err)
}
shaSum, err = gitRepo.GetBranchCommitID(opts.RefFullName)
if err != nil {
log.Error(4, "GetBranchCommitID[%s]: %v", opts.RefFullName, err)
}
return PrepareWebhooks(repo, HookEventCreate, &api.CreatePayload{
Ref: refName,
Sha: shaSum,
RefType: "branch",
Repo: apiRepo,
Sender: apiPusher,
})
}

case ActionPushTag: // Create
shaSum := git.OpenRepository(repo.RepoPath()).GetTagCommitID(refName)
gitRepo, err := git.OpenRepository(repo.RepoPath())
if err != nil {
log.Error(4, "OpenRepository[%s]: %v", repo.RepoPath(), err)
}
shaSum, err = gitRepo.GetTagCommitID(opts.RefFullName)
if err != nil {
log.Error(4, "GetTagCommitID[%s]: %v", opts.RefFullName, err)
}
return PrepareWebhooks(repo, HookEventCreate, &api.CreatePayload{
Ref: refName,
Sha: shaSum,
Expand Down

0 comments on commit 5e7b220

Please sign in to comment.