diff --git a/src/interactors/bitbucket.rs b/src/interactors/bitbucket.rs new file mode 100644 index 0000000..d2f8401 --- /dev/null +++ b/src/interactors/bitbucket.rs @@ -0,0 +1,18 @@ +use failure::Error; +use hyper::Uri; +use relative_path::RelativePathBuf; + +use ::models::repo::RepoPath; + +const BITBUCKET_USER_CONTENT_BASE_URI: &'static str = "https://bitbucket.org"; + +pub fn get_manifest_uri(repo_path: &RepoPath, path: &RelativePathBuf) -> Result { + let path_str: &str = path.as_ref(); + Ok(format!("{}/{}/{}/raw/HEAD/{}", + BITBUCKET_USER_CONTENT_BASE_URI, + repo_path.qual.as_ref(), + repo_path.name.as_ref(), + path_str + ).parse::()?) +} + diff --git a/src/interactors/mod.rs b/src/interactors/mod.rs index 3224f8f..105eee6 100644 --- a/src/interactors/mod.rs +++ b/src/interactors/mod.rs @@ -6,6 +6,7 @@ use tokio_service::Service; use ::models::repo::{RepoSite, RepoPath}; +pub mod bitbucket; pub mod crates; pub mod github; pub mod gitlab; @@ -34,6 +35,9 @@ impl Service for RetrieveFileAtPath &RepoSite::Gitlab => { gitlab::get_manifest_uri(&repo_path, &path) }, + &RepoSite::Bitbucket => { + bitbucket::get_manifest_uri(&repo_path, &path) + } }; let uri_future = uri.into_future().from_err(); diff --git a/src/models/repo.rs b/src/models/repo.rs index daef7cd..d6a7fd1 100644 --- a/src/models/repo.rs +++ b/src/models/repo.rs @@ -29,13 +29,15 @@ impl RepoPath { pub enum RepoSite { Github, Gitlab, + Bitbucket, } impl RepoSite { pub fn to_base_uri(&self) -> &'static str { match self { &RepoSite::Github => "https://github.com", - &RepoSite::Gitlab => "https://gitlab.com" + &RepoSite::Gitlab => "https://gitlab.com", + &RepoSite::Bitbucket => "https://bitbucket.org", } } } @@ -47,6 +49,7 @@ impl FromStr for RepoSite { match input { "github" => Ok(RepoSite::Github), "gitlab" => Ok(RepoSite::Gitlab), + "bitbucket" => Ok(RepoSite::Bitbucket), _ => Err(format_err!("unknown repo site identifier")) } } @@ -56,7 +59,8 @@ impl AsRef for RepoSite { fn as_ref(&self) -> &str { match self { &RepoSite::Github => "github", - &RepoSite::Gitlab => "gitlab" + &RepoSite::Gitlab => "gitlab", + &RepoSite::Bitbucket => "bitbucket", } } } diff --git a/src/server/views/html/status.rs b/src/server/views/html/status.rs index 49ac18f..1e0e210 100644 --- a/src/server/views/html/status.rs +++ b/src/server/views/html/status.rs @@ -88,6 +88,7 @@ fn get_site_icon(repo_site: &RepoSite) -> &'static str { match *repo_site { RepoSite::Github => "fa-github", RepoSite::Gitlab => "fa-gitlab", + RepoSite::Bitbucket => "fa-bitbucket", } }