mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 18:36:30 +00:00
Merge pull request #24 from pwoolcoc/feature/add-bitbucket
add support for bitbucket repositories
This commit is contained in:
commit
831ad7a9ae
4 changed files with 29 additions and 2 deletions
18
src/interactors/bitbucket.rs
Normal file
18
src/interactors/bitbucket.rs
Normal 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>()?)
|
||||||
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -29,13 +29,15 @@ impl RepoPath {
|
||||||
pub enum RepoSite {
|
pub enum RepoSite {
|
||||||
Github,
|
Github,
|
||||||
Gitlab,
|
Gitlab,
|
||||||
|
Bitbucket,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RepoSite {
|
impl RepoSite {
|
||||||
pub fn to_base_uri(&self) -> &'static str {
|
pub fn to_base_uri(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
&RepoSite::Github => "https://github.com",
|
&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 {
|
match input {
|
||||||
"github" => Ok(RepoSite::Github),
|
"github" => Ok(RepoSite::Github),
|
||||||
"gitlab" => Ok(RepoSite::Gitlab),
|
"gitlab" => Ok(RepoSite::Gitlab),
|
||||||
|
"bitbucket" => Ok(RepoSite::Bitbucket),
|
||||||
_ => Err(format_err!("unknown repo site identifier"))
|
_ => Err(format_err!("unknown repo site identifier"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +59,8 @@ impl AsRef<str> for RepoSite {
|
||||||
fn as_ref(&self) -> &str {
|
fn as_ref(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
&RepoSite::Github => "github",
|
&RepoSite::Github => "github",
|
||||||
&RepoSite::Gitlab => "gitlab"
|
&RepoSite::Gitlab => "gitlab",
|
||||||
|
&RepoSite::Bitbucket => "bitbucket",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ fn get_site_icon(repo_site: &RepoSite) -> &'static str {
|
||||||
match *repo_site {
|
match *repo_site {
|
||||||
RepoSite::Github => "fa-github",
|
RepoSite::Github => "fa-github",
|
||||||
RepoSite::Gitlab => "fa-gitlab",
|
RepoSite::Gitlab => "fa-gitlab",
|
||||||
|
RepoSite::Bitbucket => "fa-bitbucket",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue