From cc537251fe6d8dd62c90f79ebefb5a917091e0ad Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Mon, 12 Feb 2018 15:32:00 -0500 Subject: [PATCH 1/6] Add 'Bitbucket' to RepoSite enum --- src/models/repo.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/models/repo.rs b/src/models/repo.rs index daef7cd..97c07f5 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 => "https://bitbucket.org", } } } From 3ca1c7b238eb5d153f745fb3bd1e5dfa00187eb8 Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Mon, 12 Feb 2018 15:37:57 -0500 Subject: [PATCH 2/6] Add bitbucket module for generating url to Cargo.toml --- src/interactors/bitbucket.rs | 17 +++++++++++++++++ src/interactors/mod.rs | 4 ++++ 2 files changed, 21 insertions(+) create mode 100644 src/interactors/bitbucket.rs diff --git a/src/interactors/bitbucket.rs b/src/interactors/bitbucket.rs new file mode 100644 index 0000000..b21e8b4 --- /dev/null +++ b/src/interactors/bitbucket.rs @@ -0,0 +1,17 @@ +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(); + format!("{}/{}/{}/raw/master/{}", + 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(); From ca4cd5273d8897a738fce8cf496afc1967b68308 Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Mon, 12 Feb 2018 15:38:33 -0500 Subject: [PATCH 3/6] Add fa-bitbucket to get_site_icon Closes #6 --- src/server/views/html/status.rs | 1 + 1 file changed, 1 insertion(+) 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", } } From 161e29e6d6e640cdfb113302da45416e9b80a629 Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Mon, 12 Feb 2018 22:32:54 -0500 Subject: [PATCH 4/6] use failure::Error instead of hyper::error::UriError --- src/interactors/bitbucket.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/interactors/bitbucket.rs b/src/interactors/bitbucket.rs index b21e8b4..c058553 100644 --- a/src/interactors/bitbucket.rs +++ b/src/interactors/bitbucket.rs @@ -1,3 +1,4 @@ +use failure::Error; use hyper::Uri; use relative_path::RelativePathBuf; @@ -5,13 +6,13 @@ 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 { +pub fn get_manifest_uri(repo_path: &RepoPath, path: &RelativePathBuf) -> Result { let path_str: &str = path.as_ref(); - format!("{}/{}/{}/raw/master/{}", + Ok(format!("{}/{}/{}/raw/master/{}", BITBUCKET_USER_CONTENT_BASE_URI, repo_path.qual.as_ref(), repo_path.name.as_ref(), path_str - ).parse::() + ).parse::()?) } From 107840c6eea49d6bcfa69bfdca8e03fc6c2a86bc Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Mon, 12 Feb 2018 22:33:16 -0500 Subject: [PATCH 5/6] use HEAD instead of master --- src/interactors/bitbucket.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interactors/bitbucket.rs b/src/interactors/bitbucket.rs index c058553..d2f8401 100644 --- a/src/interactors/bitbucket.rs +++ b/src/interactors/bitbucket.rs @@ -8,7 +8,7 @@ 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/master/{}", + Ok(format!("{}/{}/{}/raw/HEAD/{}", BITBUCKET_USER_CONTENT_BASE_URI, repo_path.qual.as_ref(), repo_path.name.as_ref(), From bd2482a3cd6896791a14b7fc21563edb95b54145 Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Mon, 12 Feb 2018 23:37:29 -0500 Subject: [PATCH 6/6] Whoops, wrong string here --- src/models/repo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/repo.rs b/src/models/repo.rs index 97c07f5..d6a7fd1 100644 --- a/src/models/repo.rs +++ b/src/models/repo.rs @@ -60,7 +60,7 @@ impl AsRef for RepoSite { match self { &RepoSite::Github => "github", &RepoSite::Gitlab => "gitlab", - &RepoSite::Bitbucket => "https://bitbucket.org", + &RepoSite::Bitbucket => "bitbucket", } } }