Skip to content

Conversation

@bimakw
Copy link
Contributor

@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
Contributor 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
Contributor 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
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 20, 2025
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 20, 2025
@lunny lunny merged commit b6ffe0e into go-gitea:main Dec 21, 2025
24 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Dec 21, 2025
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 21, 2025
zjjhot added a commit to zjjhot/gitea that referenced this pull request Dec 22, 2025
* giteaofficial/main:
  Fix WebAuthn error checking (go-gitea#36219)
  [skip ci] Updated translations via Crowdin
  refactor: extract helper functions from SearchIssues (go-gitea#36158)
  [skip ci] Updated translations via Crowdin
  Revert "[skip ci] Updated translations via Crowdin"
  Closed milestones with no issues now show as 100% completed (go-gitea#36220)
  Show edit page confirmation dialog on tree view file change (go-gitea#36130)
  Fix regression in writing authorized principals (go-gitea#36213)
  [skip ci] Updated translations via Crowdin
  Convert locale files from ini to json format (go-gitea#35489)
  Bump crowdin/github-action from 1 to 2 (go-gitea#36204)
  Bump appleboy/git-push-action from 0.0.3 to 1.0.0 (go-gitea#36194)
  Fix labeler config for stylelint (go-gitea#36199)
  Add `modifies/dependencies` label to dependabot (go-gitea#36206)
  Add date to "No Contributions" tooltip (go-gitea#36190)
  Revert "Bump alpine to 3.23 (go-gitea#36185)" (go-gitea#36202)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. 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