gitlabx

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gitlabx wraps the official GitLab client behind a small interface the TUI can depend on and tests can fake. It is the only package in the module that imports client-go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements Service against a real GitLab instance.

func New

func New(baseURL, token string, projects, groups []string) (*Client, error)

New builds a Client for the given instance. projects and groups are the full paths the MR list fans out over.

func (*Client) CreateDraftNote

func (c *Client) CreateDraftNote(ctx context.Context, project any, iid int64, body string, pos *Position) error

func (*Client) CreateInlineDiscussion

func (c *Client) CreateInlineDiscussion(ctx context.Context, project any, iid int64, body string, pos *Position) error

func (*Client) CreateNote

func (c *Client) CreateNote(ctx context.Context, project any, iid int64, body string) error

func (*Client) GetMergeRequest

func (c *Client) GetMergeRequest(ctx context.Context, project any, iid int64) (*MRDetail, error)

func (*Client) GetMergeRequestTemplate added in v1.3.0

func (c *Client) GetMergeRequestTemplate(ctx context.Context, project any) (string, error)

GetMergeRequestTemplate resolves the project's default MR description template (including templates inherited from parent groups, which the web UI applies but the API does not substitute). It returns "" when no template is configured. It prefers a template named "Default", otherwise the first one listed.

func (*Client) ListCommits added in v1.3.0

func (c *Client) ListCommits(ctx context.Context, project any, iid int64) ([]Commit, error)

func (*Client) ListDiffs

func (c *Client) ListDiffs(ctx context.Context, project any, iid int64) ([]FileDiff, error)

func (*Client) ListDiscussions

func (c *Client) ListDiscussions(ctx context.Context, project any, iid int64) ([]Discussion, error)

func (*Client) ListGroupProjects

func (c *Client) ListGroupProjects(ctx context.Context, group string, search string, page Page) ([]ProjectInfo, bool, error)

func (*Client) ListGroups

func (c *Client) ListGroups(ctx context.Context, search string, page Page) ([]GroupInfo, bool, error)

func (*Client) ListMemberProjects

func (c *Client) ListMemberProjects(ctx context.Context, search string, page Page) ([]ProjectInfo, bool, error)

func (*Client) ListOpenMergeRequests

func (c *Client) ListOpenMergeRequests(ctx context.Context, filter MRFilter, page Page) ([]MRSummary, bool, error)

func (*Client) PublishAllDraftNotes

func (c *Client) PublishAllDraftNotes(ctx context.Context, project any, iid int64) error

type Commit added in v1.3.0

type Commit struct {
	ShortID string
	Title   string
	Message string // full message (subject + body)
}

Commit is one commit on an MR's source branch, for hygiene checks that compare commit messages against the diff.

type DiffRefs

type DiffRefs struct {
	BaseSHA  string
	HeadSHA  string
	StartSHA string
}

DiffRefs are the three SHAs GitLab requires on every positioned comment.

type Discussion

type Discussion struct {
	ID    string
	Notes []Note
}

Discussion is a thread of notes on an MR.

func (Discussion) Anchor

func (d Discussion) Anchor() *Position

Anchor returns the diff position of the discussion's first positioned note, or nil for general (unanchored) threads.

type FileDiff

type FileDiff struct {
	OldPath       string
	NewPath       string
	Diff          string
	NewFile       bool
	RenamedFile   bool
	DeletedFile   bool
	GeneratedFile bool
	TooLarge      bool
}

FileDiff is one file's unified diff within an MR.

func (FileDiff) Path

func (f FileDiff) Path() string

Path returns the display path: the new path, annotated when renamed.

type GroupInfo

type GroupInfo struct {
	ID          int64
	FullPath    string
	Name        string
	Description string
}

GroupInfo is a group the user can browse, for in-TUI selection.

type MRDetail

type MRDetail struct {
	MRSummary
	DiffRefs DiffRefs
	// HasConflicts and DivergedCommits drive the rebase hygiene check:
	// DivergedCommits > 0 means the target branch moved ahead.
	HasConflicts        bool
	DivergedCommits     int64
	DetailedMergeStatus string
}

MRDetail is the full view of one merge request.

func (MRDetail) NeedsRebase added in v1.3.0

func (m MRDetail) NeedsRebase() bool

NeedsRebase reports whether the source branch is behind its target or conflicts, i.e. the author should rebase before review. It trusts GitLab's detailed_merge_status ("need_rebase") as well as the diverged-commit count, because the latter is often reported as 0 unless merge status has been recomputed server-side.

type MRFilter

type MRFilter struct {
	State          string // opened | merged | closed | all
	AuthorUsername string
	TargetBranch   string
	Search         string

	// Projects/Groups override the configured scope for this query (used
	// by in-TUI selection). Both empty = use the configured scope.
	Projects []string
	Groups   []string
}

MRFilter narrows the MR list. Zero values mean "no filter" except State, which defaults to opened.

type MRSummary

type MRSummary struct {
	ProjectID    int64
	ProjectPath  string // full path with namespace; may be empty if unknown
	IID          int64
	Title        string
	Description  string
	State        string
	Draft        bool
	Author       string
	SourceBranch string
	TargetBranch string
	HeadSHA      string
	WebURL       string
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

MRSummary is the list-view projection of a merge request.

func (MRSummary) Project

func (m MRSummary) Project() any

Project returns the best identifier for API calls: the full path when known, otherwise the numeric ID.

func (MRSummary) Ref

func (m MRSummary) Ref() string

Ref returns a human-readable reference like group/app!42.

type Note

type Note struct {
	ID        int64
	Author    string
	Body      string
	System    bool
	Resolved  bool
	CreatedAt time.Time
	Position  *Position // nil for general (unpositioned) notes
}

Note is a single comment, optionally anchored to a diff position.

type Page

type Page struct {
	Number  int
	PerPage int
}

Page is an offset pagination request applied to every configured source.

type Position

type Position struct {
	BaseSHA  string
	HeadSHA  string
	StartSHA string
	OldPath  string
	NewPath  string
	OldLine  *int
	NewLine  *int
}

Position locates a comment on a diff, mapping 1:1 onto the GitLab API's text position type.

type ProjectInfo

type ProjectInfo struct {
	ID                int64
	PathWithNamespace string
	Description       string
	LastActivity      time.Time
}

ProjectInfo is a project the user can browse, for in-TUI selection.

type Service

type Service interface {
	// ListOpenMergeRequests returns one page of MRs merged across the
	// scope (filter override or the configured projects and groups),
	// newest-updated first, and whether any source has more pages.
	ListOpenMergeRequests(ctx context.Context, filter MRFilter, page Page) ([]MRSummary, bool, error)

	// ListGroups returns groups the user has access to, for in-TUI scope
	// selection.
	ListGroups(ctx context.Context, search string, page Page) ([]GroupInfo, bool, error)

	// ListGroupProjects returns a group's projects (including subgroups).
	ListGroupProjects(ctx context.Context, group string, search string, page Page) ([]ProjectInfo, bool, error)

	// ListMemberProjects returns projects the user is a member of,
	// covering personal and directly-shared projects outside any group.
	ListMemberProjects(ctx context.Context, search string, page Page) ([]ProjectInfo, bool, error)

	// GetMergeRequest fetches full MR details including diff refs.
	// project is a full path (group/app) or numeric ID.
	GetMergeRequest(ctx context.Context, project any, iid int64) (*MRDetail, error)

	// ListDiffs returns every file diff of the MR (paginating internally).
	ListDiffs(ctx context.Context, project any, iid int64) ([]FileDiff, error)

	// ListCommits returns every commit on the MR's source branch
	// (paginating internally), for commit-message hygiene checks.
	ListCommits(ctx context.Context, project any, iid int64) ([]Commit, error)

	// GetMergeRequestTemplate resolves the project's default MR description
	// template (including group-inherited ones), or "" if none is set.
	GetMergeRequestTemplate(ctx context.Context, project any) (string, error)

	// ListDiscussions returns every discussion thread on the MR
	// (paginating internally).
	ListDiscussions(ctx context.Context, project any, iid int64) ([]Discussion, error)

	// CreateInlineDiscussion posts a positioned comment on the MR diff.
	CreateInlineDiscussion(ctx context.Context, project any, iid int64, body string, pos *Position) error

	// CreateNote posts a general (unpositioned) comment on the MR — the
	// fallback when no diff position can be resolved.
	CreateNote(ctx context.Context, project any, iid int64, body string) error

	// CreateDraftNote adds a comment to the user's pending review; pos may
	// be nil for a general draft note. Nothing is visible to others until
	// PublishAllDraftNotes.
	CreateDraftNote(ctx context.Context, project any, iid int64, body string, pos *Position) error

	// PublishAllDraftNotes publishes the pending review in one action.
	PublishAllDraftNotes(ctx context.Context, project any, iid int64) error
}

Service is what the rest of the application sees of GitLab. Write operations (discussions, draft notes) join the interface with the review publishing milestone.

Directories

Path Synopsis
Package position maps review findings onto GitLab diff positions: the base/head/start SHAs plus old/new path and line GitLab requires for an inline discussion.
Package position maps review findings onto GitLab diff positions: the base/head/start SHAs plus old/new path and line GitLab requires for an inline discussion.

Jump to

Keyboard shortcuts

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