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 ¶
- type Approvals
- type Client
- func (c *Client) Approve(ctx context.Context, project any, iid int64, sha string) error
- func (c *Client) CompareRevisions(ctx context.Context, project any, from, to string) ([]FileDiff, error)
- func (c *Client) CreateDraftNote(ctx context.Context, project any, iid int64, body string, pos *Position) error
- func (c *Client) CreateInlineDiscussion(ctx context.Context, project any, iid int64, body string, pos *Position) error
- func (c *Client) CreateNote(ctx context.Context, project any, iid int64, body string) error
- func (c *Client) GetApprovals(ctx context.Context, project any, iid int64) (*Approvals, error)
- func (c *Client) GetMergeRequest(ctx context.Context, project any, iid int64) (*MRDetail, error)
- func (c *Client) GetMergeRequestTemplate(ctx context.Context, project any) (string, error)
- func (c *Client) ListCommits(ctx context.Context, project any, iid int64) ([]Commit, error)
- func (c *Client) ListDiffs(ctx context.Context, project any, iid int64) ([]FileDiff, error)
- func (c *Client) ListDirectoryFiles(ctx context.Context, project any, dir, ref string) ([]RepoFile, error)
- func (c *Client) ListDiscussions(ctx context.Context, project any, iid int64) ([]Discussion, error)
- func (c *Client) ListGroupProjects(ctx context.Context, group string, search string, page Page) ([]ProjectInfo, bool, error)
- func (c *Client) ListGroups(ctx context.Context, search string, page Page) ([]GroupInfo, bool, error)
- func (c *Client) ListMemberProjects(ctx context.Context, search string, page Page) ([]ProjectInfo, bool, error)
- func (c *Client) ListOpenMergeRequests(ctx context.Context, filter MRFilter, page Page) ([]MRSummary, bool, error)
- func (c *Client) PublishAllDraftNotes(ctx context.Context, project any, iid int64) error
- func (c *Client) Unapprove(ctx context.Context, project any, iid int64) error
- type Commit
- type DiffRefs
- type Discussion
- type FileDiff
- type GroupInfo
- type MRDetail
- type MRFilter
- type MRSummary
- type Note
- type Page
- type PipelineStatus
- type Position
- type ProjectInfo
- type RepoFile
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Approvals ¶ added in v1.11.0
type Approvals struct {
Approved bool // every required approval rule is satisfied
ApprovalsRequired int64
ApprovalsLeft int64
ApprovedBy []string // display names, see userDisplay
UserHasApproved bool
UserCanApprove bool
}
Approvals is one MR's approval state as seen by the current user.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements Service against a real GitLab instance.
func New ¶
New builds a Client for the given instance. projects and groups are the full paths the MR list fans out over.
func (*Client) CompareRevisions ¶ added in v1.30.0
func (c *Client) CompareRevisions(ctx context.Context, project any, from, to string) ([]FileDiff, error)
CompareRevisions diffs two commits directly (straight/two-dot, so the result is exactly what changed between the trees, even after an amend or force-push where from is no longer an ancestor of to).
func (*Client) CreateDraftNote ¶
func (*Client) CreateInlineDiscussion ¶
func (*Client) CreateNote ¶
func (*Client) GetApprovals ¶ added in v1.11.0
func (*Client) GetMergeRequest ¶
func (*Client) GetMergeRequestTemplate ¶ added in v1.3.0
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 (*Client) ListDirectoryFiles ¶ added in v1.18.0
func (c *Client) ListDirectoryFiles(ctx context.Context, project any, dir, ref string) ([]RepoFile, error)
ListDirectoryFiles returns the files directly under dir at ref, fetching each blob's raw content. A missing directory returns nil, not an error.
func (*Client) ListDiscussions ¶
func (*Client) ListGroupProjects ¶
func (*Client) ListGroups ¶
func (*Client) ListMemberProjects ¶
func (*Client) ListOpenMergeRequests ¶
func (*Client) PublishAllDraftNotes ¶
type Commit ¶ added in v1.3.0
Commit is one commit on an MR's source branch, for hygiene checks that compare commit messages against the diff.
type Discussion ¶
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.
func (Discussion) Resolvable ¶ added in v1.40.0
func (d Discussion) Resolvable() bool
Resolvable reports whether the discussion is a thread at all (has any resolvable note), as opposed to system notes or plain comments.
func (Discussion) Unresolved ¶ added in v1.40.0
func (d Discussion) Unresolved() bool
Unresolved reports whether the discussion is an open thread: it holds a resolvable note nobody has resolved yet. GitLab resolves a thread only once every resolvable note in it is resolved.
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.
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
Pipeline *PipelineStatus // head pipeline; nil when none has run
}
MRDetail is the full view of one merge request.
func (MRDetail) NeedsRebase ¶ added in v1.3.0
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 // username
AuthorName string // full name; empty when GitLab omits it
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) AuthorDisplay ¶ added in v1.24.0
AuthorDisplay formats the author for display.
func (MRSummary) AuthorWebURL ¶ added in v1.17.0
AuthorWebURL is the author's profile page on the MR's instance, or empty when either part is unknown.
func (MRSummary) BranchWebURL ¶ added in v1.17.0
BranchWebURL is the tree view of a branch on the MR's project, or empty when the project URL is unknown. Branches on a fork are not resolvable from the summary, so source-branch links assume same-project MRs.
func (MRSummary) Project ¶
Project returns the best identifier for API calls: the full path when known, otherwise the numeric ID.
func (MRSummary) ProjectWebURL ¶ added in v1.17.0
ProjectWebURL is the project's web URL, derived from the MR's WebURL (…/group/app/-/merge_requests/42 → …/group/app). Empty when unknown.
type Note ¶
type Note struct {
ID int64
Author string // username
AuthorName string // full name; empty when GitLab omits it
Body string
System bool
Resolvable bool
Resolved bool
CreatedAt time.Time
Position *Position // nil for general (unpositioned) notes
}
Note is a single comment, optionally anchored to a diff position.
func (Note) AuthorDisplay ¶ added in v1.24.0
AuthorDisplay formats the note's author for display.
type PipelineStatus ¶ added in v1.40.0
type PipelineStatus struct {
Status string // GitLab status: success, failed, running, pending, canceled, skipped, manual, ...
WebURL string
}
PipelineStatus is the outcome of an MR's head pipeline. The list API omits pipelines, so it is only populated on MRDetail.
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 RepoFile ¶ added in v1.18.0
RepoFile is one file fetched from a repository tree, named by its base file name within the listed directory.
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)
// CompareRevisions returns the file diffs between two commits (a direct
// two-dot comparison, not merge-base). Used by incremental re-review to
// diff the MR's new head against the last reviewed one; an unreachable
// from-commit (force-push, GC) surfaces as an error.
CompareRevisions(ctx context.Context, project any, from, to string) ([]FileDiff, 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)
// ListDirectoryFiles returns the files directly under dir in the
// project repository at ref, with contents. A missing directory is not
// an error: it returns nil. Used to offer repo-shipped review agents in
// the pickers before any checkout exists.
ListDirectoryFiles(ctx context.Context, project any, dir, ref string) ([]RepoFile, 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
// GetApprovals returns the MR's approval state as seen by the
// current user.
GetApprovals(ctx context.Context, project any, iid int64) (*Approvals, error)
// Approve approves the MR. A non-empty sha must match the MR's HEAD,
// guarding against approving code pushed after it was reviewed.
Approve(ctx context.Context, project any, iid int64, sha string) error
// Unapprove removes the current user's approval from the MR.
Unapprove(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. |