diff --git a/src/lib.rs b/src/lib.rs index 7806845..9fc5f0e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ use crate::{ cache::CacheState, config::Settings, error::{Error, Result}, - service::{Bitbucket, FormService, GitHub, Gitlab, Service}, + service::{Bitbucket, FormService, GitHub, Gitlab, Service, Sourcehut}, statics::{CLIENT, CSS, FAVICON, VERSION_INFO}, template::RepoInfo, }; @@ -490,6 +490,7 @@ async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Res .service(web::resource("/github/{user}/{repo}").to(calculate_hoc::)) .service(web::resource("/gitlab/{user}/{repo}").to(calculate_hoc::)) .service(web::resource("/bitbucket/{user}/{repo}").to(calculate_hoc::)) + .service(web::resource("/sourcehut/{user}/{repo}").to(calculate_hoc::)) .service( web::resource("/github/{user}/{repo}/delete") .route(web::post().to(delete_repo_and_cache::)), @@ -502,15 +503,21 @@ async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Res web::resource("/bitbucket/{user}/{repo}/delete") .route(web::post().to(delete_repo_and_cache::)), ) + .service( + web::resource("/sourcehut/{user}/{repo}/delete") + .route(web::post().to(delete_repo_and_cache::)), + ) .service(web::resource("/github/{user}/{repo}/json").to(json_hoc::)) .service(web::resource("/gitlab/{user}/{repo}/json").to(json_hoc::)) .service(web::resource("/bitbucket/{user}/{repo}/json").to(json_hoc::)) + .service(web::resource("/sourcehut/{user}/{repo}/json").to(json_hoc::)) .service(web::resource("/view/github/{user}/{repo}").to(overview::)) .service(web::resource("/view/gitlab/{user}/{repo}").to(overview::)) .service(web::resource("/view/bitbucket/{user}/{repo}").to(overview::)) .service(web::resource("/github/{user}/{repo}/view").to(overview::)) .service(web::resource("/gitlab/{user}/{repo}/view").to(overview::)) .service(web::resource("/bitbucket/{user}/{repo}/view").to(overview::)) + .service(web::resource("/sourcehut/{user}/{repo}/view").to(overview::)) .default_service(web::resource("").route(web::get().to(async_p404))) }) .workers(workers) diff --git a/src/service.rs b/src/service.rs index b9300e2..e80c744 100644 --- a/src/service.rs +++ b/src/service.rs @@ -12,6 +12,8 @@ pub(crate) enum FormService { Gitlab, #[serde(rename = "bitbucket")] Bitbucket, + #[serde(rename = "sourcehut")] + Sourcehut, } impl FormService { @@ -20,6 +22,7 @@ impl FormService { FormService::GitHub => "github.com", FormService::Gitlab => "gitlab.com", FormService::Bitbucket => "bitbucket.org", + FormService::Sourcehut => "git.sr.ht", } } @@ -28,6 +31,7 @@ impl FormService { FormService::GitHub => "github", FormService::Gitlab => "gitlab", FormService::Bitbucket => "bitbucket", + FormService::Sourcehut => "sourcehut", } } } @@ -73,3 +77,17 @@ impl Service for Bitbucket { format!("https://{}/{}/commits/{}", Self::domain(), repo, commit_ref) } } + +pub(crate) struct Sourcehut; + +impl Service for Sourcehut { + fn domain() -> &'static str { + "git.sr.ht" + } + fn url_path() -> &'static str { + "sourcehut" + } + fn commit_url(repo: &str, commit_ref: &str) -> String { + format!("https://{}/{}/commit/{}", Self::domain(), repo, commit_ref) + } +} diff --git a/templates/index.rs.html b/templates/index.rs.html index 76595ae..9dd2520 100644 --- a/templates/index.rs.html +++ b/templates/index.rs.html @@ -20,7 +20,7 @@ gives an overview about the amount of work put into a codebase.

There is a command-line tool to calculate the HoC of a repository, but some people might want a nice badge to put in their README, that's why I implemented this API. Currently the API can be -used for GitHub, GitLab and Bitbucket repositories. Just put the following code in your README: +used for GitHub, GitLab, Bitbucket and Sourcehut repositories. Just put the following code in your README:

@@ -28,8 +28,8 @@ used for GitHub, GitLab and Bitbucket repositories. Just put the following code
 

-where <service> is one of github, gitlab or bitbucket. So the -following Markdown +where <service> is one of github, gitlab, bitbucket or +sourcehut. So the following Markdown

@@ -74,6 +74,7 @@ the lines of
         
         
         
+