From 0066bc511321d393065fb17a0c91f15b8e483fe5 Mon Sep 17 00:00:00 2001 From: parnic Date: Mon, 8 Aug 2022 15:03:58 -0500 Subject: [PATCH] Add issue filter for Author (#20578) This adds a new filter option on the issues and pulls pages to filter by the author/poster/creator of the issue or PR --- models/repo/user_repo.go | 12 +++++ options/locale/locale_en-US.ini | 2 + routers/web/repo/issue.go | 10 +++- templates/repo/issue/list.tmpl | 54 ++++++++++++++-------- templates/repo/issue/milestone_issues.tmpl | 46 ++++++++++++------ templates/repo/issue/openclose.tmpl | 4 +- templates/repo/issue/search.tmpl | 1 + templates/shared/issuelist.tmpl | 2 +- 8 files changed, 93 insertions(+), 38 deletions(-) diff --git a/models/repo/user_repo.go b/models/repo/user_repo.go index 71e0c5755..6c0a241dc 100644 --- a/models/repo/user_repo.go +++ b/models/repo/user_repo.go @@ -170,3 +170,15 @@ func GetReviewers(ctx context.Context, repo *Repository, doerID, posterID int64) users := make([]*user_model.User, 0, 8) return users, db.GetEngine(ctx).Where(cond).OrderBy(user_model.GetOrderByName()).Find(&users) } + +// GetIssuePosters returns all users that have authored an issue/pull request for the given repository +func GetIssuePosters(ctx context.Context, repo *Repository, isPull bool) ([]*user_model.User, error) { + users := make([]*user_model.User, 0, 8) + cond := builder.In("`user`.id", + builder.Select("poster_id").From("issue").Where( + builder.Eq{"repo_id": repo.ID}. + And(builder.Eq{"is_pull": isPull}), + ).GroupBy("poster_id"), + ) + return users, db.GetEngine(ctx).Where(cond).OrderBy(user_model.GetOrderByName()).Find(&users) +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 783783617..426521e4e 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1269,6 +1269,8 @@ issues.filter_milestone = Milestone issues.filter_milestone_no_select = All milestones issues.filter_assignee = Assignee issues.filter_assginee_no_select = All assignees +issues.filter_poster = Author +issues.filter_poster_no_select = All authors issues.filter_type = Type issues.filter_type.all_issues = All issues issues.filter_type.assigned_to_you = Assigned to you diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index e6f9529e3..ad25a94e1 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -133,7 +133,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti var ( assigneeID = ctx.FormInt64("assignee") - posterID int64 + posterID = ctx.FormInt64("poster") mentionedID int64 reviewRequestedID int64 forceEmpty bool @@ -291,6 +291,12 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti return } + ctx.Data["Posters"], err = repo_model.GetIssuePosters(ctx, repo, isPullOption.IsTrue()) + if err != nil { + ctx.ServerError("GetIssuePosters", err) + return + } + handleTeamMentions(ctx) if ctx.Written() { return @@ -364,6 +370,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti ctx.Data["SortType"] = sortType ctx.Data["MilestoneID"] = milestoneID ctx.Data["AssigneeID"] = assigneeID + ctx.Data["PosterID"] = posterID ctx.Data["IsShowClosed"] = isShowClosed ctx.Data["Keyword"] = keyword if isShowClosed { @@ -379,6 +386,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti pager.AddParam(ctx, "labels", "SelectLabels") pager.AddParam(ctx, "milestone", "MilestoneID") pager.AddParam(ctx, "assignee", "AssigneeID") + pager.AddParam(ctx, "poster", "PosterID") ctx.Data["Page"] = pager } diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 2a53239f1..8e8c256c5 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -46,9 +46,9 @@ @@ -60,9 +60,25 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}} + + + + @@ -74,9 +90,9 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}} @@ -109,14 +125,14 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}} diff --git a/templates/repo/issue/milestone_issues.tmpl b/templates/repo/issue/milestone_issues.tmpl index 484d0a811..0f00e9284 100644 --- a/templates/repo/issue/milestone_issues.tmpl +++ b/templates/repo/issue/milestone_issues.tmpl @@ -52,9 +52,25 @@ + + + + @@ -66,9 +82,9 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}} {{end}} @@ -100,12 +116,12 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}} diff --git a/templates/repo/issue/openclose.tmpl b/templates/repo/issue/openclose.tmpl index 9242d0c5c..ccfb40684 100644 --- a/templates/repo/issue/openclose.tmpl +++ b/templates/repo/issue/openclose.tmpl @@ -1,5 +1,5 @@ diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index d1555c16c..f4e0674be 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -43,7 +43,7 @@ {{end}} {{range .Labels}} - {{.Name | RenderEmoji}} + {{.Name | RenderEmoji}} {{end}}