pub struct GitLabClient { /* private fields */ }Expand description
The main client for interacting with the GitLab API.
This client provides access to all GitLab API operations including pipelines, jobs, runners, merge requests, and more.
§Examples
use gitlab_manager::{GitLabClient, error::Result};
#[tokio::main]
async fn main() -> Result<()> {
let client = GitLabClient::new("https://gitlab.com", "your-token")?;
// List pipelines
let pipelines = client.pipelines("myproject").list().await?;
// Get specific pipeline
let pipeline = client.pipeline("myproject", 123).get().await?;
Ok(())
}Implementations§
Source§impl GitLabClient
impl GitLabClient
Sourcepub fn new(url: &str, token: &str) -> Result<Self>
pub fn new(url: &str, token: &str) -> Result<Self>
Creates a new GitLab client with the specified URL and personal access token.
§Arguments
url- The GitLab instance URL (e.g., “https://gitlab.com”)token- A GitLab personal access token with appropriate permissions
§Errors
Returns GitLabError::Config if the URL is invalid or the token is malformed.
Returns GitLabError::Authentication if the credentials are invalid.
§Examples
use gitlab_manager::GitLabClient;
let client = GitLabClient::new("https://gitlab.com", "glpat-xxxxxxxxxxxx")?;Sourcepub fn client(&self) -> &Gitlab
pub fn client(&self) -> &Gitlab
Returns a reference to the underlying GitLab API client.
This provides direct access to the gitlab crate’s client for advanced use cases
not covered by this library’s API.
§Examples
use gitlab_manager::GitLabClient;
let client = GitLabClient::new("https://gitlab.com", "token")?;
let raw_client = client.client();Sourcepub fn pipelines(&self, project: impl Into<String>) -> PipelineListBuilder<'_>
pub fn pipelines(&self, project: impl Into<String>) -> PipelineListBuilder<'_>
Creates a builder for listing pipelines in a project.
§Arguments
project- The project path (e.g., “myorg/myproject”) or ID
§Examples
use gitlab_manager::{GitLabClient, models::PipelineStatus};
let client = GitLabClient::new("https://gitlab.com", "token")?;
// List all pipelines
let all = client.pipelines("myorg/myproject").list().await?;
// List failed pipelines on main branch
let failed = client.pipelines("myorg/myproject")
.status(PipelineStatus::Failed)
.ref_name("main")
.limit(10)
.list()
.await?;Sourcepub fn pipeline(
&self,
project: impl Into<String>,
pipeline_id: u64,
) -> PipelineBuilder<'_>
pub fn pipeline( &self, project: impl Into<String>, pipeline_id: u64, ) -> PipelineBuilder<'_>
Creates a builder for operations on a specific pipeline.
§Arguments
project- The project path (e.g., “myorg/myproject”) or IDpipeline_id- The pipeline ID
§Examples
use gitlab_manager::GitLabClient;
let client = GitLabClient::new("https://gitlab.com", "token")?;
// Get pipeline details
let pipeline = client.pipeline("myorg/myproject", 12345).get().await?;
// Retry a failed pipeline
client.pipeline("myorg/myproject", 12345).retry().await?;
// Cancel a running pipeline
client.pipeline("myorg/myproject", 12345).cancel().await?;Sourcepub fn jobs(&self, project: impl Into<String>) -> JobListBuilder<'_>
pub fn jobs(&self, project: impl Into<String>) -> JobListBuilder<'_>
Creates a builder for listing jobs in a project or pipeline.
§Arguments
project- The project path (e.g., “myorg/myproject”) or ID
§Examples
use gitlab_manager::{GitLabClient, models::JobStatus};
let client = GitLabClient::new("https://gitlab.com", "token")?;
// List jobs in a specific pipeline
let jobs = client.jobs("myorg/myproject")
.pipeline(12345)
.list()
.await?;
// List failed jobs
let failed = client.jobs("myorg/myproject")
.pipeline(12345)
.status(JobStatus::Failed)
.list()
.await?;Sourcepub fn job(&self, project: impl Into<String>, job_id: u64) -> JobBuilder<'_>
pub fn job(&self, project: impl Into<String>, job_id: u64) -> JobBuilder<'_>
Creates a builder for operations on a specific job.
§Arguments
project- The project path (e.g., “myorg/myproject”) or IDjob_id- The job ID
§Examples
use gitlab_manager::GitLabClient;
let client = GitLabClient::new("https://gitlab.com", "token")?;
// Get job details
let job = client.job("myorg/myproject", 67890).get().await?;
// Retry a failed job
client.job("myorg/myproject", 67890).retry().await?;
// Get job logs
let logs = client.job("myorg/myproject", 67890).logs().await?;Sourcepub fn project(&self, project: impl Into<String>) -> ProjectBuilder<'_>
pub fn project(&self, project: impl Into<String>) -> ProjectBuilder<'_>
Creates a builder for project-level operations.
Use this for operations at the project scope, such as creating pipelines.
§Arguments
project- The project path (e.g., “myorg/myproject”) or ID
§Examples
use gitlab_manager::GitLabClient;
let client = GitLabClient::new("https://gitlab.com", "token")?;
// Trigger a new pipeline
let pipeline = client.project("myorg/myproject")
.create_pipeline()
.ref_name("main")
.variable("ENVIRONMENT", "production")
.trigger()
.await?;
println!("Created pipeline #{}", pipeline.id);Auto Trait Implementations§
impl Freeze for GitLabClient
impl !RefUnwindSafe for GitLabClient
impl Send for GitLabClient
impl Sync for GitLabClient
impl Unpin for GitLabClient
impl !UnwindSafe for GitLabClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more