@@ -31,7 +31,6 @@ import (
3131 "code.gitea.io/gitea/modules/util"
3232 webhook_module "code.gitea.io/gitea/modules/webhook"
3333 notify_service "code.gitea.io/gitea/services/notify"
34- pull_service "code.gitea.io/gitea/services/pull"
3534 files_service "code.gitea.io/gitea/services/repository/files"
3635
3736 "xorm.io/builder"
@@ -468,7 +467,7 @@ var (
468467)
469468
470469// DeleteBranch delete branch
471- func DeleteBranch (ctx context.Context , doer * user_model.User , repo * repo_model.Repository , gitRepo * git.Repository , branchName string ) error {
470+ func DeleteBranch (ctx context.Context , doer * user_model.User , repo * repo_model.Repository , gitRepo * git.Repository , branchName string , pr * issues_model. PullRequest ) error {
472471 perm , err := access_model .GetUserRepoPermission (ctx , repo , doer )
473472 if err != nil {
474473 return err
@@ -515,6 +514,12 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
515514 }
516515 }
517516
517+ if pr != nil {
518+ if err := issues_model .AddDeletePRBranchComment (ctx , doer , pr .BaseRepo , pr .Issue .ID , pr .HeadBranch ); err != nil {
519+ return fmt .Errorf ("DeleteBranch: %v" , err )
520+ }
521+ }
522+
518523 return gitRepo .DeleteBranch (branchName , git.DeleteBranchOptions {
519524 Force : true ,
520525 })
@@ -541,23 +546,6 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
541546 return nil
542547}
543548
544- func DeletePullRequestHeadBranch (ctx context.Context , pr * issues_model.PullRequest , doer * user_model.User , headGitRepo * git.Repository ) error {
545- if err := pull_service .RetargetChildrenOnMerge (ctx , doer , pr ); err != nil {
546- return err
547- }
548-
549- if err := DeleteBranch (ctx , doer , pr .HeadRepo , headGitRepo , pr .HeadBranch ); err != nil {
550- return err
551- }
552-
553- if err := issues_model .AddDeletePRBranchComment (ctx , doer , pr .BaseRepo , pr .IssueID , pr .HeadBranch ); err != nil {
554- // Do not fail here as branch has already been deleted
555- log .Error ("AddDeletePRBranchComment: %v" , err )
556- }
557-
558- return nil
559- }
560-
561549type BranchSyncOptions struct {
562550 RepoID int64
563551}
0 commit comments