Skip to content

Commit

Permalink
On merge of already closed PR redirect back to the pulls page (#10010)
Browse files Browse the repository at this point in the history
* On merge of already closed PR redirect back to the pulls page

* More redirects
* As per @6543

Co-Authored-By: 6543 <[email protected]>
  • Loading branch information
zeripath and 6543 committed Jan 27, 2020
1 parent 03cb168 commit 51f6a7a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,13 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
return
}
if issue.IsClosed {
ctx.NotFound("MergePullRequest", nil)
if issue.IsPull {
ctx.Flash.Error(ctx.Tr("repo.pulls.is_closed"))
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
return
}
ctx.Flash.Error(ctx.Tr("repo.issues.closed_title"))
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
return
}

Expand All @@ -691,12 +697,20 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
return
}
if !allowedMerge {
ctx.NotFound("MergePullRequest", nil)
ctx.Flash.Error(ctx.Tr("repo.pulls.update_not_allowed"))
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
return
}

if !pr.CanAutoMerge() || pr.HasMerged {
ctx.NotFound("MergePullRequest", nil)
if !pr.CanAutoMerge() {
ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_not_ready"))
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
return
}

if pr.HasMerged {
ctx.Flash.Error(ctx.Tr("repo.pulls.has_merged"))
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
return
}

Expand Down

0 comments on commit 51f6a7a

Please sign in to comment.