Skip to content

Commit

Permalink
Trigger webhook when deleting a branch after merging a PR (#9424)
Browse files Browse the repository at this point in the history
* fixed so when deleting a branch after merging a PR, a webhook is triggered

* changed to use pr.HeadRepo instead of ctx.Repo when sending webhook for a deletion of branch after merging pr

Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
  • Loading branch information
3 people authored and zeripath committed Dec 25, 2019
1 parent 8e65572 commit f88715e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/repofiles"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/gitdiff"
Expand Down Expand Up @@ -928,6 +929,21 @@ func CleanUpPullRequest(ctx *context.Context) {
return
}

if err := repofiles.PushUpdate(
pr.HeadRepo,
pr.HeadBranch,
repofiles.PushUpdateOptions{
RefFullName: git.BranchPrefix + pr.HeadBranch,
OldCommitID: branchCommitID,
NewCommitID: git.EmptySHA,
PusherID: ctx.User.ID,
PusherName: ctx.User.Name,
RepoUserName: pr.HeadRepo.Owner.Name,
RepoName: pr.HeadRepo.Name,
}); err != nil {
log.Error("Update: %v", err)
}

if err := models.AddDeletePRBranchComment(ctx.User, pr.BaseRepo, issue.ID, pr.HeadBranch); err != nil {
// Do not fail here as branch has already been deleted
log.Error("DeleteBranch: %v", err)
Expand Down

0 comments on commit f88715e

Please sign in to comment.