aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
authorBrecht Van Lommel2023-02-25 03:55:50 +0100
committerGitHub2023-02-24 21:55:50 -0500
commit10cdcb9ea8077098921d72720f9f36fcfd950452 (patch)
treee966411cf1bbc62bf7059deaa9238c14c0a9a04d /models
parent843f81113ebe71fd725210c5a382268333865cc7 (diff)
Add "Reviewed by you" filter for pull requests (#22927)
This includes pull requests that you approved, requested changes or commented on. Currently such pull requests are not visible in any of the filters on /pulls, while they may need further action like merging, or prodding the author or reviewers. Especially when working with a large team on a repository it's helpful to get a full overview of pull requests that may need your attention, without having to sift through the complete list.
Diffstat (limited to 'models')
-rw-r--r--models/issues/issue.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/models/issues/issue.go b/models/issues/issue.go
index c59e9d14e..edd74261e 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -1148,6 +1148,7 @@ type IssuesOptions struct { //nolint
PosterID int64
MentionedID int64
ReviewRequestedID int64
+ ReviewedID int64
SubscriberID int64
MilestoneIDs []int64
ProjectID int64
@@ -1262,6 +1263,10 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
applyReviewRequestedCondition(sess, opts.ReviewRequestedID)
}
+ if opts.ReviewedID > 0 {
+ applyReviewedCondition(sess, opts.ReviewedID)
+ }
+
if opts.SubscriberID > 0 {
applySubscribedCondition(sess, opts.SubscriberID)
}
@@ -1432,6 +1437,36 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64)
reviewRequestedID, ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest, reviewRequestedID)
}
+func applyReviewedCondition(sess *xorm.Session, reviewedID int64) *xorm.Session {
+ // Query for pull requests where you are a reviewer or commenter, excluding
+ // any pull requests already returned by the the review requested filter.
+ notPoster := builder.Neq{"issue.poster_id": reviewedID}
+ reviewed := builder.In("issue.id", builder.
+ Select("issue_id").
+ From("review").
+ Where(builder.And(
+ builder.Neq{"type": ReviewTypeRequest},
+ builder.Or(
+ builder.Eq{"reviewer_id": reviewedID},
+ builder.In("reviewer_team_id", builder.
+ Select("team_id").
+ From("team_user").
+ Where(builder.Eq{"uid": reviewedID}),
+ ),
+ ),
+ )),
+ )
+ commented := builder.In("issue.id", builder.
+ Select("issue_id").
+ From("comment").
+ Where(builder.And(
+ builder.Eq{"poster_id": reviewedID},
+ builder.In("type", CommentTypeComment, CommentTypeCode, CommentTypeReview),
+ )),
+ )
+ return sess.And(notPoster, builder.Or(reviewed, commented))
+}
+
func applySubscribedCondition(sess *xorm.Session, subscriberID int64) *xorm.Session {
return sess.And(
builder.
@@ -1586,6 +1621,7 @@ type IssueStats struct {
CreateCount int64
MentionCount int64
ReviewRequestedCount int64
+ ReviewedCount int64
}
// Filter modes.
@@ -1595,6 +1631,7 @@ const (
FilterModeCreate
FilterModeMention
FilterModeReviewRequested
+ FilterModeReviewed
FilterModeYourRepositories
)
@@ -1608,6 +1645,7 @@ type IssueStatsOptions struct {
MentionedID int64
PosterID int64
ReviewRequestedID int64
+ ReviewedID int64
IsPull util.OptionalBool
IssueIDs []int64
}
@@ -1646,6 +1684,7 @@ func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) {
accum.CreateCount += stats.CreateCount
accum.OpenCount += stats.MentionCount
accum.ReviewRequestedCount += stats.ReviewRequestedCount
+ accum.ReviewedCount += stats.ReviewedCount
i = chunk
}
return accum, nil
@@ -1703,6 +1742,10 @@ func getIssueStatsChunk(opts *IssueStatsOptions, issueIDs []int64) (*IssueStats,
applyReviewRequestedCondition(sess, opts.ReviewRequestedID)
}
+ if opts.ReviewedID > 0 {
+ applyReviewedCondition(sess, opts.ReviewedID)
+ }
+
switch opts.IsPull {
case util.OptionalBoolTrue:
sess.And("issue.is_pull=?", true)
@@ -1843,6 +1886,19 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
if err != nil {
return nil, err
}
+ case FilterModeReviewed:
+ stats.OpenCount, err = applyReviewedCondition(sess(cond), opts.UserID).
+ And("issue.is_closed = ?", false).
+ Count(new(Issue))
+ if err != nil {
+ return nil, err
+ }
+ stats.ClosedCount, err = applyReviewedCondition(sess(cond), opts.UserID).
+ And("issue.is_closed = ?", true).
+ Count(new(Issue))
+ if err != nil {
+ return nil, err
+ }
}
cond = cond.And(builder.Eq{"issue.is_closed": opts.IsClosed})
@@ -1871,6 +1927,11 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
return nil, err
}
+ stats.ReviewedCount, err = applyReviewedCondition(sess(cond), opts.UserID).Count(new(Issue))
+ if err != nil {
+ return nil, err
+ }
+
return stats, nil
}