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

@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
@bimakw bimakw force-pushed the refactor/split-search-issues branch from e04b0bd to 8909fce Compare December 18, 2025 10:11
@bimakw
Copy link
Author

bimakw commented Dec 18, 2025

Thanks @lunny for the review! Updated to use || operator to consolidate the error handling conditions.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 18, 2025
- Add ErrOwnerOrgRequired custom error type to replace string comparison
- Refactor error handling to use proper Go error pattern
@bimakw bimakw force-pushed the refactor/split-search-issues branch from 8909fce to 70a5b58 Compare December 19, 2025 03:05
@bimakw
Copy link
Author

bimakw commented Dec 19, 2025

Thanks @wxiaoguang for the feedback! You're right - using string comparison for errors is fragile.

I've added a proper custom error type ErrOwnerOrgRequired with IsErrOwnerOrgRequired() helper function, following the same pattern used elsewhere in the codebase (e.g., ErrOrgNotExist, ErrTeamNotExist).

@wxiaoguang wxiaoguang force-pushed the refactor/split-search-issues branch from 8a97ad1 to 1d28fc2 Compare December 19, 2025 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 1 This PR needs approval from one additional maintainer to be merged. 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.

4 participants