Skip to content
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

[WIP] Refactor review related code #28544

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
4568fce
add index to columns we use filter
6543 Dec 19, 2023
8f75edc
database done right!!!
6543 Dec 19, 2023
d54ec89
single source of truth for reviewType who affect reviews
6543 Dec 20, 2023
1c27639
rename func to be more apropriate
6543 Dec 20, 2023
d248a0a
use introduced GetReviewOption
6543 Dec 20, 2023
9d44369
CreateReview now make sure to clean up and not leafe reviews in stran…
6543 Dec 20, 2023
9f34f03
note todo
6543 Dec 20, 2023
189db73
Update models/issues/review.go
6543 Dec 20, 2023
70b1b6d
remove ReviewID on CommentTypeReviewRequest as its not important and …
6543 Dec 20, 2023
1ace570
wrap errors
6543 Dec 20, 2023
fd51505
finish
6543 Dec 20, 2023
4481841
not use anymore
6543 Dec 20, 2023
2bba3bb
RequestReview get deleted on review. So we dont have to try to load t…
6543 Dec 20, 2023
cf0f77d
Clean up old reviews on creating a new one
6543 Dec 20, 2023
3c21bd7
func caller use the created comment to retrieve created review too
6543 Dec 20, 2023
05db236
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Dec 20, 2023
3667b97
Merge branch 'main' into no_error-when-notfound-is-expected
6543 Dec 20, 2023
9245e65
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Dec 20, 2023
8e643a1
Merge branch 'main' into pull_review_fixfix-builder
6543 Dec 20, 2023
aa70e2e
fix conflict
6543 Dec 20, 2023
369bf6b
Merge branch 'main' into no_error-when-notfound-is-expected
6543 Dec 21, 2023
9a71752
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Dec 21, 2023
a6adb7e
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Dec 21, 2023
e08e306
else if
6543 Dec 21, 2023
4858468
Merge branch 'main' into no_error-when-notfound-is-expected
6543 Dec 21, 2023
5810f61
Merge branch 'main' into pull_review_fixfix-builder
6543 Dec 22, 2023
00abbf6
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Dec 23, 2023
8a06ccb
handle ReviewTypePending
6543 Dec 23, 2023
91e3b66
Merge branch 'cleanup_old-reviews-on-review' into pull_review_fixfix-…
6543 Dec 23, 2023
92e237c
Merge branch 'main' into no_error-when-notfound-is-expected
6543 Dec 23, 2023
9fcea4c
Update models/issues/review.go
6543 Dec 23, 2023
3729221
add back
6543 Dec 30, 2023
e78ad74
Merge branch 'main' into no_error-when-notfound-is-expected
6543 Dec 30, 2023
dcad850
Merge branch 'main' into no_error-when-notfound-is-expected
6543 Dec 31, 2023
b03faf4
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Jan 13, 2024
6406fd4
Merge branch 'main' into no_error-when-notfound-is-expected
6543 Jan 13, 2024
ec62290
add note why we do skip it
6543 Jan 13, 2024
bcdebcc
Merge branch 'no_error-when-notfound-is-expected' into pull_review_fi…
6543 Jan 19, 2024
726e7ba
Merge branch 'cleanup_old-reviews-on-review' into pull_review_fixfix-…
6543 Jan 19, 2024
b775268
Merge branch 'main' into pull_review_fixfix-builder
6543 Jan 19, 2024
4d4c6d7
fix merge conflict resolve
6543 Jan 19, 2024
0df942a
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Jan 19, 2024
c2d62ae
Merge branch 'main' into no_error-when-notfound-is-expected
6543 Jan 19, 2024
84024c1
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Feb 12, 2024
090dde4
Merge branch 'main' into no_error-when-notfound-is-expected
6543 Feb 12, 2024
34ea361
ignore error
6543 Feb 12, 2024
67208a1
Merge branch 'main' into no_error-when-notfound-is-expected
6543 Feb 12, 2024
7e26578
Merge branch 'main' into pull_review_fixfix-builder
6543 Feb 12, 2024
f1b38c0
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Feb 12, 2024
ba24e26
ignore error msg
6543 Feb 12, 2024
2d0d3b4
Update models/issues/comment_list.go
6543 Feb 12, 2024
ee71a43
Merge branch 'no_error-when-notfound-is-expected' into pull_review_fi…
6543 Feb 12, 2024
1eb0a84
Merge branch 'cleanup_old-reviews-on-review' into pull_review_fixfix-…
6543 Feb 12, 2024
79e50b5
Merge branch 'main' into pull_review_fixfix-builder
6543 Feb 13, 2024
f4fbcf5
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Feb 14, 2024
d4049d9
return result for unittest.AssertCount* helper func
6543 Feb 15, 2024
2db7e7c
Add TestAPIPullReviewStayDismissed test
6543 Feb 15, 2024
18dc9b3
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Feb 15, 2024
8bc501b
Merge branch 'cleanup_old-reviews-on-review' into pull_review_fixfix-…
6543 Feb 15, 2024
758dd63
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Feb 15, 2024
ab2ef38
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Feb 16, 2024
01dafcc
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Feb 16, 2024
36a2152
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Feb 19, 2024
68c4de2
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Feb 19, 2024
d23ace7
Merge branch 'main' into cleanup_old-reviews-on-review
lafriks Feb 19, 2024
b3d062d
test against rerequest and add some codecomments
6543 Feb 19, 2024
48fa3ad
Merge branch 'main' into cleanup_old-reviews-on-review
6543 Feb 19, 2024
4102b16
Merge branch 'main' into pull_review_fixfix-builder
6543 Feb 19, 2024
10a3727
Merge branch 'cleanup_old-reviews-on-review' into pull_review_fixfix-…
6543 Feb 19, 2024
89ba349
Merge branch 'main' into pull_review_fixfix-builder
6543 Feb 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions models/issues/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,14 +798,16 @@ func HasEnoughApprovals(ctx context.Context, protectBranch *git_model.ProtectedB

// GetGrantedApprovalsCount returns the number of granted approvals for pr. A granted approval must be authored by a user in an approval whitelist.
func GetGrantedApprovalsCount(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) int64 {
sess := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
And("type = ?", ReviewTypeApprove).
And("official = ?", true).
And("dismissed = ?", false)
opt := &GetReviewOption{
6543 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lunny suggest: How about reuse db.Find here?

Dismissed: util.OptionalBoolFalse,
Official: util.OptionalBoolTrue,
Types: []ReviewType{ReviewTypeApprove},
IssueID: pr.IssueID,
}
if protectBranch.IgnoreStaleApprovals {
sess = sess.And("stale = ?", false)
opt.Stale = util.OptionalBoolFalse
}
approvals, err := sess.Count(new(Review))
approvals, err := db.GetEngine(ctx).Where(opt.toCond()).Count(new(Review))
if err != nil {
log.Error("GetGrantedApprovalsCount: %v", err)
return 0
Expand All @@ -819,11 +821,13 @@ func MergeBlockedByRejectedReview(ctx context.Context, protectBranch *git_model.
if !protectBranch.BlockOnRejectedReviews {
return false
}
rejectExist, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
And("type = ?", ReviewTypeReject).
And("official = ?", true).
And("dismissed = ?", false).
Exist(new(Review))
opt := &GetReviewOption{
Dismissed: util.OptionalBoolFalse,
Official: util.OptionalBoolTrue,
Types: []ReviewType{ReviewTypeReject},
IssueID: pr.IssueID,
}
rejectExist, err := db.GetEngine(ctx).Where(opt.toCond()).Exist(new(Review))
if err != nil {
log.Error("MergeBlockedByRejectedReview: %v", err)
return true
Expand All @@ -838,10 +842,12 @@ func MergeBlockedByOfficialReviewRequests(ctx context.Context, protectBranch *gi
if !protectBranch.BlockOnOfficialReviewRequests {
return false
}
has, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
And("type = ?", ReviewTypeRequest).
And("official = ?", true).
Exist(new(Review))
opt := &GetReviewOption{
Official: util.OptionalBoolTrue,
Types: []ReviewType{ReviewTypeRequest},
IssueID: pr.IssueID,
}
has, err := db.GetEngine(ctx).Where(opt.toCond()).Exist(new(Review))
if err != nil {
log.Error("MergeBlockedByOfficialReviewRequests: %v", err)
return true
Expand Down
142 changes: 114 additions & 28 deletions models/issues/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ const (
ReviewTypeRequest
)

// AffectReview indicate if this review type alter a pull state
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write about branch protection

func (rt ReviewType) AffectReview() bool {
return rt == ReviewTypeApprove || rt == ReviewTypeReject
}

// Icon returns the corresponding icon for the review type
func (rt ReviewType) Icon() string {
switch rt {
Expand All @@ -103,11 +108,11 @@ func (rt ReviewType) Icon() string {

// Review represents collection of code comments giving feedback for a PR
type Review struct {
ID int64 `xorm:"pk autoincr"`
Type ReviewType
ID int64 `xorm:"pk autoincr"`
Type ReviewType `xorm:"index"`
Reviewer *user_model.User `xorm:"-"`
ReviewerID int64 `xorm:"index"`
ReviewerTeamID int64 `xorm:"NOT NULL DEFAULT 0"`
ReviewerTeamID int64 `xorm:"index NOT NULL DEFAULT 0"`
ReviewerTeam *organization.Team `xorm:"-"`
OriginalAuthor string
OriginalAuthorID int64
Expand Down Expand Up @@ -292,8 +297,14 @@ func IsOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organizatio

// CreateReview creates a new review based on opts
func CreateReview(ctx context.Context, opts CreateReviewOptions) (*Review, error) {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return nil, err
}
defer committer.Close()
sess := db.GetEngine(ctx)

review := &Review{
Type: opts.Type,
Issue: opts.Issue,
IssueID: opts.Issue.ID,
Reviewer: opts.Reviewer,
Expand All @@ -303,19 +314,46 @@ func CreateReview(ctx context.Context, opts CreateReviewOptions) (*Review, error
CommitID: opts.CommitID,
Stale: opts.Stale,
}

if opts.Reviewer != nil {
review.Type = opts.Type
review.ReviewerID = opts.Reviewer.ID
} else {
if review.Type != ReviewTypeRequest {
review.Type = ReviewTypeRequest

opt := &GetReviewOption{
ReviewerID: opts.Reviewer.ID,
IssueID: opts.Issue.ID,
}
// make sure user review requests are cleared
if opts.Type != ReviewTypePending {
if _, err := sess.Where(opt.toCond().And(builder.Eq{"type": ReviewTypeRequest})).Delete(new(Review)); err != nil {
return nil, err
}
}
// make sure if the created review gets dismissed no old review surface
// other types can be ignored, as they don't affect branch protection
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// other types can be ignored, as they don't affect branch protection

with the new helper it should be self explaining cc @wxiaoguang ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: this code might be deleted later on anyway if i'm done refactoring

if opts.Type.AffectReview() {
if _, err := sess.Where(opt.toCond().And(builder.In("type", ReviewTypeApprove, ReviewTypeReject))).
Cols("dismissed").Update(&Review{Dismissed: true}); err != nil {
return nil, err
}
}

} else if opts.ReviewerTeam != nil {
review.Type = ReviewTypeRequest
review.ReviewerTeamID = opts.ReviewerTeam.ID

} else {
return nil, fmt.Errorf("provide either reviewer or reviewer team")
}

if _, err := sess.Insert(review); err != nil {
return nil, err
}
return review, db.Insert(ctx, review)
return review, committer.Commit()
}

// GetCurrentReview returns the current pending review of reviewer for given issue
func GetCurrentReview(ctx context.Context, reviewer *user_model.User, issue *Issue) (*Review, error) {
// GetCurrentPendingReview returns the current pending review of reviewer for given issue
func GetCurrentPendingReview(ctx context.Context, reviewer *user_model.User, issue *Issue) (*Review, error) {
if reviewer == nil {
return nil, nil
}
Expand Down Expand Up @@ -364,7 +402,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, revi

official := false

review, err := GetCurrentReview(ctx, doer, issue)
review, err := GetCurrentPendingReview(ctx, doer, issue)
if err != nil {
if !IsErrReviewNotExist(err) {
return nil, nil, err
Expand All @@ -374,7 +412,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, revi
return nil, nil, ContentEmptyErr{}
}

if reviewType == ReviewTypeApprove || reviewType == ReviewTypeReject {
if reviewType.AffectReview() {
// Only reviewers latest review of type approve and reject shall count as "official", so existing reviews needs to be cleared
if _, err := db.Exec(ctx, "UPDATE `review` SET official=? WHERE issue_id=? AND reviewer_id=?", false, issue.ID, doer.ID); err != nil {
return nil, nil, err
Expand Down Expand Up @@ -404,7 +442,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, revi
return nil, nil, ContentEmptyErr{}
}

if reviewType == ReviewTypeApprove || reviewType == ReviewTypeReject {
if reviewType.AffectReview() {
// Only reviewers latest review of type approve and reject shall count as "official", so existing reviews needs to be cleared
if _, err := db.Exec(ctx, "UPDATE `review` SET official=? WHERE issue_id=? AND reviewer_id=?", false, issue.ID, doer.ID); err != nil {
return nil, nil, err
Expand Down Expand Up @@ -440,7 +478,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, revi
}

// try to remove team review request if need
if issue.Repo.Owner.IsOrganization() && (reviewType == ReviewTypeApprove || reviewType == ReviewTypeReject) {
if issue.Repo.Owner.IsOrganization() && reviewType.AffectReview() {
teamReviewRequests := make([]*Review, 0, 10)
if err := sess.SQL("SELECT * FROM review WHERE issue_id = ? AND reviewer_team_id > 0 AND type = ?", issue.ID, ReviewTypeRequest).Find(&teamReviewRequests); err != nil {
return nil, nil, err
Expand All @@ -464,15 +502,63 @@ func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, revi
return review, comm, committer.Commit()
}

type GetReviewOption struct {
Dismissed util.OptionalBool
Official util.OptionalBool
Stale util.OptionalBool
Types []ReviewType
IssueID int64
ReviewerID int64
TeamID int64
}

func (o *GetReviewOption) toCond() builder.Cond {
cond := builder.And(builder.Eq{"review.issue_id": o.IssueID})

if !o.Dismissed.IsNone() {
cond = cond.And(builder.Eq{"review.dismissed": o.Dismissed.IsTrue()})
}
if !o.Official.IsNone() {
cond = cond.And(builder.Eq{"review.official": o.Official.IsTrue()})
}
if !o.Stale.IsNone() {
cond = cond.And(builder.Eq{"review.stale": o.Stale.IsTrue()})
}
if len(o.Types) != 0 {
cond = cond.And(builder.In("review.type", o.Types))
}
if o.ReviewerID > 0 {
cond = cond.And(builder.Eq{"review.reviewer_id": o.ReviewerID, "original_author_id": 0})
}
if o.TeamID > 0 {
cond = cond.And(builder.Eq{"review.reviewer_team_id": o.TeamID})
}

return cond
}

// GetReviewByOption get the latest review for a pull request filtered by given option
func GetReviewByOption(ctx context.Context, opt *GetReviewOption) (*Review, error) {
review := new(Review)
has, err := db.GetEngine(ctx).Where(opt.toCond()).OrderBy("id").Desc().Get(review)
if err != nil {
return nil, err
}
if !has {
return nil, ErrReviewNotExist{}
}
return review, nil
}

// GetReviewByIssueIDAndUserID get the latest review of reviewer for a pull request
func GetReviewByIssueIDAndUserID(ctx context.Context, issueID, userID int64) (*Review, error) {
review := new(Review)

has, err := db.GetEngine(ctx).Where(
builder.In("type", ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest).
And(builder.Eq{"issue_id": issueID, "reviewer_id": userID, "original_author_id": 0})).
Desc("id").
Get(review)
opt := &GetReviewOption{
Types: []ReviewType{ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest},
IssueID: issueID,
ReviewerID: userID,
}
has, err := db.GetEngine(ctx).Where(opt.toCond()).Desc("review.id").Get(review)
if err != nil {
return nil, err
}
Expand All @@ -487,10 +573,11 @@ func GetReviewByIssueIDAndUserID(ctx context.Context, issueID, userID int64) (*R
// GetTeamReviewerByIssueIDAndTeamID get the latest review request of reviewer team for a pull request
func GetTeamReviewerByIssueIDAndTeamID(ctx context.Context, issueID, teamID int64) (*Review, error) {
review := new(Review)

has, err := db.GetEngine(ctx).Where(builder.Eq{"issue_id": issueID, "reviewer_team_id": teamID}).
Desc("id").
Get(review)
opt := &GetReviewOption{
IssueID: issueID,
TeamID: teamID,
}
has, err := db.GetEngine(ctx).Where(opt.toCond()).Desc("review.id").Get(review)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -518,7 +605,7 @@ func MarkReviewsAsNotStale(ctx context.Context, issueID int64, commitID string)

// DismissReview change the dismiss status of a review
func DismissReview(ctx context.Context, review *Review, isDismiss bool) (err error) {
if review.Dismissed == isDismiss || (review.Type != ReviewTypeApprove && review.Type != ReviewTypeReject) {
if review.Dismissed == isDismiss || !review.Type.AffectReview() {
return nil
}

Expand Down Expand Up @@ -589,7 +676,7 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
return nil, err
}

// skip it when reviewer hase been request to review
// skip it when reviewer has been request to review
if review != nil && review.Type == ReviewTypeRequest {
return nil, nil
}
Expand All @@ -605,7 +692,7 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
}
}

review, err = CreateReview(ctx, CreateReviewOptions{
_, err = CreateReview(ctx, CreateReviewOptions{
Type: ReviewTypeRequest,
Issue: issue,
Reviewer: reviewer,
Expand All @@ -623,7 +710,6 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
Issue: issue,
RemovedAssignee: false, // Use RemovedAssignee as !isRequest
AssigneeID: reviewer.ID, // Use AssigneeID as reviewer ID
ReviewID: review.ID,
})
if err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions models/issues/review_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ func GetReviewsByIssueID(ctx context.Context, issueID int64) (ReviewList, error)
sess := db.GetEngine(ctx)

// Get latest review of each reviewer, sorted in order they were made
// TODO: use FindLatestReviews()
if err := sess.SQL("SELECT * FROM review WHERE id IN (SELECT max(id) as id FROM review WHERE issue_id = ? AND reviewer_team_id = 0 AND type in (?, ?, ?) AND dismissed = ? AND original_author_id = 0 GROUP BY issue_id, reviewer_id) ORDER BY review.updated_unix ASC",
issueID, ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest, false).
Find(&reviews); err != nil {
return nil, err
}

teamReviewRequests := make([]*Review, 0, 5)
// TODO: use FindLatestReviews()
if err := sess.SQL("SELECT * FROM review WHERE id IN (SELECT max(id) as id FROM review WHERE issue_id = ? AND reviewer_team_id <> 0 AND original_author_id = 0 GROUP BY issue_id, reviewer_team_id) ORDER BY review.updated_unix ASC",
issueID).
Find(&teamReviewRequests); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions models/issues/review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ func TestFindLatestReviews(t *testing.T) {
assert.Equal(t, "singular review from org6 and final review for this pr", reviews[1].Content)
}

func TestGetCurrentReview(t *testing.T) {
func TestGetCurrentPendingReview(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})

review, err := issues_model.GetCurrentReview(db.DefaultContext, user, issue)
review, err := issues_model.GetCurrentPendingReview(db.DefaultContext, user, issue)
assert.NoError(t, err)
assert.NotNil(t, review)
assert.Equal(t, issues_model.ReviewTypePending, review.Type)
assert.Equal(t, "Pending Review", review.Content)

user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 7})
review2, err := issues_model.GetCurrentReview(db.DefaultContext, user2, issue)
review2, err := issues_model.GetCurrentPendingReview(db.DefaultContext, user2, issue)
assert.Error(t, err)
assert.True(t, issues_model.IsErrReviewNotExist(err))
assert.Nil(t, review2)
Expand Down
8 changes: 4 additions & 4 deletions models/unittest/unit_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func AssertSuccessfulInsert(t assert.TestingT, beans ...any) {
}

// AssertCount assert the count of a bean
func AssertCount(t assert.TestingT, bean, expected any) {
assert.EqualValues(t, expected, GetCount(t, bean))
func AssertCount(t assert.TestingT, bean, expected any) bool {
return assert.EqualValues(t, expected, GetCount(t, bean))
}

// AssertInt64InRange assert value is in range [low, high]
Expand All @@ -150,7 +150,7 @@ func GetCountByCond(t assert.TestingT, tableName string, cond builder.Cond) int6
}

// AssertCountByCond test the count of database entries matching bean
func AssertCountByCond(t assert.TestingT, tableName string, cond builder.Cond, expected int) {
assert.EqualValues(t, expected, GetCountByCond(t, tableName, cond),
func AssertCountByCond(t assert.TestingT, tableName string, cond builder.Cond, expected int) bool {
return assert.EqualValues(t, expected, GetCountByCond(t, tableName, cond),
"Failed consistency test, the counted bean (of table %s) was %+v", tableName, cond)
}
2 changes: 1 addition & 1 deletion routers/api/v1/repo/pull_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss, dismissPriors
return
}

if review.Type != issues_model.ReviewTypeApprove && review.Type != issues_model.ReviewTypeReject {
if !review.Type.AffectReview() {
ctx.Error(http.StatusForbidden, "", "not need to dismiss this review because it's type is not Approve or change request")
return
}
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
return
}

currentReview, err := issues_model.GetCurrentReview(ctx, ctx.Doer, issue)
currentReview, err := issues_model.GetCurrentPendingReview(ctx, ctx.Doer, issue)
if err != nil && !issues_model.IsErrReviewNotExist(err) {
ctx.ServerError("GetCurrentReview", err)
return
Expand Down
Loading
Loading