mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-18 00:26:37 +00:00
Support subcrate in repo (#991)
Fixed #838 - Add new key `subcrate` for rendering `pkg-url` - Add new release paths in GitHub, GitLab & SourceForge using key `subcrate` for auto-detection - Add subcrate detection for GitHub and GitLab - Add `debug!` when using gh api token in `GhApiClient::new` - Add subcrate testing to `e2e-tests/subcrate.sh` - Bump cargo-release to 0.24.9 in e2e-tests/live.sh to fix test failure on MacOS without libssl installed in `/usr/local/`. - Optimize GhCrateMeta: Detect subcrate and repo-host in `Data::get_repo_info` to cache the result and avoid duplicate works, this also makes the code more ergonomic by removing the need to some `unwrap()` plus making it more efficient since we don't need to clone the url just to modify it. - Add instrument to `Data::get_repo_info` - Fix `shellcheck` err in `e2e-tests/*.sh` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
5e269193c0
commit
0261d12d9d
15 changed files with 234 additions and 40 deletions
|
@ -3,9 +3,7 @@ use leon::{Item, Template};
|
|||
use leon_macros::template;
|
||||
use url::Url;
|
||||
|
||||
use crate::errors::BinstallError;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum RepositoryHost {
|
||||
GitHub,
|
||||
GitLab,
|
||||
|
@ -35,11 +33,17 @@ pub const NOVERSION_FILENAMES: &[Template<'_>] = &[
|
|||
const GITHUB_RELEASE_PATHS: &[Template<'_>] = &[
|
||||
template!("{ repo }/releases/download/{ version }"),
|
||||
template!("{ repo }/releases/download/v{ version }"),
|
||||
// %2F is escaped form of '/'
|
||||
template!("{ repo }/releases/download/{ subcrate }%2F{ version }"),
|
||||
template!("{ repo }/releases/download/{ subcrate }%2Fv{ version }"),
|
||||
];
|
||||
|
||||
const GITLAB_RELEASE_PATHS: &[Template<'_>] = &[
|
||||
template!("{ repo }/-/releases/{ version }/downloads/binaries"),
|
||||
template!("{ repo }/-/releases/v{ version }/downloads/binaries"),
|
||||
// %2F is escaped form of '/'
|
||||
template!("{ repo }/-/releases/{ subcrate }%2F{ version }/downloads/binaries"),
|
||||
template!("{ repo }/-/releases/{ subcrate }%2Fv{ version }/downloads/binaries"),
|
||||
];
|
||||
|
||||
const BITBUCKET_RELEASE_PATHS: &[Template<'_>] = &[template!("{ repo }/downloads")];
|
||||
|
@ -47,18 +51,21 @@ const BITBUCKET_RELEASE_PATHS: &[Template<'_>] = &[template!("{ repo }/downloads
|
|||
const SOURCEFORGE_RELEASE_PATHS: &[Template<'_>] = &[
|
||||
template!("{ repo }/files/binaries/{ version }"),
|
||||
template!("{ repo }/files/binaries/v{ version }"),
|
||||
// %2F is escaped form of '/'
|
||||
template!("{ repo }/files/binaries/{ subcrate }%2F{ version }"),
|
||||
template!("{ repo }/files/binaries/{ subcrate }%2Fv{ version }"),
|
||||
];
|
||||
|
||||
impl RepositoryHost {
|
||||
pub fn guess_git_hosting_services(repo: &Url) -> Result<Self, BinstallError> {
|
||||
pub fn guess_git_hosting_services(repo: &Url) -> Self {
|
||||
use RepositoryHost::*;
|
||||
|
||||
match repo.domain() {
|
||||
Some(domain) if domain.starts_with("github") => Ok(GitHub),
|
||||
Some(domain) if domain.starts_with("gitlab") => Ok(GitLab),
|
||||
Some(domain) if domain == "bitbucket.org" => Ok(BitBucket),
|
||||
Some(domain) if domain == "sourceforge.net" => Ok(SourceForge),
|
||||
_ => Ok(Unknown),
|
||||
Some(domain) if domain.starts_with("github") => GitHub,
|
||||
Some(domain) if domain.starts_with("gitlab") => GitLab,
|
||||
Some(domain) if domain == "bitbucket.org" => BitBucket,
|
||||
Some(domain) if domain == "sourceforge.net" => SourceForge,
|
||||
_ => Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue