Help us shape the future of Go! Take the 2026 Go Developer Survey

gitlab

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gitlab is the GitLab provider: it talks to GitLab through the glab CLI.

Index

Constants

This section is empty.

Variables

View Source
var Info = protocol.Info{
	Name:         "gitlab",
	Terms:        protocol.Terms{Short: "MR", Long: "merge request", Ref: "!%d"},
	MergeMethods: []string{protocol.MethodMerge, protocol.MethodSquash, protocol.MethodRebase},
}

Info describes the GitLab provider.

Functions

func ExecRunner

func ExecRunner(args ...string) ([]byte, error)

ExecRunner runs the glab binary.

func Plugin

func Plugin(run Runner) protocol.Plugin

Plugin is the GitLab provider plugin, for protocol.Serve.

func StripDraft

func StripDraft(title string) string

StripDraft removes GitLab draft prefixes from a title.

func ToCR

func ToCR(m *MR) *protocol.CR

ToCR converts a GitLab MR.

Types

type BranchInfo

type BranchInfo struct {
	Protected bool `json:"protected"`
	Default   bool `json:"default"`
}

BranchInfo is the subset of a repository branch that git-stack uses.

type Client

type Client struct {
	Run     Runner
	Project Project
}

Client makes GitLab API calls for one project.

func (*Client) CancelAutoMerge

func (c *Client) CancelAutoMerge(iid int) error

CancelAutoMerge turns off "merge when pipeline succeeds".

func (*Client) CreateMR

func (c *Client) CreateMR(n NewMR) (*MR, error)

CreateMR opens a merge request.

func (*Client) FindMRForBranch

func (c *Client) FindMRForBranch(branch string) (*MR, error)

FindMRForBranch returns the open MR for branch, else the most recently merged one, else nil. MRs from forks are ignored: their source branch is someone else's branch that only shares the name.

func (*Client) GetBranch

func (c *Client) GetBranch(name string) (*BranchInfo, error)

GetBranch fetches a branch of the project.

func (*Client) GetMR

func (c *Client) GetMR(iid int) (*MR, error)

GetMR fetches one MR by IID.

func (*Client) GetProject

func (c *Client) GetProject() (*ProjectInfo, error)

GetProject fetches project settings.

func (*Client) ListMRsTargeting

func (c *Client) ListMRsTargeting(branch string) ([]*MR, error)

ListMRsTargeting returns open MRs, not from forks, whose target branch is branch.

func (*Client) MarkReady

func (c *Client) MarkReady(mr *MR) (*MR, error)

MarkReady removes the draft status from an MR.

func (*Client) Merge

func (c *Client) Merge(iid int, squash bool, sha string) (*MR, error)

Merge asks GitLab to merge the MR at sha. It is requested as auto-merge, so GitLab merges at once when nothing is pending, waits for the pipeline, or adds the MR to a merge train. The source branch is kept; callers delete it once dependent MRs are retargeted.

func (*Client) SearchMRs

func (c *Client) SearchMRs(text string) ([]*MR, error)

SearchMRs returns open MRs whose description contains text.

func (*Client) UpdateMR

func (c *Client) UpdateMR(iid int, fields map[string]any) (*MR, error)

UpdateMR changes the given attributes (target_branch, title, description, ...).

type MR

type MR struct {
	IID          int    `json:"iid"`
	Title        string `json:"title"`
	Description  string `json:"description"`
	State        string `json:"state"` // opened, closed, merged, locked
	Draft        bool   `json:"draft"`
	SourceBranch string `json:"source_branch"`
	TargetBranch string `json:"target_branch"`
	WebURL       string `json:"web_url"`
	SHA          string `json:"sha"`
	AutoMerge    bool   `json:"merge_when_pipeline_succeeds"`
	// RemoveSource is the MR's "delete source branch" option.
	RemoveSource bool `json:"force_remove_source_branch"`
	// MergeStatus is GitLab's detailed_merge_status (mergeable, checking, ...).
	MergeStatus string `json:"detailed_merge_status"`
	MergeError  string `json:"merge_error"`
	// Squash is the MR's own "squash commits" setting, which GitLab applies
	// when merging unless the project forces squashing on or off.
	Squash bool `json:"squash"`
	// SourceProjectID differs from TargetProjectID for an MR from a fork.
	SourceProjectID int `json:"source_project_id"`
	TargetProjectID int `json:"target_project_id"`
}

MR is the subset of a GitLab merge request that git-stack uses.

func (*MR) Checking

func (m *MR) Checking() bool

Checking reports whether GitLab is still computing mergeability.

func (*MR) Merged

func (m *MR) Merged() bool

Merged reports whether the MR has been merged.

func (*MR) Open

func (m *MR) Open() bool

Open reports whether the MR is open.

type NewMR

type NewMR struct {
	Source, Target, Title, Description string
	Draft                              bool
}

NewMR describes a merge request to create.

type Project

type Project struct {
	Host string // e.g. gitlab.com
	Path string // e.g. group/subgroup/repo
}

Project identifies a GitLab project.

type ProjectInfo

type ProjectInfo struct {
	SquashOption string `json:"squash_option"` // never, always, default_on, default_off
}

ProjectInfo is the subset of project settings git-stack uses.

type Provider

type Provider struct {
	C *Client
}

Provider adapts Client to protocol.Provider.

func (*Provider) CancelAutoMerge

func (p *Provider) CancelAutoMerge(n int) error

func (*Provider) CreateCR

func (p *Provider) CreateCR(n protocol.NewCR) (*protocol.CR, error)

func (*Provider) FindCRForBranch

func (p *Provider) FindCRForBranch(branch string) (*protocol.CR, error)

func (*Provider) GetBranch

func (p *Provider) GetBranch(name string) (*protocol.Branch, error)

func (*Provider) GetCR

func (p *Provider) GetCR(n int) (*protocol.CR, error)

func (*Provider) GetRepo

func (p *Provider) GetRepo() (*protocol.RepoSettings, error)

func (*Provider) ListCRsTargeting

func (p *Provider) ListCRsTargeting(branch string) ([]*protocol.CR, error)

func (*Provider) MarkReady

func (p *Provider) MarkReady(n int) (*protocol.CR, error)

func (*Provider) Merge

func (p *Provider) Merge(n int, method, sha string) (*protocol.CR, error)

Merge requests an auto-merge. GitLab has no per-merge choice between a merge commit and a rebase (that is the project's merge method), so "merge" and "rebase" both keep the commits.

func (*Provider) SearchCRs

func (p *Provider) SearchCRs(text string) ([]*protocol.CR, error)

func (*Provider) SyncStack

func (p *Provider) SyncStack([]int) error

SyncStack is a no-op: GitLab has no stack object; the description block is the stack.

func (*Provider) Unstack

func (p *Provider) Unstack([]int) error

Unstack is a no-op, like SyncStack.

func (*Provider) UpdateCR

func (p *Provider) UpdateCR(n int, u protocol.Update) (*protocol.CR, error)

type Runner

type Runner func(args ...string) ([]byte, error)

Runner executes glab with args and returns stdout.

Directories

Path Synopsis
Package glabtest provides an in-memory GitLab that answers `glab api` calls.
Package glabtest provides an in-memory GitLab that answers `glab api` calls.

Jump to

Keyboard shortcuts

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