allow multiple instances of gitlab to be configured
This commit is contained in:
35
src/gitlab/client.rs
Normal file
35
src/gitlab/client.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use crate::config::Config;
|
||||
use crate::error::GeneralError;
|
||||
use gitlab::AsyncGitlab;
|
||||
use gitlab::GitlabBuilder;
|
||||
use url::Url;
|
||||
|
||||
pub trait ClientProviderTrait {
|
||||
async fn client_for_url(url: &Url, config: &Config) -> Result<AsyncGitlab, GeneralError>;
|
||||
}
|
||||
|
||||
pub struct ClientProvider {}
|
||||
|
||||
impl ClientProviderTrait for ClientProvider {
|
||||
async fn client_for_url(url: &Url, config: &Config) -> Result<AsyncGitlab, GeneralError> {
|
||||
for c in &config.gitlab {
|
||||
if url.domain() == Some(c.domain.as_str()) {
|
||||
let client = GitlabBuilder::new("gitlab.com", c.token.clone())
|
||||
.build_async()
|
||||
.await;
|
||||
|
||||
return match client {
|
||||
Ok(new_client) => Ok(new_client),
|
||||
Err(e) => {
|
||||
let new_error = e.into();
|
||||
Err(new_error)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Err(GeneralError {
|
||||
description: format!("No client available for this domain: {:?}", url.domain()),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod client;
|
||||
pub mod issue;
|
||||
|
||||
use crate::error::GeneralError;
|
||||
|
||||
Reference in New Issue
Block a user