| Crates.io | lmrc-gitlab |
| lib.rs | lmrc-gitlab |
| version | 0.3.16 |
| created_at | 2025-11-26 18:21:41.014967+00 |
| updated_at | 2025-12-11 13:26:23.255129+00 |
| description | GitLab API client library for the LMRC Stack - comprehensive Rust library for programmatic control of GitLab via its API |
| homepage | https://gitlab.com/lemarco/lmrc-stack/tree/main/libs/gitlab-manager |
| repository | https://gitlab.com/lemarco/lmrc-stack |
| max_upload_size | |
| id | 1951973 |
| size | 172,909 |
Part of the LMRC Stack - Infrastructure-as-Code toolkit for building production-ready Rust applications
A comprehensive Rust library for programmatic control of GitLab via its API.
Add this to your Cargo.toml:
[dependencies]
lmrc-gitlab = "0.1.0"
tokio = { version = "1", features = ["rt-multi-thread"] }
use gitlab_client::{GitLabClient, models::PipelineStatus, Result};
#[tokio::main]
async fn main() -> Result<()> {
// Create a client
let client = GitLabClient::new("https://gitlab.com", "your-token")?;
// List failed pipelines on main branch
let pipelines = client
.pipelines("myorg/myproject")
.status(PipelineStatus::Failed)
.ref_name("main")
.limit(10)
.list()
.await?;
for pipeline in pipelines {
println!("Pipeline #{}: {}", pipeline.id, pipeline.status);
}
Ok(())
}
// Get pipeline details
let pipeline = client
.pipeline("myorg/myproject", 12345)
.get()
.await?;
println!("Status: {}", pipeline.status);
println!("Duration: {:?}", pipeline.duration);
// Retry a failed pipeline
client
.pipeline("myorg/myproject", 12345)
.retry()
.await?;
// Cancel a running pipeline
client
.pipeline("myorg/myproject", 12345)
.cancel()
.await?;
// Filter by status
let failed = client
.pipelines("myorg/myproject")
.status(PipelineStatus::Failed)
.list()
.await?;
// Filter by branch
let main_pipelines = client
.pipelines("myorg/myproject")
.ref_name("main")
.list()
.await?;
// Combine filters
let recent_failures = client
.pipelines("myorg/myproject")
.status(PipelineStatus::Failed)
.ref_name("main")
.limit(5)
.list()
.await?;
The library provides comprehensive error types for better error handling:
use gitlab_client::{GitLabClient, GitLabError};
match client.pipeline("myorg/myproject", 999).get().await {
Ok(pipeline) => println!("Found: {:?}", pipeline),
Err(GitLabError::NotFound { resource, id }) => {
println!("{} with id {} not found", resource, id);
}
Err(GitLabError::Authentication(msg)) => {
println!("Auth error: {}", msg);
}
Err(e) => println!("Other error: {}", e),
}
let pipeline = client.pipeline("myorg/myproject", 12345).get().await?;
if pipeline.status.is_finished() {
println!("Pipeline has completed");
}
if pipeline.status.is_successful() {
println!("Pipeline succeeded!");
} else if pipeline.status.is_failed() {
println!("Pipeline failed!");
}
✅ Pipelines
✅ Error Types
✅ Models
🚧 Jobs
🚧 Merge Requests
🚧 Projects
🚧 Runners
🚧 Container Registry
🚧 CI/CD Variables
🚧 Environments
This library is particularly useful for CI/CD automation. Common use cases include:
use tokio::time::{sleep, Duration};
async fn wait_for_pipeline(
client: &GitLabClient,
project: &str,
pipeline_id: u64,
) -> Result<Pipeline> {
loop {
let pipeline = client.pipeline(project, pipeline_id).get().await?;
if pipeline.status.is_finished() {
return Ok(pipeline);
}
println!("Pipeline still running... ({})", pipeline.status);
sleep(Duration::from_secs(30)).await;
}
}
// In your CI/CD script
let client = GitLabClient::new(&gitlab_url, &token)?;
// Get current pipeline
let pipeline_id = std::env::var("CI_PIPELINE_ID")?.parse()?;
let pipeline = client.pipeline(&project, pipeline_id).get().await?;
if pipeline.status.is_failed() {
// Retry failed jobs
client.pipeline(&project, pipeline_id).retry().await?;
}
The library can be configured using environment variables:
export GITLAB_URL="https://gitlab.example.com"
export GITLAB_TOKEN="your-personal-access-token"
export GITLAB_PROJECT="myorg/myproject"
Or programmatically:
let client = GitLabClient::new(
"https://gitlab.example.com",
"your-token"
)?;
The library provides detailed error types for better error handling:
GitLabError::Authentication - Invalid credentialsGitLabError::NotFound - Resource not foundGitLabError::Api - API-specific errorsGitLabError::RateLimit - Rate limit exceededGitLabError::PermissionDenied - Insufficient permissionsGitLabError::InvalidInput - Invalid parametersGitLabError::Timeout - Operation timed outGitLabError::Conflict - Resource conflictGitLabError::ServerError - GitLab server errorAll errors implement std::error::Error and can be used with ? operator.
See the examples directory for more comprehensive examples:
basic_usage.rs - Demonstrates core library featuresRun an example:
export GITLAB_TOKEN="your-token"
cargo run --example basic_usage
cargo build
cargo test
Generate and view documentation:
cargo doc --open
# Run clippy
cargo clippy -- -D warnings
# Format code
cargo fmt
Contributions are welcome! Please feel free to submit a Pull Request.
Part of the LMRC Stack project. Licensed under either of:
at your option.
Built on top of the excellent gitlab crate for low-level API access.