@@ -24,6 +24,7 @@ import (
2424 "code.gitea.io/gitea/modules/setting"
2525 api "code.gitea.io/gitea/modules/structs"
2626 "code.gitea.io/gitea/modules/timeutil"
27+ "code.gitea.io/gitea/modules/util"
2728 "code.gitea.io/gitea/modules/web"
2829 "code.gitea.io/gitea/routers/api/v1/utils"
2930 "code.gitea.io/gitea/routers/common"
@@ -32,43 +33,6 @@ import (
3233 issue_service "code.gitea.io/gitea/services/issue"
3334)
3435
35- // ErrOwnerOrgRequired represents an error when owner organisation is required for filtering on team
36- type ErrOwnerOrgRequired struct {}
37-
38- // IsErrOwnerOrgRequired checks if an error is an ErrOwnerOrgRequired
39- func IsErrOwnerOrgRequired (err error ) bool {
40- _ , ok := err .(ErrOwnerOrgRequired )
41- return ok
42- }
43-
44- func (err ErrOwnerOrgRequired ) Error () string {
45- return "owner organisation is required for filtering on team"
46- }
47-
48- // parseIssueIsClosed parses the "state" query parameter and returns the corresponding isClosed option
49- func parseIssueIsClosed (ctx * context.APIContext ) optional.Option [bool ] {
50- switch ctx .FormString ("state" ) {
51- case "closed" :
52- return optional .Some (true )
53- case "all" :
54- return optional .None [bool ]()
55- default :
56- return optional .Some (false )
57- }
58- }
59-
60- // parseIssueIsPull parses the "type" query parameter and returns the corresponding isPull option
61- func parseIssueIsPull (ctx * context.APIContext ) optional.Option [bool ] {
62- switch ctx .FormString ("type" ) {
63- case "pulls" :
64- return optional .Some (true )
65- case "issues" :
66- return optional .Some (false )
67- default :
68- return optional .None [bool ]()
69- }
70- }
71-
7236// buildSearchIssuesRepoIDs builds the list of repository IDs for issue search based on query parameters.
7337// It returns repoIDs, allPublic flag, and any error that occurred.
7438func buildSearchIssuesRepoIDs (ctx * context.APIContext ) ([]int64 , bool , error ) {
@@ -101,7 +65,7 @@ func buildSearchIssuesRepoIDs(ctx *context.APIContext) ([]int64, bool, error) {
10165 }
10266 if ctx .FormString ("team" ) != "" {
10367 if ctx .FormString ("owner" ) == "" {
104- return nil , false , ErrOwnerOrgRequired {}
68+ return nil , false , util . NewInvalidArgumentErrorf ( "owner organisation is required for filtering on team" )
10569 }
10670 team , err := organization .GetTeam (ctx , opts .OwnerID , ctx .FormString ("team" ))
10771 if err != nil {
@@ -230,11 +194,11 @@ func SearchIssues(ctx *context.APIContext) {
230194 return
231195 }
232196
233- isClosed := parseIssueIsClosed (ctx )
197+ isClosed := common . ParseIssueFilterStateIsClosed (ctx . FormString ( "state" ) )
234198
235199 repoIDs , allPublic , err := buildSearchIssuesRepoIDs (ctx )
236200 if err != nil {
237- if user_model . IsErrUserNotExist (err ) || organization . IsErrTeamNotExist ( err ) || IsErrOwnerOrgRequired (err ) {
201+ if errors . Is (err , util . ErrNotExist ) || errors . Is (err , util . ErrInvalidArgument ) {
238202 ctx .APIError (http .StatusBadRequest , err )
239203 } else {
240204 ctx .APIErrorInternal (err )
@@ -247,7 +211,7 @@ func SearchIssues(ctx *context.APIContext) {
247211 keyword = ""
248212 }
249213
250- isPull := parseIssueIsPull (ctx )
214+ isPull := common . ParseIssueFilterTypeIsPull (ctx . FormString ( "type" ) )
251215
252216 var includedAnyLabels []int64
253217 {
@@ -430,16 +394,7 @@ func ListIssues(ctx *context.APIContext) {
430394 return
431395 }
432396
433- var isClosed optional.Option [bool ]
434- switch ctx .FormString ("state" ) {
435- case "closed" :
436- isClosed = optional .Some (true )
437- case "all" :
438- isClosed = optional .None [bool ]()
439- default :
440- isClosed = optional .Some (false )
441- }
442-
397+ isClosed := common .ParseIssueFilterStateIsClosed (ctx .FormString ("state" ))
443398 keyword := ctx .FormTrim ("q" )
444399 if strings .IndexByte (keyword , 0 ) >= 0 {
445400 keyword = ""
0 commit comments