Documentation
¶
Index ¶
- Variables
- type APIClient
- func (c *APIClient) GetCurrentUser(ctx context.Context) (*User, error)
- func (c *APIClient) GetMergeRequest(ctx context.Context, projectID, mrIID int) (*MergeRequest, error)
- func (c *APIClient) GetMergeRequestPipeline(ctx context.Context, projectID, mrIID int) (*Pipeline, string, error)
- func (c *APIClient) ListMergeRequestsFull(ctx context.Context, projectPath string) ([]*MergeRequest, error)
- func (c *APIClient) ListPipelines(ctx context.Context, projectID int, ref, status, sha string) ([]*Pipeline, error)
- func (c *APIClient) ListProjects(ctx context.Context, search string) ([]*Project, error)
- func (c *APIClient) MergeMergeRequest(ctx context.Context, projectID, mrIID int, sha string) (string, error)
- func (c *APIClient) RebaseMergeRequest(ctx context.Context, projectID, mrIID int) (*MergeRequest, error)
- func (c *APIClient) SetProject(id int)
- type Client
- type MergeRequest
- type Pipeline
- type Project
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrNotMergeable = errors.New("not mergeable")
ErrNotMergeable is returned when a merge fails due to HTTP 405 or 422. This is a transient race condition: GitLab reports "mergeable" but the merge API isn't ready yet.
var ErrSHAMismatch = errors.New("SHA mismatch")
ErrSHAMismatch is returned when a merge fails due to SHA mismatch (HTTP 409).
Functions ¶
This section is empty.
Types ¶
type APIClient ¶
type APIClient struct {
// contains filtered or unexported fields
}
APIClient implements the Client interface using the go-gitlab library.
func NewAPIClient ¶
func NewAPIClient(host, token string, opts ...goGitLab.ClientOptionFunc) (*APIClient, error)
NewAPIClient creates a new GitLab API client. host should be a base URL like "https://gitlab.example.com" or just a hostname.
func (*APIClient) GetCurrentUser ¶
GetCurrentUser returns the authenticated user.
func (*APIClient) GetMergeRequest ¶
func (c *APIClient) GetMergeRequest(ctx context.Context, projectID, mrIID int) (*MergeRequest, error)
GetMergeRequest returns a single merge request with full detail.
func (*APIClient) GetMergeRequestPipeline ¶
func (c *APIClient) GetMergeRequestPipeline(ctx context.Context, projectID, mrIID int) (*Pipeline, string, error)
GetMergeRequestPipeline returns the head pipeline for a merge request, along with the MR's DetailedMergeStatus.
func (*APIClient) ListMergeRequestsFull ¶
func (c *APIClient) ListMergeRequestsFull(ctx context.Context, projectPath string) ([]*MergeRequest, error)
ListMergeRequestsFull fetches open merge requests with all fields via GraphQL.
func (*APIClient) ListPipelines ¶
func (c *APIClient) ListPipelines(ctx context.Context, projectID int, ref, status, sha string) ([]*Pipeline, error)
ListPipelines returns pipelines for a ref, ordered by ID descending. If sha is non-empty, only pipelines for that exact commit SHA are returned.
func (*APIClient) ListProjects ¶
ListProjects returns projects accessible to the current user.
func (*APIClient) MergeMergeRequest ¶
func (c *APIClient) MergeMergeRequest(ctx context.Context, projectID, mrIID int, sha string) (string, error)
MergeMergeRequest merges the MR with a SHA guard. Returns the merge commit SHA on success.
func (*APIClient) RebaseMergeRequest ¶
func (c *APIClient) RebaseMergeRequest(ctx context.Context, projectID, mrIID int) (*MergeRequest, error)
RebaseMergeRequest triggers a rebase of the MR onto its target branch.
func (*APIClient) SetProject ¶
SetProject sets the project ID for subsequent API calls.
type Client ¶
type Client interface {
// GetCurrentUser returns the authenticated user. Used to validate credentials.
GetCurrentUser(ctx context.Context) (*User, error)
// ListProjects returns projects accessible to the current user.
ListProjects(ctx context.Context, search string) ([]*Project, error)
// ListMergeRequestsFull returns open merge requests with all fields (including
// pipeline status and commit count) via a single GraphQL query.
// projectPath is the full path (e.g. "team/project").
ListMergeRequestsFull(ctx context.Context, projectPath string) ([]*MergeRequest, error)
// GetMergeRequest returns a single merge request with full detail.
GetMergeRequest(ctx context.Context, projectID, mrIID int) (*MergeRequest, error)
// RebaseMergeRequest triggers a rebase of the MR onto its target branch.
// Returns the updated MR (with post-rebase SHA) on success.
// Returns an error if a rebase conflict occurs.
// The branch pipeline after rebase is always skipped.
RebaseMergeRequest(ctx context.Context, projectID, mrIID int) (*MergeRequest, error)
// MergeMergeRequest merges the MR with a SHA guard.
// sha is the expected head SHA — the server returns 409 if it doesn't match.
// Returns the merge commit SHA on success.
MergeMergeRequest(ctx context.Context, projectID, mrIID int, sha string) (string, error)
// GetMergeRequestPipeline returns the head pipeline for a merge request,
// along with the MR's DetailedMergeStatus.
GetMergeRequestPipeline(ctx context.Context, projectID, mrIID int) (*Pipeline, string, error)
// ListPipelines returns pipelines for a ref, ordered by ID descending.
// If sha is non-empty, only pipelines for that exact commit SHA are returned.
ListPipelines(ctx context.Context, projectID int, ref, status, sha string) ([]*Pipeline, error)
}
Client defines the interface for GitLab API operations used by glmt. This is the key seam for testing — the train runner and TUI depend only on this interface.
type MergeRequest ¶
type MergeRequest struct {
IID int
State string // opened, merged, closed
Title string
Author string
SourceBranch string
TargetBranch string
SHA string // head SHA
CreatedAt string
CommitCount int
Draft bool
ApprovalCount int
HeadPipelineStatus string // success, failed, running, pending, canceled, skipped, created
DetailedMergeStatus string // mergeable, checking, unchecked, etc.
BlockingDiscussionsResolved bool
WebURL string
}
MergeRequest represents a GitLab merge request with fields needed for train execution.
type Pipeline ¶
type Pipeline struct {
ID int
Status string // running, success, failed, canceled, pending, created, skipped
Ref string
SHA string
WebURL string
}
Pipeline represents a GitLab CI pipeline.