gitflow-gitlab 2.1.0

gf 的 GitLab 适配器,基于 glab CLI 提供 Issue/MR/Release/Review 等能力。GitLab adapter for gf via glab CLI.
Documentation

gitflow-gitlab

Crates.io Documentation License: MIT

GitLab platform implementation for gf — Issue, MR, Release, and Review providers via glab CLI.

Overview

gitflow-gitlab provides GitLab-specific implementations of the core platform traits defined in gitflow-core. It uses the official glab CLI under the hood for all GitLab API interactions.

Features

  • Issue Provider: Create, list, view, and manage GitLab Issues
  • MR Provider: Create, review, and manage Merge Requests (GitLab's PRs)
  • Release Provider: Create and manage GitLab Releases
  • Review Provider: Submit and manage code reviews
  • Pipeline Provider: Monitor GitLab CI/CD pipelines
  • Authentication: Leverages glab auth for authentication
  • Async Support: Full async/await support with Tokio

Installation

Add to your Cargo.toml:

[dependencies]
gitflow-gitlab = "0.8"

Prerequisites

This crate requires the GitLab CLI (glab) to be installed and authenticated:

# Install glab CLI
brew install glab  # macOS
# See: https://gitlab.com/gitlab-org/cli for other platforms

# Authenticate
glab auth login

Usage

Creating a GitLab Provider

use gf_gitlab::GitLabProvider;
use gf_core::IssueProvider;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let provider = GitLabProvider::new()?;

    // List open issues
    let issues = provider.list_issues("owner/repo", "open").await?;
    for issue in issues {
        println!("#{}: {}", issue.number, issue.title);
    }

    Ok(())
}

Working with Issues

use gf_gitlab::GitLabProvider;
use gf_core::{IssueProvider, IssueState};

let provider = GitLabProvider::new()?;

// Create an issue
let issue = provider.create_issue(
    "owner/repo",
    "Bug report",
    "Description of the bug",
    &["bug", "priority::high"],
).await?;

// Update issue state
provider.update_issue_state(
    "owner/repo",
    issue.number,
    IssueState::Closed,
).await?;

Working with Merge Requests

use gf_gitlab::GitLabProvider;
use gf_core::PrProvider;

let provider = GitLabProvider::new()?;

// Create a merge request
let mr = provider.create_pr(
    "owner/repo",
    "feature-branch",
    "main",
    "Add new feature",
    "Detailed description",
).await?;

// Merge MR
provider.merge_pr("owner/repo", mr.number).await?;

Working with Pipelines

use gf_gitlab::GitLabProvider;
use gf_core::{PipelineProvider, PipelineStatus};

let provider = GitLabProvider::new()?;

// Get pipeline status
let pipeline = provider.get_pipeline("owner/repo", "main").await?;
println!("Pipeline status: {:?}", pipeline.status);

Architecture

┌─────────────────────────────────────┐
│     gitflow-core (traits)       │
│  IssueProvider, PrProvider, etc.    │
└──────────────────┬──────────────────┘
                   │ implements
                   ▼
┌─────────────────────────────────────┐
│    gitflow-gitlab (this crate)  │
│      GitLabProvider                 │
└──────────────────┬──────────────────┘
                   │ uses
                   ▼
┌─────────────────────────────────────┐
│        glab CLI (GitLab API)        │
└─────────────────────────────────────┘

Error Handling

All operations return Result<T, gf_core::Error>:

use gf_gitlab::GitLabProvider;
use gf_core::Error;

let provider = GitLabProvider::new()?;
match provider.list_issues("owner/repo", "open").await {
    Ok(issues) => { /* handle issues */ },
    Err(Error::NotFound) => { /* project not found */ },
    Err(Error::Auth) => { /* authentication failed */ },
    Err(e) => { /* other error */ },
}

Environment Variables

  • GITLAB_TOKEN — GitLab authentication token (optional if glab auth login was used)
  • GITLAB_HOST — GitLab self-hosted instance hostname (optional, defaults to gitlab.com)

Ecosystem

This crate is part of the gf workspace:

  • gitflow-core — Core types and traits
  • gitflow-github — GitHub platform implementation
  • gitflow-gitlab (this crate) — GitLab platform implementation
  • gitflow-gitcode — GitCode platform implementation
  • gf — CLI application

Documentation

Contributing

Contributions are welcome! Please see the main repository for contribution guidelines.

License

Licensed under the MIT License. See LICENSE for details.