mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-15 23:26:36 +00:00
fix: normalize GitHub URLs ending in .git to not ending in .git
This commit is contained in:
parent
a39cf031f9
commit
7eca355cc3
1 changed files with 59 additions and 12 deletions
|
@ -206,20 +206,41 @@ impl Data {
|
||||||
let subcrate = RepoInfo::detect_subcrate(&mut repo, repository_host);
|
let subcrate = RepoInfo::detect_subcrate(&mut repo, repository_host);
|
||||||
|
|
||||||
let mut is_private = false;
|
let mut is_private = false;
|
||||||
if repository_host == RepositoryHost::GitHub && client.has_gh_token() {
|
if repository_host == RepositoryHost::GitHub {
|
||||||
if let Some(gh_repo) = GhRepo::try_extract_from_url(&repo) {
|
// ensure the URL does not end with .git
|
||||||
loop {
|
if repo.as_str().ends_with(".git") {
|
||||||
match client.get_repo_info(&gh_repo).await {
|
let repo_name_segment = repo
|
||||||
Ok(Some(gh_repo_info)) => {
|
.path_segments()
|
||||||
is_private = gh_repo_info.is_private();
|
.expect("GitHub URLs always have a base")
|
||||||
break;
|
.last()
|
||||||
}
|
.expect("path_segments() always returns at least 1 element");
|
||||||
Ok(None) => return Err(GhApiError::NotFound.into()),
|
|
||||||
Err(GhApiError::RateLimit { retry_after }) => {
|
let repo_name = repo_name_segment.trim_end_matches(".git").to_owned();
|
||||||
sleep(retry_after.unwrap_or(DEFAULT_GH_API_RETRY_DURATION))
|
|
||||||
|
repo.path_segments_mut()
|
||||||
|
.expect("GitHub URLs always have a base")
|
||||||
|
.pop()
|
||||||
|
.push(&repo_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if client.has_gh_token() {
|
||||||
|
if let Some(gh_repo) = GhRepo::try_extract_from_url(&repo) {
|
||||||
|
loop {
|
||||||
|
match client.get_repo_info(&gh_repo).await {
|
||||||
|
Ok(Some(gh_repo_info)) => {
|
||||||
|
is_private = gh_repo_info.is_private();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Ok(None) => return Err(GhApiError::NotFound.into()),
|
||||||
|
Err(GhApiError::RateLimit { retry_after }) => {
|
||||||
|
sleep(
|
||||||
|
retry_after
|
||||||
|
.unwrap_or(DEFAULT_GH_API_RETRY_DURATION),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
|
}
|
||||||
|
Err(err) => return Err(err.into()),
|
||||||
}
|
}
|
||||||
Err(err) => return Err(err.into()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,6 +343,8 @@ pub type TargetDataErased = TargetData<dyn leon::Values + Send + Sync + 'static>
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use std::num::{NonZeroU16, NonZeroU64};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -388,4 +411,28 @@ mod test {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_ignore_dot_git_for_github_repos() {
|
||||||
|
let url_without_git = "https://github.com/cargo-bins/cargo-binstall";
|
||||||
|
let url_with_git = format!("{}.git", url_without_git);
|
||||||
|
|
||||||
|
let data = Data::new("cargo-binstall".into(), "v1.2.3".into(), Some(url_with_git));
|
||||||
|
|
||||||
|
let gh_client = GhApiClient::new(
|
||||||
|
Client::new(
|
||||||
|
"user-agent",
|
||||||
|
None,
|
||||||
|
NonZeroU16::new(1000).unwrap(),
|
||||||
|
NonZeroU64::new(1000).unwrap(),
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
|
let repo_info = data.get_repo_info(&gh_client).await.unwrap().unwrap();
|
||||||
|
|
||||||
|
assert_eq!(url_without_git, repo_info.repo.as_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue