Implemented Gitea actions to support converting Gitea issues into work packages in OpenProject. Modified various modules to include necessary structs, functions, and tests to handle Gitea issues, ensure URL validation, and adapt work package creation based on Gitea issues.
49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
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<AsyncGitlab, GeneralError> {
|
|
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
|
|
}
|