gitlabglab

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package gitlabglab implements the GitLab provider adapter by shelling out to the `glab` CLI. Lands in M6.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Supports

func Supports(raw string) bool

Supports reports whether this adapter can handle the URL. Used by the provider registry to dispatch.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter fetches GitLab merge request data via the `glab` CLI.

func New

func New(run provider.Runner) *Adapter

New constructs an Adapter. Passing nil uses provider.DefaultRunner and a default Preflight that calls exec.LookPath. Tests that need to substitute LookPath can use NewWithLookPath.

func NewWithLookPath

func NewWithLookPath(run provider.Runner, lookPath func(string) (string, error)) *Adapter

NewWithLookPath constructs an Adapter with explicit run + lookPath injection so cross-package tests (e.g. internal/app/) can build a fully hermetic Adapter that needs neither real `glab` on PATH nor real network. Passing nil for either falls back to defaults (provider.DefaultRunner, exec.LookPath).

func (*Adapter) Fetch

func (a *Adapter) Fetch(ctx context.Context, rawURL string) (*review.ReviewInput, error)

Fetch retrieves MR metadata and the unified diff via glab, then returns a normalized ReviewInput with Host=review.HostGitLab. The diff is parsed via internal/diff to surface classification errors early, before the model is invoked.

func (*Adapter) FetchLinkedIssues added in v0.2.0

func (a *Adapter) FetchLinkedIssues(ctx context.Context, target review.ReviewTarget) ([]review.IssueContext, []string, error)

FetchLinkedIssues resolves the issues this MR closes via the closes_issues API. diffsmith-144.

One call returns title + description for every closing issue, so there is no per-issue failure mode: a failure of the single API call is total (returned as err for the caller to surface as one note and proceed with no criteria), matching review.LinkedIssueFetcher's contract.

func (*Adapter) List

func (a *Adapter) List(ctx context.Context, repo provider.RepoCoord) ([]provider.PRSummary, error)

List enumerates open MRs for the repo via `glab mr list`. Omitting `--opened` (deprecated as of glab v1.x) inherits the default "open" behavior without triggering the deprecation warning that glab writes to stdout, mixed with the JSON.

After the initial listing, List fetches per-MR discussion data bounded-concurrently (cap 6) to populate enrichment fields. A per-MR discussions fetch failure marks that row Enriched=false with base fields intact; all other rows continue to be enriched.

func (*Adapter) Preflight

func (a *Adapter) Preflight(ctx context.Context) error

Preflight verifies glab is on PATH and authenticated before any fetch.

func (*Adapter) PreflightList

func (a *Adapter) PreflightList(ctx context.Context) error

PreflightList verifies glab is authenticated before listing MRs.

func (*Adapter) Supports

func (a *Adapter) Supports(rawURL string) bool

Supports reports whether the URL is a GitLab merge request URL.

type MergeRequestRef

type MergeRequestRef struct {
	ProjectPath string
	Number      int
	URL         string // canonical: https://gitlab.com/<project-path>/-/merge_requests/<number>
	RepoURL     string // https://gitlab.com/<project-path>
}

MergeRequestRef identifies a GitLab merge request parsed from a URL. ProjectPath is the full URL-path namespace+project (e.g. "group/project" or "group/sub/project" for nested groups); the adapter splits it at the last slash to populate review.ReviewTarget.Owner/Repo. RepoURL is the project URL passed to `glab -R`.

func ParseURL

func ParseURL(raw string) (*MergeRequestRef, error)

ParseURL extracts a MergeRequestRef from a GitLab merge request URL.

Accepts the canonical form and any sub-path under it (e.g. /diffs, /commits), query strings, and trailing slashes. Supports nested groups of any depth (gitlab.com/<group>/<sub>/.../<project>). Rejects URLs that are not MRs, not gitlab.com, or not HTTPS — self-hosted GitLab is a V1.x concern, not V1.

type Preflight

type Preflight struct {
	Run      provider.Runner
	LookPath func(name string) (string, error)
}

Preflight verifies the runtime environment is ready to fetch GitLab MRs.

Per docs/architecture.md § Pre-Flight Checks, the model is never invoked when these fail; the user sees an actionable message instead of a stack trace from `os/exec`. Mirrors internal/provider/githubgh.Preflight; the only intentional divergence is the auth-failure error string ordering (actionable text first, %w wrap at the tail) so the contiguous acceptance-required substring is preserved without sacrificing errors.Is/Unwrap on the underlying transport error.

func NewPreflight

func NewPreflight(run provider.Runner, lookPath func(string) (string, error)) *Preflight

NewPreflight builds a Preflight with sensible defaults. Tests inject fakes; production code calls NewPreflight(nil, nil).

func (*Preflight) Check

func (p *Preflight) Check(ctx context.Context) error

Check runs `glab` binary presence and `glab auth status` in order. The first failure is surfaced with an actionable message; later checks are skipped.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL