@ -46,6 +46,8 @@ const (
ActionReopenIssue // 13
ActionReopenIssue // 13
ActionClosePullRequest // 14
ActionClosePullRequest // 14
ActionReopenPullRequest // 15
ActionReopenPullRequest // 15
ActionDeleteTag // 16
ActionDeleteBranch // 17
)
)
var (
var (
@ -554,6 +556,12 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
// Check it's tag push or branch.
// Check it's tag push or branch.
if strings . HasPrefix ( opts . RefFullName , git . TagPrefix ) {
if strings . HasPrefix ( opts . RefFullName , git . TagPrefix ) {
opType = ActionPushTag
opType = ActionPushTag
if opts . NewCommitID == git . EmptySHA {
opType = ActionDeleteTag
}
opts . Commits = & PushCommits { }
} else if opts . NewCommitID == git . EmptySHA {
opType = ActionDeleteBranch
opts . Commits = & PushCommits { }
opts . Commits = & PushCommits { }
} else {
} else {
// if not the first commit, set the compare URL.
// if not the first commit, set the compare URL.
@ -599,40 +607,38 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
apiRepo := repo . APIFormat ( AccessModeNone )
apiRepo := repo . APIFormat ( AccessModeNone )
var shaSum string
var shaSum string
var isHookEventPush = false
switch opType {
switch opType {
case ActionCommitRepo : // Push
case ActionCommitRepo : // Push
if err = PrepareWebhooks ( repo , HookEventPush , & api . PushPayload {
isHookEventPush = true
Ref : opts . RefFullName ,
Before : opts . OldCommitID ,
After : opts . NewCommitID ,
CompareURL : setting . AppURL + opts . Commits . CompareURL ,
Commits : opts . Commits . ToAPIPayloadCommits ( repo . HTMLURL ( ) ) ,
Repo : apiRepo ,
Pusher : apiPusher ,
Sender : apiPusher ,
} ) ; err != nil {
return fmt . Errorf ( "PrepareWebhooks: %v" , err )
}
if isNewBranch {
if isNewBranch {
gitRepo , err := git . OpenRepository ( repo . RepoPath ( ) )
gitRepo , err := git . OpenRepository ( repo . RepoPath ( ) )
if err != nil {
if err != nil {
log . Error ( 4 , "OpenRepository[%s]: %v" , repo . RepoPath ( ) , err )
log . Error ( 4 , "OpenRepository[%s]: %v" , repo . RepoPath ( ) , err )
}
}
shaSum , err = gitRepo . GetBranchCommitID ( refName )
shaSum , err = gitRepo . GetBranchCommitID ( refName )
if err != nil {
if err != nil {
log . Error ( 4 , "GetBranchCommitID[%s]: %v" , opts . RefFullName , err )
log . Error ( 4 , "GetBranchCommitID[%s]: %v" , opts . RefFullName , err )
}
}
retu rn PrepareWebhooks ( repo , HookEventCreate , & api . CreatePayload {
if e rr = PrepareWebhooks ( repo , HookEventCreate , & api . CreatePayload {
Ref : refName ,
Ref : refName ,
Sha : shaSum ,
Sha : shaSum ,
RefType : "branch" ,
RefType : "branch" ,
Repo : apiRepo ,
Repo : apiRepo ,
Sender : apiPusher ,
Sender : apiPusher ,
} )
} ) ; err != nil {
return fmt . Errorf ( "PrepareWebhooks: %v" , err )
}
}
}
case ActionDeleteBranch : // Delete Branch
isHookEventPush = true
case ActionPushTag : // Create
case ActionPushTag : // Create
isHookEventPush = true
gitRepo , err := git . OpenRepository ( repo . RepoPath ( ) )
gitRepo , err := git . OpenRepository ( repo . RepoPath ( ) )
if err != nil {
if err != nil {
log . Error ( 4 , "OpenRepository[%s]: %v" , repo . RepoPath ( ) , err )
log . Error ( 4 , "OpenRepository[%s]: %v" , repo . RepoPath ( ) , err )
@ -641,13 +647,32 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
if err != nil {
if err != nil {
log . Error ( 4 , "GetTagCommitID[%s]: %v" , opts . RefFullName , err )
log . Error ( 4 , "GetTagCommitID[%s]: %v" , opts . RefFullName , err )
}
}
retu rn PrepareWebhooks ( repo , HookEventCreate , & api . CreatePayload {
if e rr = PrepareWebhooks ( repo , HookEventCreate , & api . CreatePayload {
Ref : refName ,
Ref : refName ,
Sha : shaSum ,
Sha : shaSum ,
RefType : "tag" ,
RefType : "tag" ,
Repo : apiRepo ,
Repo : apiRepo ,
Sender : apiPusher ,
Sender : apiPusher ,
} )
} ) ; err != nil {
return fmt . Errorf ( "PrepareWebhooks: %v" , err )
}
case ActionDeleteTag : // Delete Tag
isHookEventPush = true
}
if isHookEventPush {
if err = PrepareWebhooks ( repo , HookEventPush , & api . PushPayload {
Ref : opts . RefFullName ,
Before : opts . OldCommitID ,
After : opts . NewCommitID ,
CompareURL : setting . AppURL + opts . Commits . CompareURL ,
Commits : opts . Commits . ToAPIPayloadCommits ( repo . HTMLURL ( ) ) ,
Repo : apiRepo ,
Pusher : apiPusher ,
Sender : apiPusher ,
} ) ; err != nil {
return fmt . Errorf ( "PrepareWebhooks: %v" , err )
}
}
}
return nil
return nil