gitlab

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gitlab provides GitLab API client operations.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrTokenRequired is returned when GITLAB_TOKEN environment variable is missing.
	ErrTokenRequired = errTokenRequired
	// ErrInvalidURLFormat is returned when the GitLab URL format is invalid.
	ErrInvalidURLFormat = errInvalidURLFormat
	// ErrAssigneeNotFound is returned when the assignee user cannot be found.
	ErrAssigneeNotFound = errAssigneeNotFound
	// ErrReviewerNotFound is returned when the reviewer user cannot be found.
	ErrReviewerNotFound = errReviewerNotFound
	// ErrPipelineTimeout is returned when waiting for pipeline completion times out.
	ErrPipelineTimeout = errPipelineTimeout
	// ErrMRNotFound is returned when no merge request is found for the branch.
	ErrMRNotFound = errMRNotFound
)

Error definitions for GitLab API operations.

Functions

This section is empty.

Types

type APIClient added in v0.5.0

type APIClient interface {
	// SetProjectFromURL configures the project from a git remote URL.
	// Supports both HTTPS and SSH formats.
	SetProjectFromURL(url string) error

	// ListLabels returns all labels available in the project.
	ListLabels() ([]*Label, error)

	// CreateMergeRequest creates a new merge request with the specified parameters.
	// Returns the created merge request or an error if creation fails.
	CreateMergeRequest(
		sourceBranch, targetBranch, title, description, assignee, reviewer string,
		labels []string, squash bool,
	) (*gitlab.MergeRequest, error)

	// GetMergeRequestByBranch fetches an existing merge request by source and target branches.
	// Returns errMRNotFound if no matching merge request exists.
	GetMergeRequestByBranch(sourceBranch, targetBranch string) (*gitlab.MergeRequest, error)

	// WaitForPipeline waits for all pipelines to complete for the merge request.
	// Returns the overall status (success, failed, etc.) or an error on timeout.
	WaitForPipeline(timeout time.Duration) (string, error)

	// ApproveMergeRequest approves a merge request.
	// Returns an error if the approval fails.
	ApproveMergeRequest(mrIID int) error

	// MergeMergeRequest merges a merge request with optional squash.
	// Returns an error if the merge fails.
	MergeMergeRequest(mrIID int, squash bool) error

	// GetMergeRequestsByBranch returns all open merge requests for the given source branch.
	GetMergeRequestsByBranch(sourceBranch string) ([]*gitlab.BasicMergeRequest, error)
}

APIClient defines the interface for GitLab API operations. This interface enables dependency injection and facilitates black box testing by allowing mock implementations to replace the actual GitLab API client.

type Client

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

Client represents a GitLab API client wrapper.

func NewClient

func NewClient() (*Client, error)

NewClient creates a new GitLab client.

func (*Client) ApproveMergeRequest

func (c *Client) ApproveMergeRequest(mrIID int) error

ApproveMergeRequest approves a merge request.

func (*Client) CreateMergeRequest

func (c *Client) CreateMergeRequest(
	sourceBranch, targetBranch, title, description, assignee, reviewer string,
	labels []string, squash bool,
) (*gitlab.MergeRequest, error)

CreateMergeRequest creates a new merge request with assignees, reviewers, and labels.

func (*Client) GetMergeRequestByBranch

func (c *Client) GetMergeRequestByBranch(sourceBranch, targetBranch string) (*gitlab.MergeRequest, error)

GetMergeRequestByBranch fetches an existing merge request by source and target branches.

func (*Client) GetMergeRequestsByBranch

func (c *Client) GetMergeRequestsByBranch(sourceBranch string) ([]*gitlab.BasicMergeRequest, error)

GetMergeRequestsByBranch returns all open merge requests for the given source branch.

func (*Client) ListLabels

func (c *Client) ListLabels() ([]*Label, error)

ListLabels returns all labels for the project.

func (*Client) MergeMergeRequest

func (c *Client) MergeMergeRequest(mrIID int, squash bool) error

MergeMergeRequest merges a merge request.

func (*Client) SetLogger

func (c *Client) SetLogger(logger *bullets.Logger)

SetLogger sets the logger for the GitLab client.

func (*Client) SetProjectFromURL

func (c *Client) SetProjectFromURL(url string) error

SetProjectFromURL sets the project from a git remote URL.

func (*Client) WaitForPipeline

func (c *Client) WaitForPipeline(timeout time.Duration) (string, error)

WaitForPipeline waits for all pipelines to complete for the merge request.

type DisplayRenderer added in v0.5.0

type DisplayRenderer interface {
	// Info logs an informational message.
	Info(message string)

	// Debug logs a debug message.
	Debug(message string)

	// Error logs an error message.
	Error(message string)

	// Success logs a success message.
	Success(message string)

	// InfoHandle creates an updatable handle for an info message.
	// The handle can be updated with new content or converted to success/error.
	InfoHandle(message string) *bullets.BulletHandle

	// SpinnerCircle creates an animated spinner with the given message.
	// Returns a Spinner that can be stopped with Success(), Error(), or Replace().
	SpinnerCircle(message string) *bullets.Spinner

	// IncreasePadding increases the indentation level for nested output.
	IncreasePadding()

	// DecreasePadding decreases the indentation level for nested output.
	DecreasePadding()
}

DisplayRenderer defines the interface for UI rendering operations. This interface abstracts the bullets.Logger and bullets.UpdatableLogger functionality to enable testing of display logic without actual terminal output.

type Job added in v0.5.0

type Job struct {
	ID         int
	Name       string
	Status     string
	Stage      string
	CreatedAt  time.Time
	StartedAt  *time.Time
	FinishedAt *time.Time
	Duration   float64
	WebURL     string
}

Job represents a GitLab pipeline job with detailed status information.

type Label

type Label struct {
	Name string
}

Label represents a GitLab label.

type StateTracker added in v0.5.0

type StateTracker interface {
	// contains filtered or unexported methods
}

StateTracker defines the interface for thread-safe job state management. This interface abstracts the jobTracker functionality to enable testing of state transitions and display handle management without real API calls.

Jump to

Keyboard shortcuts

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