From ae3e77e1083ddc4e8a5f9402dfddc7a999f0d824 Mon Sep 17 00:00:00 2001 From: Brad Albright Date: Wed, 18 Dec 2019 22:07:56 -0600 Subject: [PATCH 1/2] fixed so when deleting a branch after merging a PR, a webhook is triggered --- routers/repo/pull.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/routers/repo/pull.go b/routers/repo/pull.go index e4b4a5ac4987e..410e608a47f71 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -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" @@ -928,6 +929,21 @@ func CleanUpPullRequest(ctx *context.Context) { return } + if err := repofiles.PushUpdate( + ctx.Repo.Repository, + pr.HeadBranch, + repofiles.PushUpdateOptions{ + RefFullName: git.BranchPrefix + pr.HeadBranch, + OldCommitID: branchCommitID, + NewCommitID: git.EmptySHA, + PusherID: ctx.User.ID, + PusherName: ctx.User.Name, + RepoUserName: ctx.Repo.Owner.Name, + RepoName: ctx.Repo.Repository.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) From b24b56b3e8bdadc1040013b165b83b17e51e905b Mon Sep 17 00:00:00 2001 From: Brad Albright Date: Fri, 20 Dec 2019 08:23:06 -0600 Subject: [PATCH 2/2] changed to use pr.HeadRepo instead of ctx.Repo when sending webhook for a deletion of branch after merging pr --- routers/repo/pull.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 410e608a47f71..932e99290b441 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -930,7 +930,7 @@ func CleanUpPullRequest(ctx *context.Context) { } if err := repofiles.PushUpdate( - ctx.Repo.Repository, + pr.HeadRepo, pr.HeadBranch, repofiles.PushUpdateOptions{ RefFullName: git.BranchPrefix + pr.HeadBranch, @@ -938,8 +938,8 @@ func CleanUpPullRequest(ctx *context.Context) { NewCommitID: git.EmptySHA, PusherID: ctx.User.ID, PusherName: ctx.User.Name, - RepoUserName: ctx.Repo.Owner.Name, - RepoName: ctx.Repo.Repository.Name, + RepoUserName: pr.HeadRepo.Owner.Name, + RepoName: pr.HeadRepo.Name, }); err != nil { log.Error("Update: %v", err) }