use crate::config::{Config, GitlabConfig}; use crate::error::GeneralError; use gitlab::{AsyncGitlab, GitlabBuilder}; use url::Url; pub struct ClientProvider {} impl ClientProvider {} fn is_client_for_url(url: &Url, config: &GitlabConfig) -> bool { if url.domain() == Some(config.domain.as_str()) { return true; } false } pub async fn client_for_url(url: &Url, config: &Config) -> Result { for c in &config.gitlab { if is_client_for_url(url, c) { 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()), }) } pub fn has_client_for_url(url: &Url, config: &Config) -> bool { for c in &config.gitlab { if is_client_for_url(url, c) { return true; } } false }