From 2dbf22255db681c137c92dca7362f6adf5462e2e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 5 Dec 2024 21:23:51 -0800 Subject: [PATCH] Fix bug --- models/migrations/migrations.go | 2 +- routers/api/v1/repo/pull.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 7eea8e8e76..ca5a9df128 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -369,7 +369,7 @@ func prepareMigrationTasks() []*migration { newMigration(309, "Improve Notification table indices", v1_23.ImproveNotificationTableIndices), newMigration(310, "Add Priority to ProtectedBranch", v1_23.AddPriorityToProtectedBranch), newMigration(311, "Add TimeEstimate to Issue table", v1_23.AddTimeEstimateColumnToIssueTable), - newMigration(310, "Add DeleteBranchAfterMerge to AutoMerge", v1_23.AddDeleteBranchAfterMergeForAutoMerge), + newMigration(312, "Add DeleteBranchAfterMerge to AutoMerge", v1_23.AddDeleteBranchAfterMergeForAutoMerge), } return preparedMigrations } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 1301f954d4..6fe4c439b6 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1084,9 +1084,13 @@ func MergePullRequest(ctx *context.APIContext) { } defer headRepo.Close() } - if err := pull_service.RetargetChildrenOnMerge(ctx, ctx.Doer, pr); err != nil { - ctx.Error(http.StatusInternalServerError, "RetargetChildrenOnMerge", err) - return + + // TODO: why only retarget same repository pull requests? + if setting.Repository.PullRequest.RetargetChildrenOnMerge && pr.BaseRepoID == pr.HeadRepoID { + if err := pull_service.RetargetBranchPulls(ctx, ctx.Doer, pr.HeadRepoID, pr.HeadBranch, pr.BaseBranch); err != nil { + ctx.Error(http.StatusInternalServerError, "RetargetBranchPulls", err) + return + } } if err := repo_service.DeleteBranch(ctx, ctx.Doer, pr.HeadRepo, headRepo, pr.HeadBranch, pr); err != nil { switch {