Skip to content

Conversation

@bimakw
Copy link

@bimakw bimakw commented Dec 14, 2025

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

Split the SearchIssues function into smaller, more maintainable pieces:

- parseIssueIsClosed: parses "state" query parameter
- parseIssueIsPull: parses "type" query parameter
- buildSearchIssuesRepoIDs: builds repository IDs list for search

This improves code readability and makes the logic easier to test
and reuse.

Ref: go-gitea#35015
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 14, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Dec 14, 2025
Replace fmt.Errorf with errors.New for better performance as suggested
by perfsprint linter.
if err != nil {
repoIDs, allPublic, err := buildSearchIssuesRepoIDs(ctx)
if err != nil {
if user_model.IsErrUserNotExist(err) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use ||?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants