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
if err != nil {
repoIDs, allPublic, err := buildSearchIssuesRepoIDs(ctx)
if err != nil {
if user_model.IsErrUserNotExist(err) || organization.IsErrTeamNotExist(err) || err.Error() == "owner organisation is required for filtering on team" {
Copy link
Contributor

Choose a reason for hiding this comment

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

err.Error() == "owner organisation is required for filtering on team"

please don't do this, it is an abuse to Golang error system and is very fragile.

- 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).

opts.AllLimited = true
}
if ctx.FormString("owner") != "" {
owner, err := user_model.GetUserByName(ctx, ctx.FormString("owner"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems not right, the "owner" can only be "UserTypeIndividual" now

Related to Add new user types reserved, bot, and remote (#24026), that PR seems wrong.

Copy link
Contributor

@wxiaoguang wxiaoguang Dec 19, 2025

Choose a reason for hiding this comment

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

Wait for Need a complete fix for broken GetUserByName #36208

OK, just go with this without waiting for that issue

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