Skip to content

Add review pending filter on pull request overview #13702

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 51 additions & 8 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,7 @@ type IssuesOptions struct {
AssigneeID int64
PosterID int64
MentionedID int64
ReviewPendingID int64
MilestoneIDs []int64
ProjectID int64
ProjectBoardID int64
Expand Down Expand Up @@ -1176,6 +1177,12 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
And("issue_user.uid = ?", opts.MentionedID)
}

if opts.ReviewPendingID > 0 {
sess.Join("INNER", []string{"review", "r"}, "issue.id = r.issue_id").
And("r.reviewer_id = ?", opts.ReviewPendingID).
And("r.type = ?", ReviewTypePending)
}

if len(opts.MilestoneIDs) > 0 {
sess.In("issue.milestone_id", opts.MilestoneIDs)
}
Expand Down Expand Up @@ -1359,6 +1366,7 @@ type IssueStats struct {
AssignCount int64
CreateCount int64
MentionCount int64
ReviewPendingCount int64
}

// Filter modes.
Expand All @@ -1367,6 +1375,7 @@ const (
FilterModeAssign
FilterModeCreate
FilterModeMention
FilterModeReviewPending
)

func parseCountResult(results []map[string][]byte) int64 {
Expand All @@ -1381,14 +1390,15 @@ func parseCountResult(results []map[string][]byte) int64 {

// IssueStatsOptions contains parameters accepted by GetIssueStats.
type IssueStatsOptions struct {
RepoID int64
Labels string
MilestoneID int64
AssigneeID int64
MentionedID int64
PosterID int64
IsPull util.OptionalBool
IssueIDs []int64
RepoID int64
Labels string
MilestoneID int64
AssigneeID int64
MentionedID int64
PosterID int64
ReviewPendingID int64
IsPull util.OptionalBool
IssueIDs []int64
}

// GetIssueStats returns issue statistic information by given conditions.
Expand Down Expand Up @@ -1417,6 +1427,7 @@ func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) {
accum.AssignCount += stats.AssignCount
accum.CreateCount += stats.CreateCount
accum.OpenCount += stats.MentionCount
accum.ReviewPendingCount += stats.ReviewPendingCount
i = chunk
}
return accum, nil
Expand Down Expand Up @@ -1468,6 +1479,12 @@ func getIssueStatsChunk(opts *IssueStatsOptions, issueIDs []int64) (*IssueStats,
And("issue_user.is_mentioned = ?", true)
}

if opts.ReviewPendingID > 0 {
sess.Join("INNER", []string{"review", "r"}, "issue.id = r.issue_id").
And("r.reviewer_id = ?", opts.ReviewPendingID).
And("r.type = ?", ReviewTypePending)
}

switch opts.IsPull {
case util.OptionalBoolTrue:
sess.And("issue.is_pull=?", true)
Expand Down Expand Up @@ -1573,6 +1590,23 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
if err != nil {
return nil, err
}
case FilterModeReviewPending:
stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
Join("INNER", []string{"review", "r"}, "issue.id = r.issue_id").
And("r.reviewer_id = ?", opts.UserID).
And("r.type = ?", ReviewTypePending).
Count(new(Issue))
if err != nil {
return nil, err
}
stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
Join("INNER", []string{"review", "r"}, "issue.id = r.issue_id").
And("r.reviewer_id = ?", opts.UserID).
And("r.type = ?", ReviewTypePending).
Count(new(Issue))
if err != nil {
return nil, err
}
}

cond = cond.And(builder.Eq{"issue.is_closed": opts.IsClosed})
Expand Down Expand Up @@ -1606,6 +1640,15 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
return nil, err
}

stats.ReviewPendingCount, err = x.Where(cond).
Join("INNER", []string{"review", "r"}, "issue.id = r.issue_id").
And("r.reviewer_id = ?", opts.UserID).
And("r.type = ?", ReviewTypePending).
Count(new(Issue))
if err != nil {
return nil, err
}

return stats, nil
}

Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ issues.filter_type.all_issues = All issues
issues.filter_type.assigned_to_you = Assigned to you
issues.filter_type.created_by_you = Created by you
issues.filter_type.mentioning_you = Mentioning you
issues.filter_type.review_pending = Review pending
issues.filter_sort = Sort
issues.filter_sort.latest = Newest
issues.filter_sort.oldest = Oldest
Expand Down
53 changes: 29 additions & 24 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,17 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
var err error
viewType := ctx.Query("type")
sortType := ctx.Query("sort")
types := []string{"all", "your_repositories", "assigned", "created_by", "mentioned"}
types := []string{"all", "your_repositories", "assigned", "created_by", "mentioned", "review_pending"}
if !com.IsSliceContainsStr(types, viewType) {
viewType = "all"
}

var (
assigneeID = ctx.QueryInt64("assignee")
posterID int64
mentionedID int64
forceEmpty bool
assigneeID = ctx.QueryInt64("assignee")
posterID int64
mentionedID int64
reviewPendingID int64
forceEmpty bool
)

if ctx.IsSigned {
Expand All @@ -133,6 +134,8 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
mentionedID = ctx.User.ID
case "assigned":
assigneeID = ctx.User.ID
case "review_pending":
reviewPendingID = ctx.User.ID
}
}

Expand Down Expand Up @@ -169,14 +172,15 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
issueStats = &models.IssueStats{}
} else {
issueStats, err = models.GetIssueStats(&models.IssueStatsOptions{
RepoID: repo.ID,
Labels: selectLabels,
MilestoneID: milestoneID,
AssigneeID: assigneeID,
MentionedID: mentionedID,
PosterID: posterID,
IsPull: isPullOption,
IssueIDs: issueIDs,
RepoID: repo.ID,
Labels: selectLabels,
MilestoneID: milestoneID,
AssigneeID: assigneeID,
MentionedID: mentionedID,
PosterID: posterID,
ReviewPendingID: reviewPendingID,
IsPull: isPullOption,
IssueIDs: issueIDs,
})
if err != nil {
ctx.ServerError("GetIssueStats", err)
Expand Down Expand Up @@ -217,17 +221,18 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
Page: pager.Paginater.Current(),
PageSize: setting.UI.IssuePagingNum,
},
RepoIDs: []int64{repo.ID},
AssigneeID: assigneeID,
PosterID: posterID,
MentionedID: mentionedID,
MilestoneIDs: mileIDs,
ProjectID: projectID,
IsClosed: util.OptionalBoolOf(isShowClosed),
IsPull: isPullOption,
LabelIDs: labelIDs,
SortType: sortType,
IssueIDs: issueIDs,
RepoIDs: []int64{repo.ID},
AssigneeID: assigneeID,
PosterID: posterID,
MentionedID: mentionedID,
ReviewPendingID: reviewPendingID,
MilestoneIDs: mileIDs,
ProjectID: projectID,
IsClosed: util.OptionalBoolOf(isShowClosed),
IsPull: isPullOption,
LabelIDs: labelIDs,
SortType: sortType,
IssueIDs: issueIDs,
})
if err != nil {
ctx.ServerError("Issues", err)
Expand Down
4 changes: 4 additions & 0 deletions routers/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ func Issues(ctx *context.Context) {
filterMode = models.FilterModeCreate
case "mentioned":
filterMode = models.FilterModeMention
case "review_pending":
filterMode = models.FilterModeReviewPending
case "your_repositories": // filterMode already set to All
default:
viewType = "your_repositories"
Expand Down Expand Up @@ -452,6 +454,8 @@ func Issues(ctx *context.Context) {
opts.PosterID = ctxUser.ID
case models.FilterModeMention:
opts.MentionedID = ctxUser.ID
case models.FilterModeReviewPending:
opts.ReviewPendingID = ctxUser.ID
}

var forceEmpty bool
Expand Down
3 changes: 3 additions & 0 deletions templates/repo/issue/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
<a class="{{if eq .ViewType "assigned"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=assigned&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.assigned_to_you"}}</a>
<a class="{{if eq .ViewType "created_by"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=created_by&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.created_by_you"}}</a>
<a class="{{if eq .ViewType "mentioned"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=mentioned&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.mentioning_you"}}</a>
{{if .PageIsPullList}}
<a class="{{if eq .ViewType "review_pending"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=review_pending&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.review_pending"}}</a>
{{end}}
</div>
</div>
{{end}}
Expand Down
1 change: 1 addition & 0 deletions templates/repo/issue/milestone_issues.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<a class="{{if eq .ViewType "assigned"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=assigned&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.assigned_to_you"}}</a>
<a class="{{if eq .ViewType "created_by"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=created_by&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.created_by_you"}}</a>
<a class="{{if eq .ViewType "mentioned"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=mentioned&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.mentioning_you"}}</a>
<a class="{{if eq .ViewType "review_pending"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type=review_pending&sort={{$.SortType}}&state={{$.State}}&labels={{.SelectLabels}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_type.review_pending"}}</a>
</div>
</div>
{{end}}
Expand Down
6 changes: 6 additions & 0 deletions templates/user/dashboard/issues.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
{{.i18n.Tr "repo.issues.filter_type.mentioning_you"}}
<strong class="ui right">{{CountFmt .IssueStats.MentionCount}}</strong>
</a>
{{if .PageIsPulls}}
<a class="{{if eq .ViewType "review_pending"}}ui basic blue button{{end}} item" href="{{.Link}}?type=review_pending&repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort={{$.SortType}}&state={{.State}}">
{{.i18n.Tr "repo.issues.filter_type.review_pending"}}
<strong class="ui right">{{CountFmt .IssueStats.ReviewPendingCount}}</strong>
</a>
{{end}}
{{end}}
<div class="ui divider"></div>
<a class="{{if not $.RepoIDs}}ui basic blue button{{end}} repo name item" href="{{$.Link}}?type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&q={{$.Keyword}}">
Expand Down