allow multiple instances of gitlab to be configured

This commit is contained in:
2024-03-17 21:34:03 +01:00
parent 34f6eac006
commit df71e1073c
8 changed files with 80 additions and 39 deletions

35
src/gitlab/client.rs Normal file
View 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()),
})
}
}

View File

@@ -1,3 +1,4 @@
pub mod client;
pub mod issue;
use crate::error::GeneralError;