lmrc-gitlab
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.
Features
- Type-safe API: Strongly typed models for all GitLab resources
- Async/await: Built on tokio for efficient async operations
- Comprehensive error handling: Custom error types with detailed context
- Builder patterns: Fluent, ergonomic API design
- Well documented: Extensive documentation with examples
- Tested: Comprehensive test coverage
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["rt-multi-thread"] }
Quick Start
use ;
async
Usage Examples
Working with Pipelines
// Get pipeline details
let pipeline = client
.pipeline
.get
.await?;
println!;
println!;
// Retry a failed pipeline
client
.pipeline
.retry
.await?;
// Cancel a running pipeline
client
.pipeline
.cancel
.await?;
Filtering Pipelines
// Filter by status
let failed = client
.pipelines
.status
.list
.await?;
// Filter by branch
let main_pipelines = client
.pipelines
.ref_name
.list
.await?;
// Combine filters
let recent_failures = client
.pipelines
.status
.ref_name
.limit
.list
.await?;
Error Handling
The library provides comprehensive error types for better error handling:
use ;
match client.pipeline.get.await
Checking Pipeline Status
let pipeline = client.pipeline.get.await?;
if pipeline.status.is_finished
if pipeline.status.is_successful else if pipeline.status.is_failed
API Coverage
Current Features
-
✅ Pipelines
- List with filters (status, ref, limit)
- Get details
- Retry
- Cancel
-
✅ Error Types
- Authentication errors
- API errors
- Not found errors
- Rate limiting
- Validation errors
- And more...
-
✅ Models
- Pipeline (basic and detailed)
- Job
- Runner
- Strong typing with enums for statuses
Planned Features
-
🚧 Jobs
- List jobs in pipeline
- Get job details
- Retry/cancel jobs
- Download artifacts
- View logs
-
🚧 Merge Requests
- Create/update/merge MRs
- List MRs with filters
- Approve/unapprove
- Add comments
-
🚧 Projects
- Get project details
- List projects
- Create/update projects
-
🚧 Runners
- List runners
- Get runner details
- Register/unregister runners
-
🚧 Container Registry
- List repositories and tags
- Delete old tags
- Cleanup operations
-
🚧 CI/CD Variables
- Get/set variables
- Manage protected variables
-
🚧 Environments
- List environments
- Deploy to environment
- Stop environment
CI/CD Integration
This library is particularly useful for CI/CD automation. Common use cases include:
Wait for Pipeline Completion
use ;
async
Trigger and Monitor Pipeline
// In your CI/CD script
let client = new?;
// Get current pipeline
let pipeline_id = var?.parse?;
let pipeline = client.pipeline.get.await?;
if pipeline.status.is_failed
Configuration
The library can be configured using environment variables:
Or programmatically:
let client = new?;
Error Types
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 error
All errors implement std::error::Error and can be used with ? operator.
Examples
See the examples directory for more comprehensive examples:
basic_usage.rs- Demonstrates core library features
Run an example:
Development
Building
Testing
Documentation
Generate and view documentation:
Code Quality
# Run clippy
# Format code
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Part of the LMRC Stack project. Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
Built on top of the excellent gitlab crate for low-level API access.