From 8bdee6b770a0ea735a2067ebc8fc5d79dc673320 Mon Sep 17 00:00:00 2001 From: Atk Date: Wed, 19 Jan 2022 00:51:33 +0000 Subject: [PATCH] Codeberg support (#134) --- README.md | 2 +- src/models/repo.rs | 14 ++++++++++++++ src/server/views/html/status.rs | 6 +++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bb448f0..c06fd29 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ We currently support projects and crates hosted on crates.io, Github, Gitlab, Bi To analyze the state of your dependencies you can use the following URLs: - for projects on crates.io: `https://deps.rs/crate/` -- for projects on Github, Gitlab, Bitbucket, or SourceHut: `https://deps.rs/repo///` (where `` is either `github`, `gitlab`, `bitbucket`, or `sourcehut`) +- for projects on Github, Gitlab, Bitbucket, SourceHut, or Codeberg: `https://deps.rs/repo///` (where `` is either `github`, `gitlab`, `bitbucket`, `sourcehut`, or `codeberg`) On the analysis page, you will also find the markdown code to include a fancy badge in your project README so visitors (and you) can see at a glance if your dependencies are still up to date! diff --git a/src/models/repo.rs b/src/models/repo.rs index d266580..7b867cb 100644 --- a/src/models/repo.rs +++ b/src/models/repo.rs @@ -55,6 +55,7 @@ pub enum RepoSite { Gitlab, Bitbucket, Sourcehut, + Codeberg, } impl RepoSite { @@ -64,6 +65,7 @@ impl RepoSite { RepoSite::Gitlab => "https://gitlab.com", RepoSite::Bitbucket => "https://bitbucket.org", RepoSite::Sourcehut => "https://git.sr.ht", + RepoSite::Codeberg => "https://codeberg.org", } } @@ -73,6 +75,7 @@ impl RepoSite { RepoSite::Gitlab => "https://gitlab.com", RepoSite::Bitbucket => "https://bitbucket.org", RepoSite::Sourcehut => "https://git.sr.ht", + RepoSite::Codeberg => "https://codeberg.org", } } @@ -81,6 +84,7 @@ impl RepoSite { RepoSite::Github => "HEAD", RepoSite::Gitlab | RepoSite::Bitbucket => "raw/HEAD", RepoSite::Sourcehut => "blob/HEAD", + RepoSite::Codeberg => "raw", } } } @@ -94,6 +98,7 @@ impl FromStr for RepoSite { "gitlab" => Ok(RepoSite::Gitlab), "bitbucket" => Ok(RepoSite::Bitbucket), "sourcehut" => Ok(RepoSite::Sourcehut), + "codeberg" => Ok(RepoSite::Codeberg), _ => Err(anyhow!("unknown repo site identifier")), } } @@ -106,6 +111,7 @@ impl AsRef for RepoSite { RepoSite::Gitlab => "gitlab", RepoSite::Bitbucket => "bitbucket", RepoSite::Sourcehut => "sourcehut", + RepoSite::Codeberg => "codeberg", } } } @@ -201,5 +207,13 @@ mod tests { ); assert_eq!(out.to_string(), exp); } + + for (input, expected) in &paths { + let repo = RepoPath::from_parts("codeberg", "deps-rs", "deps.rs").unwrap(); + let out = repo.to_usercontent_file_url(RelativePath::new(input)); + + let exp = format!("https://codeberg.org/deps-rs/deps.rs/raw/{}", expected); + assert_eq!(out.to_string(), exp); + } } } diff --git a/src/server/views/html/status.rs b/src/server/views/html/status.rs index c70d18a..475959b 100644 --- a/src/server/views/html/status.rs +++ b/src/server/views/html/status.rs @@ -126,9 +126,9 @@ fn get_site_icon(site: &RepoSite) -> (FaType, &'static str) { RepoSite::Github => (FaType::Brands, "github"), RepoSite::Gitlab => (FaType::Brands, "gitlab"), RepoSite::Bitbucket => (FaType::Brands, "bitbucket"), - // FIXME: There is no brands/sourcehut icon, so just use a regular - // circle which looks pretty much like sr.ht's circle. - RepoSite::Sourcehut => (FaType::Regular, "circle"), + // FIXME: There is no brands/{sourcehut, codeberg} icon, so just use a + // regular circle which looks close enough. + RepoSite::Sourcehut | RepoSite::Codeberg => (FaType::Regular, "circle"), } }