@@ -1090,6 +1090,7 @@ type IssuesOptions struct {
1090
1090
AssigneeID int64
1091
1091
PosterID int64
1092
1092
MentionedID int64
1093
+ ReviewRequestedID int64
1093
1094
MilestoneIDs []int64
1094
1095
ProjectID int64
1095
1096
ProjectBoardID int64
@@ -1151,8 +1152,7 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
1151
1152
}
1152
1153
1153
1154
if len (opts .RepoIDs ) > 0 {
1154
- // In case repository IDs are provided but actually no repository has issue.
1155
- sess .In ("issue.repo_id" , opts .RepoIDs )
1155
+ applyReposCondition (sess , opts .RepoIDs )
1156
1156
}
1157
1157
1158
1158
switch opts .IsClosed {
@@ -1163,18 +1163,19 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
1163
1163
}
1164
1164
1165
1165
if opts .AssigneeID > 0 {
1166
- sess .Join ("INNER" , "issue_assignees" , "issue.id = issue_assignees.issue_id" ).
1167
- And ("issue_assignees.assignee_id = ?" , opts .AssigneeID )
1166
+ applyAssigneeCondition (sess , opts .AssigneeID )
1168
1167
}
1169
1168
1170
1169
if opts .PosterID > 0 {
1171
- sess . And ( "issue.poster_id=?" , opts .PosterID )
1170
+ applyPosterCondition ( sess , opts .PosterID )
1172
1171
}
1173
1172
1174
1173
if opts .MentionedID > 0 {
1175
- sess .Join ("INNER" , "issue_user" , "issue.id = issue_user.issue_id" ).
1176
- And ("issue_user.is_mentioned = ?" , true ).
1177
- And ("issue_user.uid = ?" , opts .MentionedID )
1174
+ applyMentionedCondition (sess , opts .MentionedID )
1175
+ }
1176
+
1177
+ if opts .ReviewRequestedID > 0 {
1178
+ applyReviewRequestedCondition (sess , opts .ReviewRequestedID )
1178
1179
}
1179
1180
1180
1181
if len (opts .MilestoneIDs ) > 0 {
@@ -1232,6 +1233,33 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
1232
1233
}
1233
1234
}
1234
1235
1236
+ func applyReposCondition (sess * xorm.Session , repoIDs []int64 ) * xorm.Session {
1237
+ return sess .In ("issue.repo_id" , repoIDs )
1238
+ }
1239
+
1240
+ func applyAssigneeCondition (sess * xorm.Session , assigneeID int64 ) * xorm.Session {
1241
+ return sess .Join ("INNER" , "issue_assignees" , "issue.id = issue_assignees.issue_id" ).
1242
+ And ("issue_assignees.assignee_id = ?" , assigneeID )
1243
+ }
1244
+
1245
+ func applyPosterCondition (sess * xorm.Session , posterID int64 ) * xorm.Session {
1246
+ return sess .And ("issue.poster_id=?" , posterID )
1247
+ }
1248
+
1249
+ func applyMentionedCondition (sess * xorm.Session , mentionedID int64 ) * xorm.Session {
1250
+ return sess .Join ("INNER" , "issue_user" , "issue.id = issue_user.issue_id" ).
1251
+ And ("issue_user.is_mentioned = ?" , true ).
1252
+ And ("issue_user.uid = ?" , mentionedID )
1253
+ }
1254
+
1255
+ func applyReviewRequestedCondition (sess * xorm.Session , reviewRequestedID int64 ) * xorm.Session {
1256
+ return sess .Join ("INNER" , []string {"review" , "r" }, "issue.id = r.issue_id" ).
1257
+ And ("r.type = ?" , ReviewTypeRequest ).
1258
+ And ("r.reviewer_id = ? and r.id in (select max(id) from review where issue_id = r.issue_id and reviewer_id = r.reviewer_id and type in (?, ?, ?))" +
1259
+ " or r.reviewer_team_id in (select team_id from team_user where uid = ?)" ,
1260
+ reviewRequestedID , ReviewTypeApprove , ReviewTypeReject , ReviewTypeRequest , reviewRequestedID )
1261
+ }
1262
+
1235
1263
// CountIssuesByRepo map from repoID to number of issues matching the options
1236
1264
func CountIssuesByRepo (opts * IssuesOptions ) (map [int64 ]int64 , error ) {
1237
1265
sess := x .NewSession ()
@@ -1364,6 +1392,7 @@ type IssueStats struct {
1364
1392
AssignCount int64
1365
1393
CreateCount int64
1366
1394
MentionCount int64
1395
+ ReviewRequestedCount int64
1367
1396
}
1368
1397
1369
1398
// Filter modes.
@@ -1372,6 +1401,7 @@ const (
1372
1401
FilterModeAssign
1373
1402
FilterModeCreate
1374
1403
FilterModeMention
1404
+ FilterModeReviewRequested
1375
1405
)
1376
1406
1377
1407
func parseCountResult (results []map [string ][]byte ) int64 {
@@ -1387,14 +1417,15 @@ func parseCountResult(results []map[string][]byte) int64 {
1387
1417
1388
1418
// IssueStatsOptions contains parameters accepted by GetIssueStats.
1389
1419
type IssueStatsOptions struct {
1390
- RepoID int64
1391
- Labels string
1392
- MilestoneID int64
1393
- AssigneeID int64
1394
- MentionedID int64
1395
- PosterID int64
1396
- IsPull util.OptionalBool
1397
- IssueIDs []int64
1420
+ RepoID int64
1421
+ Labels string
1422
+ MilestoneID int64
1423
+ AssigneeID int64
1424
+ MentionedID int64
1425
+ PosterID int64
1426
+ ReviewRequestedID int64
1427
+ IsPull util.OptionalBool
1428
+ IssueIDs []int64
1398
1429
}
1399
1430
1400
1431
// GetIssueStats returns issue statistic information by given conditions.
@@ -1423,6 +1454,7 @@ func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) {
1423
1454
accum .AssignCount += stats .AssignCount
1424
1455
accum .CreateCount += stats .CreateCount
1425
1456
accum .OpenCount += stats .MentionCount
1457
+ accum .ReviewRequestedCount += stats .ReviewRequestedCount
1426
1458
i = chunk
1427
1459
}
1428
1460
return accum , nil
@@ -1460,18 +1492,19 @@ func getIssueStatsChunk(opts *IssueStatsOptions, issueIDs []int64) (*IssueStats,
1460
1492
}
1461
1493
1462
1494
if opts .AssigneeID > 0 {
1463
- sess .Join ("INNER" , "issue_assignees" , "issue.id = issue_assignees.issue_id" ).
1464
- And ("issue_assignees.assignee_id = ?" , opts .AssigneeID )
1495
+ applyAssigneeCondition (sess , opts .AssigneeID )
1465
1496
}
1466
1497
1467
1498
if opts .PosterID > 0 {
1468
- sess . And ( "issue.poster_id = ?" , opts .PosterID )
1499
+ applyPosterCondition ( sess , opts .PosterID )
1469
1500
}
1470
1501
1471
1502
if opts .MentionedID > 0 {
1472
- sess .Join ("INNER" , "issue_user" , "issue.id = issue_user.issue_id" ).
1473
- And ("issue_user.uid = ?" , opts .MentionedID ).
1474
- And ("issue_user.is_mentioned = ?" , true )
1503
+ applyMentionedCondition (sess , opts .MentionedID )
1504
+ }
1505
+
1506
+ if opts .ReviewRequestedID > 0 {
1507
+ applyReviewRequestedCondition (sess , opts .ReviewRequestedID )
1475
1508
}
1476
1509
1477
1510
switch opts .IsPull {
@@ -1539,90 +1572,94 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
1539
1572
1540
1573
switch opts .FilterMode {
1541
1574
case FilterModeAll :
1542
- stats .OpenCount , err = sess (cond ). And ( "issue.is_closed = ?" , false ).
1543
- And (builder . In ( "issue.repo_id " , opts . UserRepoIDs ) ).
1575
+ stats .OpenCount , err = applyReposCondition ( sess (cond ), opts . UserRepoIDs ).
1576
+ And ("issue.is_closed = ? " , false ).
1544
1577
Count (new (Issue ))
1545
1578
if err != nil {
1546
1579
return nil , err
1547
1580
}
1548
- stats .ClosedCount , err = sess (cond ). And ( "issue.is_closed = ?" , true ).
1549
- And (builder . In ( "issue.repo_id " , opts . UserRepoIDs ) ).
1581
+ stats .ClosedCount , err = applyReposCondition ( sess (cond ), opts . UserRepoIDs ).
1582
+ And ("issue.is_closed = ? " , true ).
1550
1583
Count (new (Issue ))
1551
1584
if err != nil {
1552
1585
return nil , err
1553
1586
}
1554
1587
case FilterModeAssign :
1555
- stats .OpenCount , err = sess (cond ).And ("issue.is_closed = ?" , false ).
1556
- Join ("INNER" , "issue_assignees" , "issue.id = issue_assignees.issue_id" ).
1557
- And ("issue_assignees.assignee_id = ?" , opts .UserID ).
1588
+ stats .OpenCount , err = applyAssigneeCondition (sess (cond ), opts .UserID ).
1589
+ And ("issue.is_closed = ?" , false ).
1558
1590
Count (new (Issue ))
1559
1591
if err != nil {
1560
1592
return nil , err
1561
1593
}
1562
- stats .ClosedCount , err = sess (cond ).And ("issue.is_closed = ?" , true ).
1563
- Join ("INNER" , "issue_assignees" , "issue.id = issue_assignees.issue_id" ).
1564
- And ("issue_assignees.assignee_id = ?" , opts .UserID ).
1594
+ stats .ClosedCount , err = applyAssigneeCondition (sess (cond ), opts .UserID ).
1595
+ And ("issue.is_closed = ?" , true ).
1565
1596
Count (new (Issue ))
1566
1597
if err != nil {
1567
1598
return nil , err
1568
1599
}
1569
1600
case FilterModeCreate :
1570
- stats .OpenCount , err = sess (cond ). And ( "issue.is_closed = ?" , false ).
1571
- And ("issue.poster_id = ?" , opts . UserID ).
1601
+ stats .OpenCount , err = applyPosterCondition ( sess (cond ), opts . UserID ).
1602
+ And ("issue.is_closed = ?" , false ).
1572
1603
Count (new (Issue ))
1573
1604
if err != nil {
1574
1605
return nil , err
1575
1606
}
1576
- stats .ClosedCount , err = sess (cond ). And ( "issue.is_closed = ?" , true ).
1577
- And ("issue.poster_id = ?" , opts . UserID ).
1607
+ stats .ClosedCount , err = applyPosterCondition ( sess (cond ), opts . UserID ).
1608
+ And ("issue.is_closed = ?" , true ).
1578
1609
Count (new (Issue ))
1579
1610
if err != nil {
1580
1611
return nil , err
1581
1612
}
1582
1613
case FilterModeMention :
1583
- stats .OpenCount , err = sess (cond ).And ("issue.is_closed = ?" , false ).
1584
- Join ("INNER" , "issue_user" , "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?" , true ).
1585
- And ("issue_user.uid = ?" , opts .UserID ).
1614
+ stats .OpenCount , err = applyMentionedCondition (sess (cond ), opts .UserID ).
1615
+ And ("issue.is_closed = ?" , false ).
1586
1616
Count (new (Issue ))
1587
1617
if err != nil {
1588
1618
return nil , err
1589
1619
}
1590
- stats .ClosedCount , err = sess (cond ).And ("issue.is_closed = ?" , true ).
1591
- Join ("INNER" , "issue_user" , "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?" , true ).
1592
- And ("issue_user.uid = ?" , opts .UserID ).
1620
+ stats .ClosedCount , err = applyMentionedCondition (sess (cond ), opts .UserID ).
1621
+ And ("issue.is_closed = ?" , true ).
1622
+ Count (new (Issue ))
1623
+ if err != nil {
1624
+ return nil , err
1625
+ }
1626
+ case FilterModeReviewRequested :
1627
+ stats .OpenCount , err = applyReviewRequestedCondition (sess (cond ), opts .UserID ).
1628
+ And ("issue.is_closed = ?" , false ).
1629
+ Count (new (Issue ))
1630
+ if err != nil {
1631
+ return nil , err
1632
+ }
1633
+ stats .ClosedCount , err = applyReviewRequestedCondition (sess (cond ), opts .UserID ).
1634
+ And ("issue.is_closed = ?" , true ).
1593
1635
Count (new (Issue ))
1594
1636
if err != nil {
1595
1637
return nil , err
1596
1638
}
1597
1639
}
1598
1640
1599
1641
cond = cond .And (builder.Eq {"issue.is_closed" : opts .IsClosed })
1600
- stats .AssignCount , err = sess (cond ).
1601
- Join ("INNER" , "issue_assignees" , "issue.id = issue_assignees.issue_id" ).
1602
- And ("issue_assignees.assignee_id = ?" , opts .UserID ).
1603
- Count (new (Issue ))
1642
+ stats .AssignCount , err = applyAssigneeCondition (sess (cond ), opts .UserID ).Count (new (Issue ))
1604
1643
if err != nil {
1605
1644
return nil , err
1606
1645
}
1607
1646
1608
- stats .CreateCount , err = sess (cond ).
1609
- And ("poster_id = ?" , opts .UserID ).
1610
- Count (new (Issue ))
1647
+ stats .CreateCount , err = applyPosterCondition (sess (cond ), opts .UserID ).Count (new (Issue ))
1611
1648
if err != nil {
1612
1649
return nil , err
1613
1650
}
1614
1651
1615
- stats .MentionCount , err = sess (cond ).
1616
- Join ("INNER" , "issue_user" , "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?" , true ).
1617
- And ("issue_user.uid = ?" , opts .UserID ).
1618
- Count (new (Issue ))
1652
+ stats .MentionCount , err = applyMentionedCondition (sess (cond ), opts .UserID ).Count (new (Issue ))
1619
1653
if err != nil {
1620
1654
return nil , err
1621
1655
}
1622
1656
1623
- stats .YourRepositoriesCount , err = sess (cond ).
1624
- And (builder .In ("issue.repo_id" , opts .UserRepoIDs )).
1625
- Count (new (Issue ))
1657
+ stats .YourRepositoriesCount , err = applyReposCondition (sess (cond ), opts .UserRepoIDs ).Count (new (Issue ))
1658
+ if err != nil {
1659
+ return nil , err
1660
+ }
1661
+
1662
+ stats .ReviewRequestedCount , err = applyReviewRequestedCondition (sess (cond ), opts .UserID ).Count (new (Issue ))
1626
1663
if err != nil {
1627
1664
return nil , err
1628
1665
}
@@ -1646,13 +1683,11 @@ func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen
1646
1683
1647
1684
switch filterMode {
1648
1685
case FilterModeAssign :
1649
- openCountSession .Join ("INNER" , "issue_assignees" , "issue.id = issue_assignees.issue_id" ).
1650
- And ("issue_assignees.assignee_id = ?" , uid )
1651
- closedCountSession .Join ("INNER" , "issue_assignees" , "issue.id = issue_assignees.issue_id" ).
1652
- And ("issue_assignees.assignee_id = ?" , uid )
1686
+ applyAssigneeCondition (openCountSession , uid )
1687
+ applyAssigneeCondition (closedCountSession , uid )
1653
1688
case FilterModeCreate :
1654
- openCountSession . And ( "poster_id = ?" , uid )
1655
- closedCountSession . And ( "poster_id = ?" , uid )
1689
+ applyPosterCondition ( openCountSession , uid )
1690
+ applyPosterCondition ( closedCountSession , uid )
1656
1691
}
1657
1692
1658
1693
openResult , _ := openCountSession .Count (new (Issue ))
0 commit comments