gitea/routers
Giteabot 1cf8f69b38
Avoid returning without written ctx when posting PR (#31843) (#31848)
Backport #31843 by @wolfogre

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.

Co-authored-by: Jason Song <i@wolfogre.com>
2024-08-16 13:50:12 -04:00
..
api fix(api): owner ID should be zero when created repo secret (#31715) (#31811) 2024-08-10 00:21:51 +08:00
common Fix missing images in editor preview due to wrong links (#31299) (#31393) 2024-06-17 15:07:21 +08:00
install Always load or generate oauth2 jwt secret (#30942) (#30978) 2024-05-14 15:00:38 +00:00
private Fix protected branch files detection on pre_receive hook (#31778) (#31796) 2024-08-08 03:08:30 +00:00
utils Refactor external URL detection (#29973) 2024-03-22 04:32:40 +08:00
web Avoid returning without written ctx when posting PR (#31843) (#31848) 2024-08-16 13:50:12 -04:00
init.go Make sure git version&feature are always prepared (#30877) (#30879) 2024-05-07 02:07:33 +00:00