@@ -12,6 +12,7 @@ import (
12
12
13
13
"code.gitea.io/gitea/models"
14
14
"code.gitea.io/gitea/modules/context"
15
+ "code.gitea.io/gitea/modules/indexer"
15
16
"code.gitea.io/gitea/modules/setting"
16
17
"code.gitea.io/gitea/modules/util"
17
18
)
@@ -42,6 +43,10 @@ func ListIssues(ctx *context.APIContext) {
42
43
// in: query
43
44
// description: page number of requested issues
44
45
// type: integer
46
+ // - name: q
47
+ // in: query
48
+ // description: search string
49
+ // type: string
45
50
// responses:
46
51
// "200":
47
52
// "$ref": "#/responses/IssueList"
@@ -55,12 +60,30 @@ func ListIssues(ctx *context.APIContext) {
55
60
isClosed = util .OptionalBoolFalse
56
61
}
57
62
58
- issues , err := models .Issues (& models.IssuesOptions {
59
- RepoIDs : []int64 {ctx .Repo .Repository .ID },
60
- Page : ctx .QueryInt ("page" ),
61
- PageSize : setting .UI .IssuePagingNum ,
62
- IsClosed : isClosed ,
63
- })
63
+ var issues []* models.Issue
64
+
65
+ keyword := strings .Trim (ctx .Query ("q" ), " " )
66
+ if strings .IndexByte (keyword , 0 ) >= 0 {
67
+ keyword = ""
68
+ }
69
+ var issueIDs []int64
70
+ var err error
71
+ if len (keyword ) > 0 {
72
+ issueIDs , err = indexer .SearchIssuesByKeyword (ctx .Repo .Repository .ID , keyword )
73
+ }
74
+
75
+ // Only fetch the issues if we either don't have a keyword or the search returned issues
76
+ // This would otherwise return all issues if no issues were found by the search.
77
+ if len (keyword ) == 0 || len (issueIDs ) > 0 {
78
+ issues , err = models .Issues (& models.IssuesOptions {
79
+ RepoIDs : []int64 {ctx .Repo .Repository .ID },
80
+ Page : ctx .QueryInt ("page" ),
81
+ PageSize : setting .UI .IssuePagingNum ,
82
+ IsClosed : isClosed ,
83
+ IssueIDs : issueIDs ,
84
+ })
85
+ }
86
+
64
87
if err != nil {
65
88
ctx .Error (500 , "Issues" , err )
66
89
return
0 commit comments