]> source.dussan.org Git - gitea.git/commit
Avoid returning without written ctx when posting PR (#31843)
authorJason Song <i@wolfogre.com>
Fri, 16 Aug 2024 17:04:54 +0000 (01:04 +0800)
committerGitHub <noreply@github.com>
Fri, 16 Aug 2024 17:04:54 +0000 (17:04 +0000)
commitacd7053e9d4968e8b9812ab379be9027ac8e7771
tree7138723583526cfb85f6e056882050000ed95e52
parent2010fbe06054b9d9cada430f1a60f45ac7689b93
Avoid returning without written ctx when posting PR (#31843)

Fix #31625.

If `pull_service.NewPullRequest` return an error which misses each `if`
check, `CompareAndPullRequestPost` will return immediately, since it
doesn't write the HTTP response, a 200 response with empty body will be
sent to clients.

```go
if err := pull_service.NewPullRequest(ctx, repo, pullIssue, labelIDs, attachments, pullRequest, assigneeIDs); err != nil {
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
} else if git.IsErrPushRejected(err) {
// ...
ctx.JSONError(flashError)
} else if errors.Is(err, user_model.ErrBlockedUser) {
// ...
ctx.JSONError(flashError)
} else if errors.Is(err, issues_model.ErrMustCollaborator) {
// ...
ctx.JSONError(flashError)
}
return
}
```

Not sure what kind of error can cause it to happen, so this PR just
expose it. And we can fix it when users report that creating PRs failed
with error responses.

It's all my guess since I cannot reproduce the problem, but even if it's
not related, the code here needs to be improved.
routers/web/repo/pull.go