Add bitbucket module for generating url to Cargo.toml

This commit is contained in:
Paul Woolcock 2018-02-12 15:37:57 -05:00
parent cc537251fe
commit 3ca1c7b238
2 changed files with 21 additions and 0 deletions

View file

@ -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<Uri, ::hyper::error::UriError> {
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::<Uri>()
}

View file

@ -6,6 +6,7 @@ use tokio_service::Service;
use ::models::repo::{RepoSite, RepoPath}; use ::models::repo::{RepoSite, RepoPath};
pub mod bitbucket;
pub mod crates; pub mod crates;
pub mod github; pub mod github;
pub mod gitlab; pub mod gitlab;
@ -34,6 +35,9 @@ impl<S> Service for RetrieveFileAtPath<S>
&RepoSite::Gitlab => { &RepoSite::Gitlab => {
gitlab::get_manifest_uri(&repo_path, &path) gitlab::get_manifest_uri(&repo_path, &path)
}, },
&RepoSite::Bitbucket => {
bitbucket::get_manifest_uri(&repo_path, &path)
}
}; };
let uri_future = uri.into_future().from_err(); let uri_future = uri.into_future().from_err();