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
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
@@ -60,12 +59,7 @@ func ListMilestones(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
state := api.StateType(ctx.FormString("state"))
|
||||
var isClosed optional.Option[bool]
|
||||
switch state {
|
||||
case api.StateClosed, api.StateOpen:
|
||||
isClosed = optional.Some(state == api.StateClosed)
|
||||
}
|
||||
isClosed := common.ParseIssueFilterStateIsClosed(ctx.FormString("state"))
|
||||
|
||||
milestones, total, err := db.FindAndCount[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
|
||||
Reference in New Issue
Block a user