GitLabClient

Struct GitLabClient 

Source
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

Source

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")?;
Source

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();
Source

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?;
Source

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 ID
  • pipeline_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?;
Source

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?;
Source

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 ID
  • job_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?;
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more