-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
refactor: extract helper functions from SearchIssues #36158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
e04b0bd to
8909fce
Compare
|
Thanks @lunny for the review! Updated to use |
routers/api/v1/repo/issue.go
Outdated
| 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" { |
There was a problem hiding this comment.
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
8909fce to
70a5b58
Compare
|
Thanks @wxiaoguang for the feedback! You're right - using string comparison for errors is fragile. I've added a proper custom error type |
| opts.AllLimited = true | ||
| } | ||
| if ctx.FormString("owner") != "" { | ||
| owner, err := user_model.GetUserByName(ctx, ctx.FormString("owner")) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Summary
This PR refactors the
SearchIssuesfunction inrouters/api/v1/repo/issue.goby extracting common logic into reusable helper functions:parseIssueIsClosed(): Parses the "state" query parameter and returns the correspondingisClosedoptionparseIssueIsPull(): Parses the "type" query parameter and returns the correspondingisPulloptionbuildSearchIssuesRepoIDs(): Builds the list of repository IDs for issue search based on query parametersBenefits:
Changes:
SearchIssuesfunctionTest plan
/repos/issues/searchendpointRef: #35015