gitlab

package
v0.0.0-...-b708d86 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MergeMethodMerge  = "merge"
	MergeMethodSquash = "squash"
	MergeMethodRebase = "rebase"

	MergeActionDefault     = "default"
	MergeActionDirectMerge = "direct_merge"
	MergeActionMergeQueue  = "merge_queue"
)
View Source
const (
	AsyncMergeStatusPending  = "pending"
	AsyncMergeStatusMerged   = "merged"
	AsyncMergeStatusEnqueued = "enqueued"
	AsyncMergeStatusFailed   = "failed"
)

Variables

View Source
var ErrAsyncMergeUnavailable = errors.New("stack merge is not available for this repository")

Functions

func PRURL

func PRURL(host, owner, repo string, number int) string

Types

type AsyncMergeDetails

type AsyncMergeDetails struct {
	Message         string `json:"message"`
	UUID            string `json:"uuid"`
	MergeMethod     string `json:"merge_method"`
	MergeAction     string `json:"merge_action"`
	ExpectedHeadSHA string `json:"expected_head_sha"`
	SHA             string `json:"sha"`
}

type AsyncMergeResult

type AsyncMergeResult struct {
	Status  string            `json:"status"`
	Details AsyncMergeDetails `json:"details"`
}

func (*AsyncMergeResult) IsEnqueued

func (r *AsyncMergeResult) IsEnqueued() bool

func (*AsyncMergeResult) IsFailed

func (r *AsyncMergeResult) IsFailed() bool

func (*AsyncMergeResult) IsMerged

func (r *AsyncMergeResult) IsMerged() bool

func (*AsyncMergeResult) IsPending

func (r *AsyncMergeResult) IsPending() bool

type AutoMergeRequest

type AutoMergeRequest struct {
	EnabledAt string
}

type Client

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

Client talks directly to the GitLab v4 REST API. It does not require glab.

func NewClient

func NewClient(host, owner, repo string) (*Client, error)

NewClient creates a GitLab client. GITLAB_TOKEN is preferred; GLAB_TOKEN is accepted for compatibility with glab environments.

func (*Client) AddToStack

func (c *Client) AddToStack(stackNumber int, prNumbers []int) (*RemoteStack, error)

func (*Client) BaseBranchUsesMergeQueue

func (c *Client) BaseBranchUsesMergeQueue(string) (bool, error)

func (*Client) CreatePR

func (c *Client) CreatePR(base, head, title, body string, draft bool) (*PullRequest, error)

func (*Client) CreateStack

func (c *Client) CreateStack(prNumbers []int) (*RemoteStack, error)

func (*Client) DisableAutoMerge

func (c *Client) DisableAutoMerge(prID string) error

func (*Client) FindPRByNumber

func (c *Client) FindPRByNumber(number int) (*PullRequest, error)

func (*Client) FindPRDetailsForBranch

func (c *Client) FindPRDetailsForBranch(branch string) (*PRDetails, error)

func (*Client) FindPRForBranch

func (c *Client) FindPRForBranch(branch string) (*PullRequest, error)

func (*Client) FindStackForPR

func (c *Client) FindStackForPR(prNumber int) (*RemoteStack, error)

func (*Client) GetAsyncMergeResult

func (c *Client) GetAsyncMergeResult(_ int, uuid string) (*AsyncMergeResult, error)

func (*Client) GetStack

func (c *Client) GetStack(stackNumber int) (*RemoteStack, error)

func (*Client) ListStacks

func (c *Client) ListStacks() ([]RemoteStack, error)

func (*Client) MarkPRReadyForReview

func (c *Client) MarkPRReadyForReview(prID string) error

func (*Client) MergeStackAsync

func (c *Client) MergeStackAsync(prNumber int, method, _ string) (*AsyncMergeResult, error)

MergeStackAsync preserves the command interface but performs GitLab merges synchronously. GitLab has no atomic stack-merge API: members are merged from bottom to top, retargeting each remaining MR to the trunk first.

func (*Client) PRTitles

func (c *Client) PRTitles(numbers []int) (map[int]string, error)

func (*Client) RepoMergeConfig

func (c *Client) RepoMergeConfig() (*RepoMergeConfig, error)

func (*Client) Unstack

func (c *Client) Unstack(stackNumber int) (*RemoteStack, bool, error)

func (*Client) UpdatePRBase

func (c *Client) UpdatePRBase(number int, base string) error

type ClientOps

type ClientOps interface {
	FindPRForBranch(branch string) (*PullRequest, error)
	FindPRByNumber(number int) (*PullRequest, error)
	FindPRDetailsForBranch(branch string) (*PRDetails, error)
	CreatePR(base, head, title, body string, draft bool) (*PullRequest, error)
	UpdatePRBase(number int, base string) error
	MarkPRReadyForReview(prID string) error
	DisableAutoMerge(prID string) error
	ListStacks() ([]RemoteStack, error)
	FindStackForPR(prNumber int) (*RemoteStack, error)
	GetStack(stackNumber int) (*RemoteStack, error)
	CreateStack(prNumbers []int) (*RemoteStack, error)
	AddToStack(stackNumber int, prNumbers []int) (*RemoteStack, error)
	Unstack(stackNumber int) (*RemoteStack, bool, error)
	RepoMergeConfig() (*RepoMergeConfig, error)
	MergeStackAsync(prNumber int, method, mergeAction string) (*AsyncMergeResult, error)
	GetAsyncMergeResult(prNumber int, uuid string) (*AsyncMergeResult, error)
	PRTitles(numbers []int) (map[int]string, error)
	BaseBranchUsesMergeQueue(baseRef string) (bool, error)
}

ClientOps defines the interface for GitLab API operations. The concrete Client type satisfies this interface. Tests can substitute a MockClient.

type MergeQueueEntry

type MergeQueueEntry struct {
	ID string
}

MergeQueueEntry is retained for the shared stack UI. GitLab reports queued merges through merge_when_pipeline_succeeds rather than a separate object.

type MockClient

type MockClient struct {
	FindPRForBranchFn          func(string) (*PullRequest, error)
	FindPRByNumberFn           func(int) (*PullRequest, error)
	FindPRDetailsForBranchFn   func(string) (*PRDetails, error)
	CreatePRFn                 func(string, string, string, string, bool) (*PullRequest, error)
	UpdatePRBaseFn             func(int, string) error
	MarkPRReadyForReviewFn     func(string) error
	DisableAutoMergeFn         func(string) error
	ListStacksFn               func() ([]RemoteStack, error)
	FindStackForPRFn           func(int) (*RemoteStack, error)
	GetStackFn                 func(int) (*RemoteStack, error)
	CreateStackFn              func([]int) (*RemoteStack, error)
	AddToStackFn               func(int, []int) (*RemoteStack, error)
	UnstackFn                  func(int) (*RemoteStack, bool, error)
	RepoMergeConfigFn          func() (*RepoMergeConfig, error)
	MergeStackAsyncFn          func(int, string, string) (*AsyncMergeResult, error)
	GetAsyncMergeResultFn      func(int, string) (*AsyncMergeResult, error)
	PRTitlesFn                 func([]int) (map[int]string, error)
	BaseBranchUsesMergeQueueFn func(string) (bool, error)
}

MockClient is a test double for GitLab API operations. Each field is an optional function that, when set, handles the corresponding ClientOps method call. When nil, a reasonable default is returned.

func (*MockClient) AddToStack

func (m *MockClient) AddToStack(stackNumber int, prNumbers []int) (*RemoteStack, error)

func (*MockClient) BaseBranchUsesMergeQueue

func (m *MockClient) BaseBranchUsesMergeQueue(baseRef string) (bool, error)

func (*MockClient) CreatePR

func (m *MockClient) CreatePR(base, head, title, body string, draft bool) (*PullRequest, error)

func (*MockClient) CreateStack

func (m *MockClient) CreateStack(prNumbers []int) (*RemoteStack, error)

func (*MockClient) DisableAutoMerge

func (m *MockClient) DisableAutoMerge(prID string) error

func (*MockClient) FindPRByNumber

func (m *MockClient) FindPRByNumber(number int) (*PullRequest, error)

func (*MockClient) FindPRDetailsForBranch

func (m *MockClient) FindPRDetailsForBranch(branch string) (*PRDetails, error)

func (*MockClient) FindPRForBranch

func (m *MockClient) FindPRForBranch(branch string) (*PullRequest, error)

func (*MockClient) FindStackForPR

func (m *MockClient) FindStackForPR(prNumber int) (*RemoteStack, error)

func (*MockClient) GetAsyncMergeResult

func (m *MockClient) GetAsyncMergeResult(prNumber int, uuid string) (*AsyncMergeResult, error)

func (*MockClient) GetStack

func (m *MockClient) GetStack(stackNumber int) (*RemoteStack, error)

func (*MockClient) ListStacks

func (m *MockClient) ListStacks() ([]RemoteStack, error)

func (*MockClient) MarkPRReadyForReview

func (m *MockClient) MarkPRReadyForReview(prID string) error

func (*MockClient) MergeStackAsync

func (m *MockClient) MergeStackAsync(prNumber int, method, mergeAction string) (*AsyncMergeResult, error)

func (*MockClient) PRTitles

func (m *MockClient) PRTitles(numbers []int) (map[int]string, error)

func (*MockClient) RepoMergeConfig

func (m *MockClient) RepoMergeConfig() (*RepoMergeConfig, error)

func (*MockClient) Unstack

func (m *MockClient) Unstack(stackNumber int) (*RemoteStack, bool, error)

func (*MockClient) UpdatePRBase

func (m *MockClient) UpdatePRBase(number int, base string) error

type PRDetails

type PRDetails struct {
	Number   int
	State    string
	URL      string
	Title    string
	Body     string
	IsDraft  bool
	Merged   bool
	IsQueued bool
}

type PullRequest

type PullRequest struct {
	ID               string
	Number           int
	State            string
	URL              string
	Title            string
	Body             string
	HeadRefName      string
	BaseRefName      string
	IsDraft          bool
	Merged           bool
	MergeQueueEntry  *MergeQueueEntry
	AutoMergeRequest *AutoMergeRequest
}

PullRequest is the provider-neutral shape consumed by the command and TUI layers. Number is the GitLab project-scoped merge request IID.

func (*PullRequest) IsAutoMergeEnabled

func (pr *PullRequest) IsAutoMergeEnabled() bool

func (*PullRequest) IsQueued

func (pr *PullRequest) IsQueued() bool

type RemoteStack

type RemoteStack struct {
	ID           int             `json:"id"`
	Number       int             `json:"number"`
	NodeID       string          `json:"node_id"`
	URL          string          `json:"url"`
	Base         RemoteStackBase `json:"base"`
	Open         bool            `json:"open"`
	CreatedAt    string          `json:"created_at"`
	PullRequests []int           `json:"-"`
	PRDetails    []RemoteStackPR `json:"-"`
}

func (*RemoteStack) PRNumbers

func (s *RemoteStack) PRNumbers() []int

type RemoteStackBase

type RemoteStackBase struct {
	Ref string `json:"ref"`
	Sha string `json:"sha,omitempty"`
}

type RemoteStackPR

type RemoteStackPR struct {
	Number   int               `json:"number"`
	State    string            `json:"state"`
	Draft    bool              `json:"draft"`
	MergedAt *string           `json:"merged_at"`
	Head     RemoteStackPRHead `json:"head"`
}

func (RemoteStackPR) IsMerged

func (p RemoteStackPR) IsMerged() bool

type RemoteStackPRHead

type RemoteStackPRHead struct {
	Ref string `json:"ref"`
	Sha string `json:"sha"`
}

type RepoMergeConfig

type RepoMergeConfig struct {
	MergeAllowed  bool
	SquashAllowed bool
	RebaseAllowed bool
	DefaultMethod string
}

func (RepoMergeConfig) AllowedMethods

func (c RepoMergeConfig) AllowedMethods() []string

func (RepoMergeConfig) Allows

func (c RepoMergeConfig) Allows(method string) bool

Jump to

Keyboard shortcuts

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