use crate::api::jobs::{JobBuilder, JobListBuilder};
use crate::api::pipelines::{PipelineBuilder, PipelineListBuilder};
use crate::api::projects::ProjectBuilder;
use crate::api::variables::VariableBuilder;
use crate::error::{GitLabError, Result};
use gitlab::Gitlab;
pub struct GitLabClient {
client: Gitlab,
}
impl GitLabClient {
pub fn new(url: &str, token: &str) -> Result<Self> {
if url.is_empty() {
return Err(GitLabError::config("GitLab URL cannot be empty"));
}
if token.is_empty() {
return Err(GitLabError::config("GitLab token cannot be empty"));
}
let client = Gitlab::new(url, token)
.map_err(|e| GitLabError::config(format!("Failed to create GitLab client: {}", e)))?;
Ok(Self { client })
}
pub fn client(&self) -> &Gitlab {
&self.client
}
pub fn pipelines(&self, project: impl Into<String>) -> PipelineListBuilder<'_> {
PipelineListBuilder::new(&self.client, project)
}
pub fn pipeline(&self, project: impl Into<String>, pipeline_id: u64) -> PipelineBuilder<'_> {
PipelineBuilder::new(&self.client, project, pipeline_id)
}
pub fn jobs(&self, project: impl Into<String>) -> JobListBuilder<'_> {
JobListBuilder::new(&self.client, project)
}
pub fn job(&self, project: impl Into<String>, job_id: u64) -> JobBuilder<'_> {
JobBuilder::new(&self.client, project, job_id)
}
pub fn project(&self, project: impl Into<String>) -> ProjectBuilder<'_> {
ProjectBuilder::new(&self.client, project)
}
pub fn variables(&self, project: impl Into<String>) -> VariableBuilder<'_> {
VariableBuilder::new(&self.client, project)
}
}