mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-24 19:16:31 +00:00
Add gitlab self hosted alternative
This commit is contained in:
parent
031878a61a
commit
4a2413950b
2 changed files with 20 additions and 7 deletions
|
@ -49,10 +49,11 @@ impl fmt::Display for RepoPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::similar_names)]
|
||||||
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
||||||
pub enum RepoSite {
|
pub enum RepoSite {
|
||||||
Github,
|
Github,
|
||||||
Gitlab,
|
Gitlab(Option<GiteaDomain>),
|
||||||
Bitbucket,
|
Bitbucket,
|
||||||
Sourcehut,
|
Sourcehut,
|
||||||
Codeberg,
|
Codeberg,
|
||||||
|
@ -63,7 +64,8 @@ impl RepoSite {
|
||||||
pub fn to_base_uri(&self) -> &str {
|
pub fn to_base_uri(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
RepoSite::Github => "https://github.com",
|
RepoSite::Github => "https://github.com",
|
||||||
RepoSite::Gitlab => "https://gitlab.com",
|
RepoSite::Gitlab(None) => "https://gitlab.com",
|
||||||
|
RepoSite::Gitlab(Some(domain)) => domain.as_ref(),
|
||||||
RepoSite::Bitbucket => "https://bitbucket.org",
|
RepoSite::Bitbucket => "https://bitbucket.org",
|
||||||
RepoSite::Sourcehut => "https://git.sr.ht",
|
RepoSite::Sourcehut => "https://git.sr.ht",
|
||||||
RepoSite::Codeberg => "https://codeberg.org",
|
RepoSite::Codeberg => "https://codeberg.org",
|
||||||
|
@ -74,7 +76,8 @@ impl RepoSite {
|
||||||
pub fn to_usercontent_base_uri(&self) -> &str {
|
pub fn to_usercontent_base_uri(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
RepoSite::Github => "https://raw.githubusercontent.com",
|
RepoSite::Github => "https://raw.githubusercontent.com",
|
||||||
RepoSite::Gitlab => "https://gitlab.com",
|
RepoSite::Gitlab(None) => "https://gitlab.com",
|
||||||
|
RepoSite::Gitlab(Some(domain)) => domain.as_ref(),
|
||||||
RepoSite::Bitbucket => "https://bitbucket.org",
|
RepoSite::Bitbucket => "https://bitbucket.org",
|
||||||
RepoSite::Sourcehut => "https://git.sr.ht",
|
RepoSite::Sourcehut => "https://git.sr.ht",
|
||||||
RepoSite::Codeberg => "https://codeberg.org",
|
RepoSite::Codeberg => "https://codeberg.org",
|
||||||
|
@ -85,7 +88,7 @@ impl RepoSite {
|
||||||
pub fn to_usercontent_repo_suffix(&self) -> &'static str {
|
pub fn to_usercontent_repo_suffix(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
RepoSite::Github => "HEAD",
|
RepoSite::Github => "HEAD",
|
||||||
RepoSite::Gitlab | RepoSite::Bitbucket => "raw/HEAD",
|
RepoSite::Gitlab(_) | RepoSite::Bitbucket => "raw/HEAD",
|
||||||
RepoSite::Sourcehut => "blob/HEAD",
|
RepoSite::Sourcehut => "blob/HEAD",
|
||||||
RepoSite::Codeberg | RepoSite::Gitea(_) => "raw",
|
RepoSite::Codeberg | RepoSite::Gitea(_) => "raw",
|
||||||
}
|
}
|
||||||
|
@ -99,12 +102,13 @@ impl FromStr for RepoSite {
|
||||||
if let Some((site, domain)) = input.split_once('/') {
|
if let Some((site, domain)) = input.split_once('/') {
|
||||||
match site {
|
match site {
|
||||||
"gitea" => Ok(RepoSite::Gitea(domain.parse()?)),
|
"gitea" => Ok(RepoSite::Gitea(domain.parse()?)),
|
||||||
|
"gitlab" => Ok(RepoSite::Gitlab(Some(domain.parse()?))),
|
||||||
_ => Err(anyhow!("unknown repo site identifier")),
|
_ => Err(anyhow!("unknown repo site identifier")),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match input {
|
match input {
|
||||||
"github" => Ok(RepoSite::Github),
|
"github" => Ok(RepoSite::Github),
|
||||||
"gitlab" => Ok(RepoSite::Gitlab),
|
"gitlab" => Ok(RepoSite::Gitlab(None)),
|
||||||
"bitbucket" => Ok(RepoSite::Bitbucket),
|
"bitbucket" => Ok(RepoSite::Bitbucket),
|
||||||
"sourcehut" => Ok(RepoSite::Sourcehut),
|
"sourcehut" => Ok(RepoSite::Sourcehut),
|
||||||
"codeberg" => Ok(RepoSite::Codeberg),
|
"codeberg" => Ok(RepoSite::Codeberg),
|
||||||
|
@ -118,7 +122,8 @@ impl fmt::Display for RepoSite {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
RepoSite::Github => write!(f, "github"),
|
RepoSite::Github => write!(f, "github"),
|
||||||
RepoSite::Gitlab => write!(f, "gitlab"),
|
RepoSite::Gitlab(None) => write!(f, "gitlab"),
|
||||||
|
RepoSite::Gitlab(Some(s)) => write!(f, "gitlab/{s}"),
|
||||||
RepoSite::Bitbucket => write!(f, "bitbucket"),
|
RepoSite::Bitbucket => write!(f, "bitbucket"),
|
||||||
RepoSite::Sourcehut => write!(f, "sourcehut"),
|
RepoSite::Sourcehut => write!(f, "sourcehut"),
|
||||||
RepoSite::Codeberg => write!(f, "codeberg"),
|
RepoSite::Codeberg => write!(f, "codeberg"),
|
||||||
|
@ -267,5 +272,13 @@ mod tests {
|
||||||
let exp = format!("https://example.com/git/deps-rs/deps.rs/raw/{expected}");
|
let exp = format!("https://example.com/git/deps-rs/deps.rs/raw/{expected}");
|
||||||
assert_eq!(out.to_string(), exp);
|
assert_eq!(out.to_string(), exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (input, expected) in &paths {
|
||||||
|
let repo = RepoPath::from_parts("gitlab/gitlab.com", "deps-rs", "deps.rs").unwrap();
|
||||||
|
let out = repo.to_usercontent_file_url(RelativePath::new(input));
|
||||||
|
|
||||||
|
let exp = format!("https://gitlab.com/deps-rs/deps.rs/raw/HEAD/{expected}");
|
||||||
|
assert_eq!(out.to_string(), exp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ fn dependency_table(title: &str, deps: &IndexMap<CrateName, AnalyzedDependency>)
|
||||||
fn get_site_icon(site: &RepoSite) -> (FaType, &'static str) {
|
fn get_site_icon(site: &RepoSite) -> (FaType, &'static str) {
|
||||||
match *site {
|
match *site {
|
||||||
RepoSite::Github => (FaType::Brands, "github"),
|
RepoSite::Github => (FaType::Brands, "github"),
|
||||||
RepoSite::Gitlab => (FaType::Brands, "gitlab"),
|
RepoSite::Gitlab(_) => (FaType::Brands, "gitlab"),
|
||||||
RepoSite::Bitbucket => (FaType::Brands, "bitbucket"),
|
RepoSite::Bitbucket => (FaType::Brands, "bitbucket"),
|
||||||
// FIXME: There is no brands/{sourcehut, codeberg, gitea} icon, so just use an
|
// FIXME: There is no brands/{sourcehut, codeberg, gitea} icon, so just use an
|
||||||
// icon which looks close enough.
|
// icon which looks close enough.
|
||||||
|
|
Loading…
Reference in a new issue