Skip to content

Commit 3d4215f

Browse files
committed
Fix bug when delete branch don't close related PRs
1 parent fe18a85 commit 3d4215f

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,7 @@ branch.delete_html = Delete Branch
19671967
branch.delete_desc = Deleting a branch is permanent. It <strong>CANNOT</strong> be undone. Continue?
19681968
branch.deletion_success = Branch '%s' has been deleted.
19691969
branch.deletion_failed = Failed to delete branch '%s'.
1970+
branch.delete_branch_close_prs_failed = Failed to close related pull requests when delete branch '%s'.
19701971
branch.delete_branch_has_new_commits = Branch '%s' cannot be deleted because new commits have been added after merging.
19711972
branch.create_branch = Create branch <strong>%s</strong>
19721973
branch.create_from = from '%s'

routers/api/v1/repo/branch.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ func DeleteBranch(ctx *context.APIContext) {
155155
return
156156
}
157157

158+
if err := pull_service.CloseBranchPulls(ctx.User, ctx.Repo.Repository.ID, branchName); err != nil {
159+
log.Error("CloseBranchPulls: %v", err)
160+
return
161+
}
162+
158163
// Don't return error below this
159164
if err := repo_service.PushUpdate(
160165
&repo_module.PushUpdateOptions{

routers/repo/branch.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"code.gitea.io/gitea/modules/web"
2222
"code.gitea.io/gitea/routers/utils"
2323
"code.gitea.io/gitea/services/forms"
24+
pull_service "code.gitea.io/gitea/services/pull"
2425
release_service "code.gitea.io/gitea/services/release"
2526
repo_service "code.gitea.io/gitea/services/repository"
2627
)
@@ -183,6 +184,11 @@ func deleteBranch(ctx *context.Context, branchName string) error {
183184
return err
184185
}
185186

187+
if err := pull_service.CloseBranchPulls(ctx.User, ctx.Repo.Repository.ID, branchName); err != nil {
188+
log.Error("CloseBranchPulls: %v", err)
189+
return err
190+
}
191+
186192
// Don't return error below this
187193
if err := repo_service.PushUpdate(
188194
&repo_module.PushUpdateOptions{

routers/repo/pull.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,12 @@ func CleanUpPullRequest(ctx *context.Context) {
12261226
return
12271227
}
12281228

1229+
if err := pull_service.CloseBranchPulls(ctx.User, pr.HeadRepo.ID, pr.HeadBranch); err != nil {
1230+
log.Error("CloseBranchPulls: %v", err)
1231+
ctx.Flash.Error(ctx.Tr("repo.branch.delete_branch_close_prs_failed", fullBranchName))
1232+
return
1233+
}
1234+
12291235
if err := repo_service.PushUpdate(
12301236
&repo_module.PushUpdateOptions{
12311237
RefFullName: git.BranchPrefix + pr.HeadBranch,

0 commit comments

Comments
 (0)