Honor delete branch on merge repo setting when using merge API (#35488) (#35726)

Backport #35488 by @kemzeb

Fix #35463.

---------

Co-authored-by: Kemal Zebari <60799661+kemzeb@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot
2025-10-23 00:41:40 +08:00
committed by GitHub
parent c84d17b1bb
commit 0925089b5e
20 changed files with 335 additions and 265 deletions

View File

@@ -730,3 +730,24 @@ func SetMerged(ctx context.Context, pr *issues_model.PullRequest, mergedCommitID
return true, nil
})
}
func ShouldDeleteBranchAfterMerge(ctx context.Context, userOption *bool, repo *repo_model.Repository, pr *issues_model.PullRequest) (bool, error) {
if pr.Flow != issues_model.PullRequestFlowGithub {
// only support GitHub workflow (branch-based)
// for agit workflow, there is no branch, so nothing to delete
// TODO: maybe in the future, it should delete the "agit reference (refs/for/xxxx)"?
return false, nil
}
// if user has set an option, respect it
if userOption != nil {
return *userOption, nil
}
// otherwise, use repository default
prUnit, err := repo.GetUnit(ctx, unit.TypePullRequests)
if err != nil {
return false, err
}
return prUnit.PullRequestsConfig().DefaultDeleteBranchAfterMerge, nil
}