Skip to content
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

fix: normalize GitHub URLs ending in .git to not ending in .git #1804

Merged

Conversation

kristof-mattei
Copy link
Contributor

@kristof-mattei kristof-mattei commented Jun 28, 2024

Closes #1801, see #1803 for a more generic version.

Here I can add the test as the GhApiClient is never invoked.

Copy link
Member

@NobodyXu NobodyXu left a comment

Choose a reason for hiding this comment

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

Thank you!

Based on https://stackoverflow.com/questions/11068576/why-do-some-repository-urls-end-in-git-while-others-dont , I recommend to try url with stripped .git first, and then fallback to not stripping it, to keep the same behavior with git.

@NobodyXu
Copy link
Member

NobodyXu commented Jul 4, 2024

Pinging @kristof-mattei just in case you forgot this PR

@kristof-mattei
Copy link
Contributor Author

@NobodyXu These calls here (in the code I modified) never fail. It is only later on when trying to fetch the releases that the API doesn't respond with releases for repos ending in .git.

Now, if I understand correctly, you'd prefer that I revert this code, and then change the code around where the API for the releases itself gets called. First with the original URL, and if it fails AND ends in .git, try again with it trimmed?

@NobodyXu
Copy link
Member

NobodyXu commented Jul 5, 2024

Now, if I understand correctly, you'd prefer that I revert this code, and then change the code around where the API for the releases itself gets called. First with the original URL, and if it fails AND ends in .git, try again with it trimmed?

No, what I mean is to extract the repository detection logic here into a function, the call it twice:

  • First without the .git suffix
  • the fallback to with the suffix, if it has the suffix

I'd want the repository detection logic to only happen in get_repo_info, not when fetching artifacts.

@NobodyXu
Copy link
Member

NobodyXu commented Jul 6, 2024

These calls here (in the code I modified) never fail.

cc @kristof-mattei there's a GhApiClient::get_repo_info call which we uses to check if the repository exists:

match client.get_repo_info(&gh_repo).await {

In case where user does not provide a github token, we could use Client::get_redirected_final_url

I recommend you to start by doing something similar to GhRepo::try_extract_from_url to parse the git repository url.

If it cannot be parsed, then it is not a repo link (maybe a link to a specific dir within the repository) so it doesn't need stripping .git.

If it parses successfully then you can try strip the .git, if successful, then

Use either get_repo_info for github repo or get_redirected_final_url and return it if it can be accessed.

Otherwise just fallback to regular path.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This would help:
 - redirect public gh repo `.git` to its canonical form
 - redirect public gh repo, which has been recently renamed
 - cases where redirection is needed to get the real repo

This commit make it fallbacks to the previou surl, if getting
the redirected url fail, in case the repository is private.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@NobodyXu NobodyXu enabled auto-merge July 14, 2024 14:44
@NobodyXu
Copy link
Member

Thank you for this PR!

I happen to have some time so I took over the work and complete it.

@NobodyXu NobodyXu added this pull request to the merge queue Jul 14, 2024
Merged via the queue into cargo-bins:main with commit fdfc89c Jul 14, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When a package's repo ends with .git cargo-binstall fails to download the files from GitHub
2 participants