From 3ca1c7b238eb5d153f745fb3bd1e5dfa00187eb8 Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Mon, 12 Feb 2018 15:37:57 -0500 Subject: [PATCH] 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();