Skip to content

Commit c7f03bb

Browse files
committed
Cleanup error handling, add docs
1 parent 660b3d2 commit c7f03bb

File tree

6 files changed

+30
-21
lines changed

6 files changed

+30
-21
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@ ROUTER = console
10621062
;;
10631063
;; In addition to testing patches using the three-way merge method, re-test conflicting patches with git apply
10641064
;TEST_CONFLICTING_PATCHES_WITH_GIT_APPLY = false
1065+
;;
1066+
;; Retarget the child pull request to the parent pull request branch target
1067+
;RETARGET_CHILDREN_ON_MERGE = false
10651068

10661069
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10671070
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ In addition there is _`StaticRootPath`_ which can be set as a built-in at build
137137
- `POPULATE_SQUASH_COMMENT_WITH_COMMIT_MESSAGES`: **false**: In default squash-merge messages include the commit message of all commits comprising the pull request.
138138
- `ADD_CO_COMMITTER_TRAILERS`: **true**: Add co-authored-by and co-committed-by trailers to merge commit messages if committer does not match author.
139139
- `TEST_CONFLICTING_PATCHES_WITH_GIT_APPLY`: **false**: PR patches are tested using a three-way merge method to discover if there are conflicts. If this setting is set to **true**, conflicting patches will be retested using `git apply` - This was the previous behaviour in 1.18 (and earlier) but is somewhat inefficient. Please report if you find that this setting is required.
140+
- `RETARGET_CHILDREN_ON_MERGE`: **false**: Retarget the child pull request to the parent pull request branch target.
140141

141142
### Repository - Issue (`repository.issue`)
142143

modules/setting/repository.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ var (
8484
PopulateSquashCommentWithCommitMessages bool
8585
AddCoCommitterTrailers bool
8686
TestConflictingPatchesWithGitApply bool
87-
RetargetChildsOnClose bool
87+
RetargetChildrenOnMerge bool
8888
} `ini:"repository.pull-request"`
8989

9090
// Issue Setting
@@ -208,7 +208,7 @@ var (
208208
PopulateSquashCommentWithCommitMessages bool
209209
AddCoCommitterTrailers bool
210210
TestConflictingPatchesWithGitApply bool
211-
RetargetChildsOnClose bool
211+
RetargetChildrenOnMerge bool
212212
}{
213213
WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
214214
// Same as GitHub. See
@@ -223,6 +223,7 @@ var (
223223
DefaultMergeMessageOfficialApproversOnly: true,
224224
PopulateSquashCommentWithCommitMessages: false,
225225
AddCoCommitterTrailers: true,
226+
RetargetChildrenOnMerge: false,
226227
},
227228

228229
// Issue settings

routers/api/v1/repo/pull.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -904,12 +904,10 @@ func MergePullRequest(ctx *context.APIContext) {
904904
}
905905
defer headRepo.Close()
906906
}
907-
if setting.Repository.PullRequest.RetargetChildsOnClose && pr.BaseRepoID == pr.HeadRepoID {
908-
if err := pull_service.RebaseBranchPulls(ctx, ctx.Doer, pr.HeadRepoID, pr.HeadBranch, pr.BaseBranch); err != nil {
909-
log.Error("RebaseBranchPulls: %v", err)
910-
ctx.Error(http.StatusInternalServerError, "RebaseBranchPulls", err)
911-
return
912-
}
907+
if err := pull_service.RetargetChildrenOnMerge(ctx, ctx.Doer, pr); err != nil {
908+
log.Error("RetargetChildrenOnMerge: %v", err)
909+
ctx.Error(http.StatusInternalServerError, "RetargetChildrenOnMerge", err)
910+
return
913911
}
914912
if err := repo_service.DeleteBranch(ctx, ctx.Doer, pr.HeadRepo, headRepo, pr.HeadBranch); err != nil {
915913
switch {

routers/web/repo/pull.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,12 +1400,10 @@ func CleanUpPullRequest(ctx *context.Context) {
14001400
func deleteBranch(ctx *context.Context, pr *issues_model.PullRequest, gitRepo *git.Repository) {
14011401
fullBranchName := pr.HeadRepo.FullName() + ":" + pr.HeadBranch
14021402

1403-
if setting.Repository.PullRequest.RetargetChildsOnClose && pr.BaseRepoID == pr.HeadRepoID {
1404-
if err := pull_service.RebaseBranchPulls(ctx, ctx.Doer, pr.HeadRepoID, pr.HeadBranch, pr.BaseBranch); err != nil {
1405-
log.Error("RebaseBranchPulls: %v", err)
1406-
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
1407-
return
1408-
}
1403+
if err := pull_service.RetargetChildrenOnMerge(ctx, ctx.Doer, pr); err != nil {
1404+
log.Error("RetargetChildrenOnMerge: %v", err)
1405+
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
1406+
return
14091407
}
14101408

14111409
if err := repo_service.DeleteBranch(ctx, ctx.Doer, pr.HeadRepo, gitRepo, pr.HeadBranch); err != nil {

services/pull/pull.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,24 +497,32 @@ func (errs errlist) Error() string {
497497
return ""
498498
}
499499

500-
// RebaseBranchPulls change target branch for all pull requests who's base branch is the branch
501-
func RebaseBranchPulls(ctx context.Context, doer *user_model.User, repoID int64, branch, targetBranch string) error {
502-
prs, err := models.GetUnmergedPullRequestsByBaseInfo(repoID, branch)
500+
// RetargetChildrenOnMerge retarget children pull requests on merge if possible
501+
func RetargetChildrenOnMerge(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) error {
502+
if setting.Repository.PullRequest.RetargetChildrenOnMerge && pr.BaseRepoID == pr.HeadRepoID {
503+
return RetargetBranchPulls(ctx, doer, pr.HeadRepoID, pr.HeadBranch, pr.BaseBranch)
504+
}
505+
return nil
506+
}
507+
508+
// RetargetBranchPulls change target branch for all pull requests who's base branch is the branch
509+
func RetargetBranchPulls(ctx context.Context, doer *user_model.User, repoID int64, branch, targetBranch string) error {
510+
prs, err := issues_model.GetUnmergedPullRequestsByBaseInfo(repoID, branch)
503511
if err != nil {
504512
return err
505513
}
506514

507-
if err := models.PullRequestList(prs).LoadAttributes(); err != nil {
515+
if err := issues_model.PullRequestList(prs).LoadAttributes(); err != nil {
508516
return err
509517
}
510518

511519
var errs errlist
512520
for _, pr := range prs {
513-
if err = pr.Issue.LoadAttributes(); err != nil {
521+
if err = pr.Issue.LoadAttributes(ctx); err != nil {
514522
errs = append(errs, err)
515523
} else if err = ChangeTargetBranch(ctx, pr, doer, targetBranch); err != nil &&
516-
!models.IsErrIssueIsClosed(err) && !models.IsErrPullRequestHasMerged(err) &&
517-
!models.IsErrPullRequestAlreadyExists(err) {
524+
!issues_model.IsErrIssueIsClosed(err) && !models.IsErrPullRequestHasMerged(err) &&
525+
!issues_model.IsErrPullRequestAlreadyExists(err) {
518526
errs = append(errs, err)
519527
}
520528
}

0 commit comments

Comments
 (0)