1
1
mirror of https://github.com/go-gitea/gitea synced 2025-10-30 10:58:27 +00:00

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

Fix #35463.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Kemal Zebari
2025-10-21 22:06:56 -07:00
committed by GitHub
parent 5f0697243c
commit a9f2ea720b
20 changed files with 334 additions and 264 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
}