mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-24 11:06: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)]
|
||||
pub enum RepoSite {
|
||||
Github,
|
||||
Gitlab,
|
||||
Gitlab(Option<GiteaDomain>),
|
||||
Bitbucket,
|
||||
Sourcehut,
|
||||
Codeberg,
|
||||
|
@ -63,7 +64,8 @@ impl RepoSite {
|
|||
pub fn to_base_uri(&self) -> &str {
|
||||
match self {
|
||||
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::Sourcehut => "https://git.sr.ht",
|
||||
RepoSite::Codeberg => "https://codeberg.org",
|
||||
|
@ -74,7 +76,8 @@ impl RepoSite {
|
|||
pub fn to_usercontent_base_uri(&self) -> &str {
|
||||
match self {
|
||||
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::Sourcehut => "https://git.sr.ht",
|
||||
RepoSite::Codeberg => "https://codeberg.org",
|
||||
|
@ -85,7 +88,7 @@ impl RepoSite {
|
|||
pub fn to_usercontent_repo_suffix(&self) -> &'static str {
|
||||
match self {
|
||||
RepoSite::Github => "HEAD",
|
||||
RepoSite::Gitlab | RepoSite::Bitbucket => "raw/HEAD",
|
||||
RepoSite::Gitlab(_) | RepoSite::Bitbucket => "raw/HEAD",
|
||||
RepoSite::Sourcehut => "blob/HEAD",
|
||||
RepoSite::Codeberg | RepoSite::Gitea(_) => "raw",
|
||||
}
|
||||
|
@ -99,12 +102,13 @@ impl FromStr for RepoSite {
|
|||
if let Some((site, domain)) = input.split_once('/') {
|
||||
match site {
|
||||
"gitea" => Ok(RepoSite::Gitea(domain.parse()?)),
|
||||
"gitlab" => Ok(RepoSite::Gitlab(Some(domain.parse()?))),
|
||||
_ => Err(anyhow!("unknown repo site identifier")),
|
||||
}
|
||||
} else {
|
||||
match input {
|
||||
"github" => Ok(RepoSite::Github),
|
||||
"gitlab" => Ok(RepoSite::Gitlab),
|
||||
"gitlab" => Ok(RepoSite::Gitlab(None)),
|
||||
"bitbucket" => Ok(RepoSite::Bitbucket),
|
||||
"sourcehut" => Ok(RepoSite::Sourcehut),
|
||||
"codeberg" => Ok(RepoSite::Codeberg),
|
||||
|
@ -118,7 +122,8 @@ impl fmt::Display for RepoSite {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
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::Sourcehut => write!(f, "sourcehut"),
|
||||
RepoSite::Codeberg => write!(f, "codeberg"),
|
||||
|
@ -267,5 +272,13 @@ mod tests {
|
|||
let exp = format!("https://example.com/git/deps-rs/deps.rs/raw/{expected}");
|
||||
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) {
|
||||
match *site {
|
||||
RepoSite::Github => (FaType::Brands, "github"),
|
||||
RepoSite::Gitlab => (FaType::Brands, "gitlab"),
|
||||
RepoSite::Gitlab(_) => (FaType::Brands, "gitlab"),
|
||||
RepoSite::Bitbucket => (FaType::Brands, "bitbucket"),
|
||||
// FIXME: There is no brands/{sourcehut, codeberg, gitea} icon, so just use an
|
||||
// icon which looks close enough.
|
||||
|
|
Loading…
Reference in a new issue