Skip to content

Conversation

@JakobDev
Copy link
Contributor

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.

@wolfogre wolfogre added type/feature Completely new functionality. Can only be merged if feature freeze is not active. modifies/api This PR adds API routes or modifies them labels Feb 21, 2023
@wolfogre wolfogre added this to the 1.20.0 milestone Feb 21, 2023
@yi-ge
Copy link

yi-ge commented Feb 23, 2023

cool

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 23, 2023
@silverwind
Copy link
Member

silverwind commented May 10, 2023

Needs a rebase, sorry seems we missed this PR.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented May 10, 2023

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

Once code review starts on your PR, do not rebase nor squash your branch as it makes ....

Rebase sometimes causes unnoticeable code lost (it happened many time in history)

@silverwind
Copy link
Member

silverwind commented May 10, 2023

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.

@delvh delvh removed this from the 1.20.0 milestone Jun 4, 2023
@JakobDev
Copy link
Contributor Author

JakobDev commented Sep 7, 2023

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.

@silverwind
Copy link
Member

silverwind commented Sep 7, 2023

I also couldn't write tests. It looks like to code indexer does not work in the test suite.

It seems enabled at least.

// schema:
// type: string
if !setting.Indexer.RepoIndexerEnabled {
ctx.Error(http.StatusInternalServerError, "IndexerNotEnabled", "The Code Indexer is not enabled on this server")
Copy link
Member

@silverwind silverwind Sep 7, 2023

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.

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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

@JakobDev
Copy link
Contributor Author

JakobDev commented Sep 11, 2023

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.

@JakobDev JakobDev requested a review from silverwind September 11, 2023 14:56
@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 Sep 11, 2023
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 type/feature Completely new functionality. Can only be merged if feature freeze is not active.

10 participants