aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/issue.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-11-23 21:49:36 +0100
committerGitHub <noreply@github.com>2020-11-23 20:49:36 +0000
commitf88a2eae9777e0be612647bc17227c1ca13616ba (patch)
tree78aad7908e3fa61e674610cb24c7f4d1b8ad9bc2 /routers/api/v1/repo/issue.go
parent78204a7a71eedbc099aff51abd88cb16f60d50a8 (diff)
downloadgitea-f88a2eae9777e0be612647bc17227c1ca13616ba.tar.gz
gitea-f88a2eae9777e0be612647bc17227c1ca13616ba.zip
[API] Add more filters to issues search (#13514)
* Add time filter for issue search * Add limit option for paggination * Add Filter for: Created by User, Assigned to User, Mentioning User * update swagger * Add Tests for limit, before & since
Diffstat (limited to 'routers/api/v1/repo/issue.go')
-rw-r--r--routers/api/v1/repo/issue.go61
1 files changed, 58 insertions, 3 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index 0dbf2741ad..c58e0bb6ce 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -55,14 +55,48 @@ func SearchIssues(ctx *context.APIContext) {
// in: query
// description: filter by type (issues / pulls) if set
// type: string
+ // - name: since
+ // in: query
+ // description: Only show notifications updated after the given time. This is a timestamp in RFC 3339 format
+ // type: string
+ // format: date-time
+ // required: false
+ // - name: before
+ // in: query
+ // description: Only show notifications updated before the given time. This is a timestamp in RFC 3339 format
+ // type: string
+ // format: date-time
+ // required: false
+ // - name: assigned
+ // in: query
+ // description: filter (issues / pulls) assigned to you, default is false
+ // type: boolean
+ // - name: created
+ // in: query
+ // description: filter (issues / pulls) created by you, default is false
+ // type: boolean
+ // - name: mentioned
+ // in: query
+ // description: filter (issues / pulls) mentioning you, default is false
+ // type: boolean
// - name: page
// in: query
- // description: page number of requested issues
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results
// type: integer
// responses:
// "200":
// "$ref": "#/responses/IssueList"
+ before, since, err := utils.GetQueryBeforeSince(ctx)
+ if err != nil {
+ ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
+ return
+ }
+
var isClosed util.OptionalBool
switch ctx.Query("state") {
case "closed":
@@ -119,7 +153,6 @@ func SearchIssues(ctx *context.APIContext) {
}
var issueIDs []int64
var labelIDs []int64
- var err error
if len(keyword) > 0 && len(repoIDs) > 0 {
if issueIDs, err = issue_indexer.SearchIssuesByKeyword(repoIDs, keyword); err != nil {
ctx.Error(http.StatusInternalServerError, "SearchIssuesByKeyword", err)
@@ -143,13 +176,22 @@ func SearchIssues(ctx *context.APIContext) {
includedLabelNames = strings.Split(labels, ",")
}
+ // this api is also used in UI,
+ // so the default limit is set to fit UI needs
+ limit := ctx.QueryInt("limit")
+ if limit == 0 {
+ limit = setting.UI.IssuePagingNum
+ } else if limit > setting.API.MaxResponseItems {
+ limit = setting.API.MaxResponseItems
+ }
+
// Only fetch the issues if we either don't have a keyword or the search returned issues
// This would otherwise return all issues if no issues were found by the search.
if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
issuesOpt := &models.IssuesOptions{
ListOptions: models.ListOptions{
Page: ctx.QueryInt("page"),
- PageSize: setting.UI.IssuePagingNum,
+ PageSize: limit,
},
RepoIDs: repoIDs,
IsClosed: isClosed,
@@ -158,6 +200,19 @@ func SearchIssues(ctx *context.APIContext) {
SortType: "priorityrepo",
PriorityRepoID: ctx.QueryInt64("priority_repo_id"),
IsPull: isPull,
+ UpdatedBeforeUnix: before,
+ UpdatedAfterUnix: since,
+ }
+
+ // Filter for: Created by User, Assigned to User, Mentioning User
+ if ctx.QueryBool("created") {
+ issuesOpt.PosterID = ctx.User.ID
+ }
+ if ctx.QueryBool("assigned") {
+ issuesOpt.AssigneeID = ctx.User.ID
+ }
+ if ctx.QueryBool("mentioned") {
+ issuesOpt.MentionedID = ctx.User.ID
}
if issues, err = models.Issues(issuesOpt); err != nil {