Skip to content

Redirect open PRs when the target branch is deleted through merging a PR #28539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
25 changes: 25 additions & 0 deletions routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,31 @@ func MergePullRequest(ctx *context.Context) {
return
}

pullRequestsToHead, err := issues_model.GetUnmergedPullRequestsByBaseInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
if err != nil {
ctx.ServerError("GetUnmergedPullRequestsByBaseInfo", err)
return
}

for _, prToHead := range pullRequestsToHead {
if prToHead.BaseRepoID != pr.BaseRepoID {
continue
}

err = prToHead.LoadIssue(ctx)
if err != nil {
ctx.ServerError(fmt.Sprintf("LoadIssueForPullRequest[%d]", prToHead.ID), err)
return
}
prToHead.Issue.Repo = ctx.Repo.Repository

err = pull_service.ChangeTargetBranch(ctx, prToHead, ctx.Doer, pr.BaseBranch)
if err != nil {
ctx.ServerError(fmt.Sprintf("ChangeTargetBranch[%d]", prToHead.ID), err)
return
}
}

var headRepo *git.Repository
if ctx.Repo != nil && ctx.Repo.Repository != nil && pr.HeadRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
headRepo = ctx.Repo.GitRepo
Expand Down