diff options
author | Nanguan Lin <70063547+lng2020@users.noreply.github.com> | 2023-09-21 19:59:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-21 13:59:50 +0200 |
commit | 2f8e1604f825ab862ba1b182dda47d9dee40aace (patch) | |
tree | 18627b487c0b07bc13275d9a6398ff6d192ebbd2 /models/issues | |
parent | 218e719ea86883bee75d02684d4bf07f95fa4f55 (diff) | |
download | gitea-2f8e1604f825ab862ba1b182dda47d9dee40aace.tar.gz gitea-2f8e1604f825ab862ba1b182dda47d9dee40aace.zip |
Fix review request number and add more tests (#27104)
fix #27019
## testfixture yml
1. add issue20(a pr issue) in repo 23, org 17
2. add user15 to team 9
3. add four reviews about issue20
## test case
add two tests that are described with code comments
the code before pr #26784 failed the first test
<img width="479" alt="image"
src="https://github.com/go-gitea/gitea/assets/70063547/1d9b5787-11b4-4c4d-931f-6a9869547f35">
current code failed the second test(as mentioned in #27019)
<img width="484" alt="image"
src="https://github.com/go-gitea/gitea/assets/70063547/05608055-7587-43d1-bae1-92c688270819">
Any advice is appreciated.
---------
Co-authored-by: CaiCandong <50507092+CaiCandong@users.noreply.github.com>
Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'models/issues')
-rw-r--r-- | models/issues/issue_search.go | 9 | ||||
-rw-r--r-- | models/issues/issue_test.go | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/models/issues/issue_search.go b/models/issues/issue_search.go index 5d40b44704..5c05ead687 100644 --- a/models/issues/issue_search.go +++ b/models/issues/issue_search.go @@ -362,14 +362,21 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) From("team_user"). Where(builder.Eq{"team_user.uid": reviewRequestedID}) + // if the review is approved or rejected, it should not be shown in the review requested list + maxReview := builder.Select("MAX(r.id)"). + From("review as r"). + Where(builder.In("r.type", []ReviewType{ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest})). + GroupBy("r.issue_id, r.reviewer_id, r.reviewer_team_id") + subQuery := builder.Select("review.issue_id"). From("review"). Where(builder.And( - builder.In("review.type", []ReviewType{ReviewTypeRequest, ReviewTypeReject, ReviewTypeApprove}), + builder.Eq{"review.type": ReviewTypeRequest}, builder.Or( builder.Eq{"review.reviewer_id": reviewRequestedID}, builder.In("review.reviewer_team_id", existInTeamQuery), ), + builder.In("review.id", maxReview), )) return sess.Where("issue.poster_id <> ?", reviewRequestedID). And(builder.In("issue.id", subQuery)) diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go index b7fa7eff1c..513ae241bc 100644 --- a/models/issues/issue_test.go +++ b/models/issues/issue_test.go @@ -403,7 +403,7 @@ func TestCountIssues(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{}) assert.NoError(t, err) - assert.EqualValues(t, 19, count) + assert.EqualValues(t, 20, count) } func TestIssueLoadAttributes(t *testing.T) { |