tavyandy97/span-tree

private deployment request error

BrightVan opened this issue · 16 comments

https://server_domain/api/v4/projects/group_name%2Fproject_name/repository/tree?per_page=10000&ref=master

this requets url is not work. get status code 404
i found another extenssion gitlab-code-view, can work well,and it's request url like this:

https://server_domain/group_name/project_name/files/master?format=json

Hey @BrightVan !

Thank you for reporting the issue, I assume you're using an older version of GitLab (i.e. lesser than v12). Could you please confirm your GitLab version?

The reason the latter API wasn't used to form a tree was for optimization purposes. It returns an array of all the filepaths, and in case of repositories with larger number of files (i.e. greater than 10,000) it would require a lot of parsing.

Therefore the v4 API was chosen to lazy load all the contents of the tree, rather than loading them all at once. It avoids the string parsing overhead along with fetching only the content that is required.

Hey @tavyandy97 !
my gitlab version is 12.7.5
image

@BrightVan
After looking at the documentation of GitLab v12.10, I verified that the route does exist and shouldn't have thrown a 404.

Is there any error message with the 404 error? Also, could you please match the API being called with the one mentioned in the documentation?

@tavyandy97
So , maybe the reason is my gitlab version is too low? the V12.7.5 does not support that route?

@BrightVan
Checked the GitLab Archived documentation for v12.7 and seems like the route does exist. After looking around this seems to be an issue with rails and not with GitLab.

Check the following links out

  1. StackOverflow - throws 404 page not found
  2. 404s for no apparent reason

i found the bug:
you should use project id number, but not group_name%2Fproject_name
the api below is ok, just like the offcial document:

https://gitlab.example.com/api/v4/projects/{id}/repository/tree

request like below, response 404 error.

https://gitlab.example.com/api/v4/projects/group_name%2Fproject_name/repository/tree

i do not know why your request url contact with projects/group_name%2Fproject_name but not id

conclusion:
compat api:

https://server_domain/group_name/project_name/files/master?format=json
// it response 301 and will redirect to :
https://server_domain/group_name/project_name/~/files/master?format=json

normal api:

https://gitlab.example.com/api/v4/projects/group_name%2Fproject_name/repository/tree

both api work fine with gitlab.com

but in my private deployment gitlab(i upgrade from 12.7.5 to 14.1.2)
normal api test by chrome response 404, unless replace the group_name%2Fproject_name to project_id, the response OK;
compat api test by chrome response OK, i enabled extension's compat mode, but the extension can not work, response is not 301, can not redirect and get data.

The files/master?format=json API is used for the Searchbar popup which is triggered using Ctrl/command+p. However, the projects/group_name%2Fproject_name/repository/tree API is used for displaying the tree in the left-side pane.

This still seems to be a rails configuration issue on your private deployment. I do agree that instead of group_name%2Fproject_name, project_id could have been used.

Could you confirm in your older Gitlab v12.x.x deployment whether a data-project-id attribute exists in the body (on a repository's page)?
Once confirmed we can start using project_id instead of group_name%2Fproject_name.

To answer your question, group_name%2Fproject_name was used as per the GitLab documentation. It states both ID or URL encoded path of the project can be used.

The files/master?format=json API is used for the Searchbar popup which is triggered using Ctrl/command+p. However, the projects/group_name%2Fproject_name/repository/tree API is used for displaying the tree in the left-side pane.

This still seems to be a rails configuration issue on your private deployment. I do agree that instead of group_name%2Fproject_name, project_id could have been used.

Could you confirm in your older Gitlab v12.x.x deployment whether a data-project-id attribute exists in the body (on a repository's page)?
Once confirmed we can start using project_id instead of group_name%2Fproject_name.

i see a old version(12.7.5) project screenshot, the project_id exist. and what rails configuration should i modefier? i can not find relevant document

My bad, in the issue I mentioned earlier, one of the cases seems to be the group_name%2Fproject_name having a . character in it. I assume there'll be other cases as well in which it might return a 404.

I'll start working on the changes, and let you know when they've been released.

Thanks again for reporting the issue 👍

Hey @BrightVan !

The issue has been resolved and merged. The version (v0.0.4.3) has been updated to the Chrome Webstore. Will be updating it on Mozilla Addons soon. Would appreciate it if you could verify the fix on your private deployment, and let me know if it works.

Feel free to provide more feedback! Do spread the word about SpanTree 🌳

Hey @BrightVan !

The issue has been resolved and merged. The version (v0.0.4.3) has been updated to the Chrome Webstore. Will be updating it on Mozilla Addons soon. Would appreciate it if you could verify the fix on your private deployment, and let me know if it works.

Feel free to provide more feedback! Do spread the word about SpanTree 🌳

Hey @tavyandy97

Thank you for your work.
theprojects/project_id/repository/tree API works well. it's enough for me!
but the files/master?format=json API can not work.

i think it's gitlab's bug, the reason is the page is https, but the redirect url is http, chrome block it (blocked:mixed-content).

and gitlab's page does not add:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

Could you try switching off Compatibility Mode?

Compatibility Mode uses the API /files/master?format=json, which causes a redirection to /-/files/master?format=json. With Compatibility Mode turned off, there will be no redirection and the extentsion will use /-/files/master?format=json.

image

Could you try switching off Compatibility Mode?

Compatibility Mode uses the API /files/master?format=json, which causes a redirection to /-/files/master?format=json. With Compatibility Mode turned off, there will be no redirection and the extentsion will use /-/files/master?format=json.

image

after swithing off Compat Mode, it work well, thanks

Closing the issue for now.

Feel free to open a new issue in case you run into an error or have any other concerns. Do spread the word about SpanTree 🌳