Merge pull request #24 from pwoolcoc/feature/add-bitbucket

add support for bitbucket repositories
This commit is contained in:
Sam Rijs 2018-02-13 15:42:37 +11:00 committed by GitHub
commit 831ad7a9ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

View file

@ -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<Uri, Error> {
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::<Uri>()?)
}

View file

@ -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<S> Service for RetrieveFileAtPath<S>
&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();

View file

@ -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<str> for RepoSite {
fn as_ref(&self) -> &str {
match self {
&RepoSite::Github => "github",
&RepoSite::Gitlab => "gitlab"
&RepoSite::Gitlab => "gitlab",
&RepoSite::Bitbucket => "bitbucket",
}
}
}

View file

@ -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",
}
}