-
- Notifications
You must be signed in to change notification settings - Fork 6.2k
Add API for Code Search #23004
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?
Add API for Code Search #23004
Conversation
| cool |
| Needs a rebase, sorry seems we missed this PR. |
According to contributing guideline, I guess it's better to avoid rebase. A normal merge and resolving conflicts is good enough. https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#code-review
Rebase sometimes causes unnoticeable code lost (it happened many time in history) |
| Yeah sorry, I mean "conflict resolution". I don't actually care whether it's rebase or merge. My own PRs, I rebase, but I guess this is because I simply have never used merge in the past, maybe I should consider it. |
| I'm not sure, if 500 the right HTTP Code to respond. Maybe 501 would be better. I also couldn't write tests. It looks like to code indexer does not work in the test suite. |
It seems enabled at least. |
routers/api/v1/repo/search.go Outdated
| // schema: | ||
| // type: string | ||
| if !setting.Indexer.RepoIndexerEnabled { | ||
| ctx.Error(http.StatusInternalServerError, "IndexerNotEnabled", "The Code Indexer is not enabled on this server") |
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.
Yes, 501 seems better here. Imho 500 should be reserved for unexpected errors. Also add it to the docs above.
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.
I don't think 5xx status codes would be correct in such cases. I would say if the feature is disabled and because of that API is not available it should be 4xx status code, I would say 404
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.
5xx means the problem is on the server side. 4xx on the client side. If code search is not enabled, the problem is on the server side.
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.
Problem is really on client side for calling API that is disabled (not there) thus 404 just like 403 for calling method you don't have rights
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.
5xx is for status codes where the server knows it should be able to complete but for unexpected reasons it cannot but it in this case server is not willing to complete the request because it's not just not possible thus it should be 4xx status code
| The API returns now 501 when the Indexer is disabled. I added also a API route for Global, Users and Orgs. I also found out, that I explicit need to Index a Repo during tests to make it work. |
This adds a PI for performing a Code Search on a Repo. It was a loot more work than expected. The Code is based on search.go from the Repo Web Router. I hope, I got the pagination right.