refactor: extract helper functions from SearchIssues (#36158)
## Summary This PR refactors the `SearchIssues` function in `routers/api/v1/repo/issue.go` by extracting common logic into reusable helper functions: - `parseIssueIsClosed()`: Parses the "state" query parameter and returns the corresponding `isClosed` option - `parseIssueIsPull()`: Parses the "type" query parameter and returns the corresponding `isPull` option - `buildSearchIssuesRepoIDs()`: Builds the list of repository IDs for issue search based on query parameters ### Benefits: - Improved code readability - Smaller, more focused functions - Easier to test individual components - Potential for reuse in other handlers ### Changes: - Extracted 3 helper functions from the ~292 line `SearchIssues` function - No functional changes - behavior remains the same - Proper error handling preserved ## Test plan - [ ] Verify existing API tests pass - [ ] Manual testing of `/repos/issues/search` endpoint Ref: #35015 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
committed by
GitHub
parent
bf0b377879
commit
b6ffe0e4e9
@@ -25,6 +25,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/routers/common"
|
||||
"code.gitea.io/gitea/routers/web/shared/issue"
|
||||
shared_user "code.gitea.io/gitea/routers/web/shared/user"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
@@ -45,15 +46,7 @@ func SearchIssues(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var isClosed optional.Option[bool]
|
||||
switch ctx.FormString("state") {
|
||||
case "closed":
|
||||
isClosed = optional.Some(true)
|
||||
case "all":
|
||||
isClosed = optional.None[bool]()
|
||||
default:
|
||||
isClosed = optional.Some(false)
|
||||
}
|
||||
isClosed := common.ParseIssueFilterStateIsClosed(ctx.FormString("state"))
|
||||
|
||||
var (
|
||||
repoIDs []int64
|
||||
@@ -268,15 +261,7 @@ func SearchRepoIssuesJSON(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var isClosed optional.Option[bool]
|
||||
switch ctx.FormString("state") {
|
||||
case "closed":
|
||||
isClosed = optional.Some(true)
|
||||
case "all":
|
||||
isClosed = optional.None[bool]()
|
||||
default:
|
||||
isClosed = optional.Some(false)
|
||||
}
|
||||
isClosed := common.ParseIssueFilterStateIsClosed(ctx.FormString("state"))
|
||||
|
||||
keyword := ctx.FormTrim("q")
|
||||
if strings.IndexByte(keyword, 0) >= 0 {
|
||||
@@ -580,17 +565,10 @@ func prepareIssueFilterAndList(ctx *context.Context, milestoneID, projectID int6
|
||||
}
|
||||
}
|
||||
|
||||
var isShowClosed optional.Option[bool]
|
||||
switch ctx.FormString("state") {
|
||||
case "closed":
|
||||
isShowClosed = optional.Some(true)
|
||||
case "all":
|
||||
isShowClosed = optional.None[bool]()
|
||||
default:
|
||||
isShowClosed = optional.Some(false)
|
||||
}
|
||||
isShowClosed := common.ParseIssueFilterStateIsClosed(ctx.FormString("state"))
|
||||
|
||||
// if there are closed issues and no open issues, default to showing all issues
|
||||
if len(ctx.FormString("state")) == 0 && issueStats.OpenCount == 0 && issueStats.ClosedCount != 0 {
|
||||
if ctx.FormString("state") == "" && issueStats.OpenCount == 0 && issueStats.ClosedCount != 0 {
|
||||
isShowClosed = optional.None[bool]()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user