aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorNanguan Lin <70063547+lng2020@users.noreply.github.com>2023-09-21 19:59:50 +0800
committerGitHub <noreply@github.com>2023-09-21 13:59:50 +0200
commit2f8e1604f825ab862ba1b182dda47d9dee40aace (patch)
tree18627b487c0b07bc13275d9a6398ff6d192ebbd2 /models
parent218e719ea86883bee75d02684d4bf07f95fa4f55 (diff)
downloadgitea-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')
-rw-r--r--models/fixtures/issue.yml17
-rw-r--r--models/fixtures/pull_request.yml9
-rw-r--r--models/fixtures/repository.yml2
-rw-r--r--models/fixtures/review.yml38
-rw-r--r--models/fixtures/team.yml2
-rw-r--r--models/fixtures/team_user.yml6
-rw-r--r--models/issues/issue_search.go9
-rw-r--r--models/issues/issue_test.go2
8 files changed, 81 insertions, 4 deletions
diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml
index fa72f9b647..ccc1fe41fb 100644
--- a/models/fixtures/issue.yml
+++ b/models/fixtures/issue.yml
@@ -321,3 +321,20 @@
created_unix: 946684830
updated_unix: 978307200
is_locked: false
+
+-
+ id: 20
+ repo_id: 23
+ index: 1
+ poster_id: 2
+ original_author_id: 0
+ name: issue for pr
+ content: content
+ milestone_id: 0
+ priority: 0
+ is_closed: false
+ is_pull: true
+ num_comments: 0
+ created_unix: 978307210
+ updated_unix: 978307210
+ is_locked: false
diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml
index e5589ac703..396bdba88c 100644
--- a/models/fixtures/pull_request.yml
+++ b/models/fixtures/pull_request.yml
@@ -89,3 +89,12 @@
base_branch: main
merge_base: cbff181af4c9c7fee3cf6c106699e07d9a3f54e6
has_merged: false
+
+-
+ id: 8
+ type: 0 # gitea pull request
+ status: 2 # mergable
+ issue_id: 20
+ index: 1
+ head_repo_id: 23
+ base_repo_id: 23 \ No newline at end of file
diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml
index c63b7ebd48..373c1caa62 100644
--- a/models/fixtures/repository.yml
+++ b/models/fixtures/repository.yml
@@ -679,7 +679,7 @@
num_forks: 0
num_issues: 0
num_closed_issues: 0
- num_pulls: 0
+ num_pulls: 1
num_closed_pulls: 0
num_milestones: 0
num_closed_milestones: 0
diff --git a/models/fixtures/review.yml b/models/fixtures/review.yml
index dda13dc468..f964c6ac06 100644
--- a/models/fixtures/review.yml
+++ b/models/fixtures/review.yml
@@ -132,3 +132,41 @@
content: "singular review from org6 and final review for this pr"
updated_unix: 946684831
created_unix: 946684831
+
+-
+ id: 16
+ type: 4
+ reviewer_id: 20
+ issue_id: 20
+ content: "review request for user20"
+ updated_unix: 946684832
+ created_unix: 946684832
+
+-
+ id: 17
+ type: 1
+ reviewer_id: 20
+ issue_id: 20
+ content: "review approved by user20"
+ updated_unix: 946684833
+ created_unix: 946684833
+-
+ id: 18
+ type: 4
+ reviewer_id: 0
+ reviewer_team_id: 5
+ issue_id: 20
+ content: "review request for team5"
+ updated_unix: 946684834
+ created_unix: 946684834
+
+-
+ id: 19
+ type: 4
+ reviewer_id: 15
+ reviewer_team_id: 0
+ issue_id: 20
+ content: "review request for user15"
+ updated_unix: 946684835
+ created_unix: 946684835
+
diff --git a/models/fixtures/team.yml b/models/fixtures/team.yml
index 65326eedbf..295e51e39c 100644
--- a/models/fixtures/team.yml
+++ b/models/fixtures/team.yml
@@ -93,7 +93,7 @@
name: review_team
authorize: 1 # read
num_repos: 1
- num_members: 2
+ num_members: 3
includes_all_repositories: false
can_create_org_repo: false
diff --git a/models/fixtures/team_user.yml b/models/fixtures/team_user.yml
index feace5f2a5..a5f1e9fd92 100644
--- a/models/fixtures/team_user.yml
+++ b/models/fixtures/team_user.yml
@@ -123,3 +123,9 @@
org_id: 36
team_id: 20
uid: 5
+
+-
+ id: 22
+ org_id: 17
+ team_id: 9
+ uid: 15
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) {