Skip to content

Commit 2382f1b

Browse files
authored
fix 500 when reviewer is deleted with integration tests (#6856)
1 parent dab38c3 commit 2382f1b

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

integrations/pull_review_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
package integrations
5+
6+
import (
7+
"net/http"
8+
"testing"
9+
)
10+
11+
func TestPullView_ReviewerMissed(t *testing.T) {
12+
prepareTestEnv(t)
13+
session := loginUser(t, "user1")
14+
15+
req := NewRequest(t, "GET", "/pulls")
16+
session.MakeRequest(t, req, http.StatusOK)
17+
18+
req = NewRequest(t, "GET", "/user2/repo1/pulls/3")
19+
session.MakeRequest(t, req, http.StatusOK)
20+
}

models/fixtures/comment.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,15 @@
5252
tree_path: "README.md"
5353
created_unix: 946684812
5454
invalidated: true
55+
56+
-
57+
id: 7
58+
type: 21 # code comment
59+
poster_id: 100
60+
issue_id: 3
61+
content: "a review from a deleted user"
62+
line: -4
63+
review_id: 10
64+
tree_path: "README.md"
65+
created_unix: 946684812
66+
invalidated: true

models/fixtures/review.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,12 @@
7070
content: "New review 3 rejected"
7171
updated_unix: 946684810
7272
created_unix: 946684810
73+
74+
-
75+
id: 10
76+
type: 3
77+
reviewer_id: 100
78+
issue_id: 3
79+
content: "a deleted user's review"
80+
updated_unix: 946684810
81+
created_unix: 946684810

models/issue_comment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ func (c *Comment) loadReview(e Engine) (err error) {
447447
return err
448448
}
449449
}
450+
c.Review.Issue = c.Issue
450451
return nil
451452
}
452453

routers/repo/issue.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,8 @@ func ViewIssue(ctx *context.Context) {
773773
// Render comments and and fetch participants.
774774
participants[0] = issue.Poster
775775
for _, comment = range issue.Comments {
776+
comment.Issue = issue
777+
776778
if err := comment.LoadPoster(); err != nil {
777779
ctx.ServerError("LoadPoster", err)
778780
return
@@ -850,8 +852,11 @@ func ViewIssue(ctx *context.Context) {
850852
continue
851853
}
852854
if err = comment.Review.LoadAttributes(); err != nil {
853-
ctx.ServerError("Review.LoadAttributes", err)
854-
return
855+
if !models.IsErrUserNotExist(err) {
856+
ctx.ServerError("Review.LoadAttributes", err)
857+
return
858+
}
859+
comment.Review.Reviewer = models.NewGhostUser()
855860
}
856861
if err = comment.Review.LoadCodeComments(); err != nil {
857862
ctx.ServerError("Review.LoadCodeComments", err)

0 commit comments

Comments
 (0)