Documentation
¶
Overview ¶
Package gitlab implements forge.Forge against the GitLab REST API. It is reached only through the forge.Forge interface; no view imports it.
Index ¶
- Variables
- type Client
- func (c *Client) Approvals(ctx context.Context, ref forge.Ref, mr int) (forge.Approvals, error)
- func (c *Client) Approve(ctx context.Context, ref forge.Ref, mr int) error
- func (c *Client) Capabilities() forge.Caps
- func (c *Client) Comment(ctx context.Context, ref forge.Ref, target, body string) error
- func (c *Client) CreateDiffThread(ctx context.Context, ref forge.Ref, mr int, dc forge.DiffComment) error
- func (c *Client) CreateThread(ctx context.Context, ref forge.Ref, target, body string) error
- func (c *Client) Epics(ctx context.Context, s forge.Scope) ([]forge.Epic, error)
- func (c *Client) EpicsStrict(ctx context.Context, s forge.Scope) ([]forge.Epic, error)
- func (c *Client) FileContent(ctx context.Context, ref forge.Ref, path, rev string) ([]byte, error)
- func (c *Client) GroupIssues(ctx context.Context, group string, f forge.IssueFilter) ([]forge.Issue, error)
- func (c *Client) Issue(ctx context.Context, ref forge.Ref, id int) (forge.Issue, error)
- func (c *Client) Issues(ctx context.Context, ref forge.Ref, f forge.IssueFilter) ([]forge.Issue, error)
- func (c *Client) JobLog(ctx context.Context, ref forge.Ref, jobID int) (io.ReadCloser, error)
- func (c *Client) Jobs(ctx context.Context, ref forge.Ref, pipelineID int) ([]forge.Job, error)
- func (c *Client) Labels(ctx context.Context, s forge.Scope) ([]string, error)
- func (c *Client) Members(ctx context.Context, s forge.Scope) ([]forge.User, error)
- func (c *Client) Merge(ctx context.Context, ref forge.Ref, mr int) error
- func (c *Client) MergeRequest(ctx context.Context, ref forge.Ref, mr int) (forge.MergeRequest, error)
- func (c *Client) MergeRequestDiff(ctx context.Context, ref forge.Ref, mr int) (string, error)
- func (c *Client) MergeRequests(ctx context.Context, ref forge.Ref, f forge.MRFilter) ([]forge.MergeRequest, error)
- func (c *Client) Milestones(ctx context.Context, s forge.Scope) ([]forge.Milestone, error)
- func (c *Client) MyWork(ctx context.Context, f forge.MyWorkFilter) ([]forge.WorkItem, error)
- func (c *Client) Namespaces(ctx context.Context, parent string) ([]forge.Namespace, error)
- func (c *Client) Pipelines(ctx context.Context, ref forge.Ref, f forge.PipelineFilter) ([]forge.Pipeline, error)
- func (c *Client) Rebase(ctx context.Context, ref forge.Ref, mr int) error
- func (c *Client) Repos(ctx context.Context, namespace string) ([]forge.Repo, error)
- func (c *Client) ResolveTodo(ctx context.Context, t forge.Todo) error
- func (c *Client) RetryPipeline(ctx context.Context, ref forge.Ref, pipelineID int) error
- func (c *Client) SetFields(ctx context.Context, ref forge.Ref, target string, patch forge.FieldPatch) error
- func (c *Client) Starred(ctx context.Context) ([]forge.Repo, error)
- func (c *Client) Statuses(ctx context.Context, s forge.Scope) ([]forge.Status, error)
- func (c *Client) StatusesStrict(ctx context.Context, s forge.Scope) ([]forge.Status, error)
- func (c *Client) SubmitReview(ctx context.Context, ref forge.Ref, mr int, r forge.Review) (forge.ReviewResult, error)
- func (c *Client) Threads(ctx context.Context, ref forge.Ref, target string) ([]forge.Thread, error)
- func (c *Client) Todos(ctx context.Context, f forge.TodoFilter) ([]forge.Todo, error)
- func (c *Client) Tree(ctx context.Context, ref forge.Ref, path, rev string) ([]forge.TreeEntry, error)
- func (c *Client) Unapprove(ctx context.Context, ref forge.Ref, mr int) error
- func (c *Client) Whoami(ctx context.Context) (forge.User, error)
Constants ¶
This section is empty.
Variables ¶
var ErrPartialReview = errors.New("the comments were published; the verdict could not be recorded")
ErrPartialReview reports a review whose comments were published but whose standing was not recorded.
It is a distinct error because the two halves fail differently and the caller must not offer the publish again: the remarks really did land, and sending them twice is worse than a missing verdict.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client adapts the GitLab SDK to forge.Forge.
func New ¶
func New(profile, host, token string, transport http.RoundTripper) (*Client, error)
New builds a Client for one profile/host pair using a token obtained from the glab CLI.
transport, when given, is the caching round-tripper. It is installed here rather than wrapped around forge.Forge so that every endpoint is covered without any call site knowing about it.
func (*Client) Approvals ¶ added in v0.7.0
Approvals reports where a merge request stands.
The approvals endpoint is the one that works on every tier: approval_state is Premium, and this carries everything a header and a column need — including whether this account has approved and whether it is even allowed to, which saves guessing at the author rule.
func (*Client) Capabilities ¶
Capabilities reports what GitLab accepts.
Multi-line suggestions have been on by default since 13.7; a project that turned them off rejects the comment, which surfaces as an API error rather than a silent miss.
func (*Client) CreateDiffThread ¶
func (c *Client) CreateDiffThread(ctx context.Context, ref forge.Ref, mr int, dc forge.DiffComment) error
CreateDiffThread opens a discussion anchored to a place in the diff.
GitLab positions a comment with the three commits the diff was taken against plus the file and line. Without them the API takes the comment but drops it at the bottom of the discussion, which is a different comment from the one the reviewer wrote — so a missing position is refused here rather than posted somewhere else.
func (*Client) CreateThread ¶
CreateThread starts a new discussion on an issue or merge request.
It is a discussion rather than a note so a review comment opens its own resolvable thread, which is what a reviewer expects to be able to close.
func (*Client) Epics ¶ added in v0.6.0
Epics lists the epics a scope can file issues under. Epics are a group-level feature, so a project Scope resolves to its immediate namespace group rather than the project itself.
Epics also need a licensed GitLab (Premium and above): on a Free instance the query errors, and this answers with nothing and no error — the same fail-quiet Statuses and workItems follow, and for the same reason: a board's epic legend should degrade gracefully, not fail the board. EpicsStrict is the propagating twin, for the epic picker, the same way StatusesStrict is for the status one.
resolveEpicParent, which resolves an epic title for a write rather than a listing, deliberately does not call this — see its own doc comment for why fail-quiet is wrong there.
func (*Client) EpicsStrict ¶ added in v0.6.0
EpicsStrict is Epics without the fail-quiet wrapping. It resolves the scope to a group the same way Epics does — an empty group is genuinely "nothing to ask," not a failure, so that case still answers (nil, nil) rather than an error — and then calls queryEpics directly, the same propagating query resolveEpicParent already relies on for the write path.
func (*Client) FileContent ¶
FileContent returns a file's bytes at a revision.
func (*Client) GroupIssues ¶
func (c *Client) GroupIssues(ctx context.Context, group string, f forge.IssueFilter) ([]forge.Issue, error)
GroupIssues lists issues across every project in a group — what GitLab's group issue board shows.
func (*Client) Issues ¶
func (c *Client) Issues(ctx context.Context, ref forge.Ref, f forge.IssueFilter) ([]forge.Issue, error)
Issues lists issues in a project.
The status query is scoped to the project rather than to the issues, so when one is wanted it is started alongside the listing instead of after it: the board pays for the slower of the two rather than for both.
func (*Client) JobLog ¶
JobLog returns a job's trace. GitLab hands back the whole trace as a buffer, so the reader needs no closing beyond satisfying the interface.
func (*Client) Members ¶ added in v0.6.0
Members lists a project's or a group's members, including those inherited from an ancestor group — the same "who could this be assigned to" set the provider's own web UI offers.
func (*Client) Merge ¶
Merge merges a merge request immediately.
It deliberately does not set auto-merge: a stack merges under the user's explicit, confirmed keypress, and a queued merge that lands later would take the decision out of their hands.
func (*Client) MergeRequest ¶
func (c *Client) MergeRequest(ctx context.Context, ref forge.Ref, mr int) (forge.MergeRequest, error)
MergeRequest fetches one merge request by its number.
func (*Client) MergeRequestDiff ¶
MergeRequestDiff returns the merge request as a unified diff.
GitLab hands back one entry per file, carrying only the hunks — no "diff --git" or ---/+++ headers. Those are reconstructed here so the result is a real unified diff that any diff tool can read.
func (*Client) MergeRequests ¶
func (c *Client) MergeRequests(ctx context.Context, ref forge.Ref, f forge.MRFilter) ([]forge.MergeRequest, error)
MergeRequests lists merge requests in a project.
func (*Client) Milestones ¶ added in v0.6.0
Milestones lists the milestones a project's or a group's issues can be put on — its own, and every one inherited from a group above it, the way Epics already reaches up the tree with includeAncestors.
func (*Client) MyWork ¶
MyWork lists the current user's issues and merge requests across every project they can see.
GitLab has no single "everything of mine" endpoint, so this runs one query per kind and role — up to five — and merges them.
They run at once, and are merged in the order they were *asked for* rather than the order they arrived. An item matching several roles keeps the first in priority order, and that has to be a property of the list rather than of which request happened to come back quickest.
func (*Client) Namespaces ¶
Namespaces lists subgroups of parent, or top-level groups when parent is "".
func (*Client) Pipelines ¶
func (c *Client) Pipelines(ctx context.Context, ref forge.Ref, f forge.PipelineFilter) ([]forge.Pipeline, error)
Pipelines lists a project's CI runs, most recent first.
func (*Client) Rebase ¶
Rebase brings a merge request up to date with its target branch through GitLab's API. gu never runs git locally, so this is the only rebase path.
func (*Client) Repos ¶
Repos lists the projects directly inside a group.
Simple is on because toRepo reads six fields and the full representation is closer to sixty, most of them settings blocks and permission matrices no listing has ever drawn. On a group of eleven projects that is 65 KB against 9.5 KB, and a second against under half of one — paid on the explorer's most common screen, every time it opens.
func (*Client) ResolveTodo ¶ added in v0.11.0
ResolveTodo marks one todo done.
func (*Client) RetryPipeline ¶
RetryPipeline re-runs a pipeline's failed and canceled jobs.
func (*Client) SetFields ¶
func (c *Client) SetFields(ctx context.Context, ref forge.Ref, target string, patch forge.FieldPatch) error
SetFields applies a partial update to an issue or merge request.
Milestone and Assignees are names a person recognises; GitLab's REST API wants ids, so both are resolved against the scope's milestones/members before writing. A name that resolves to nothing is reported back rather than dropped — a patch that looks applied and silently is not is the exact bug this method exists to close.
Status and Epic have no REST field at all — the REST issues endpoint does not carry them — so on an issue they go through a separate GraphQL mutation after the REST write. Merge requests have neither widget, so a patch touching them there is simply not applied — the same "ignore what does not apply" contract GitHub gets for Status/Epic on every target.
func (*Client) Statuses ¶ added in v0.6.0
Statuses lists the work-item statuses a scope's issues can take, each tagged with the category (see statusCategory) internal/ui/board.go sorts the status lanes by — GitLab's own array order is the configured lifecycle, but position is always 0 on every status, so category plus array order is the only signal that survives an admin renaming one.
The status widget needs a recent GitLab: on an instance without it, the query errors and this answers with nothing and no error, same as workItems above — a board that groups by label instead is far better than one that fails to open. StatusesStrict is the propagating twin, for a caller — the status picker — that needs to tell that apart from a real failure.
func (*Client) StatusesStrict ¶ added in v0.6.0
StatusesStrict is Statuses without the fail-quiet wrapping — see its own doc comment, and forge.Forge's, for why the picker needs this instead.
func (*Client) SubmitReview ¶ added in v0.7.0
func (c *Client) SubmitReview(ctx context.Context, ref forge.Ref, mr int, r forge.Review) (forge.ReviewResult, error)
SubmitReview publishes a review as one unit.
GitLab builds a review out of draft notes: each remark is staged, then the whole batch is published in one request that also carries the summary and the reviewer's standing. That is what makes a review one notification instead of one per remark.
The order is forced. Drafts must exist before they can be published, and the formal approval has to come last because bulk_publish explicitly does not record one.
func (*Client) Threads ¶
Threads lists the discussions on an issue or merge request.
It uses the discussions endpoint rather than notes: notes arrive as a flat list, and the reply structure of a review conversation is the whole point of showing them.
Every page is followed. A long-running merge request goes past a hundred discussions easily, and stopping at the first page did not lose the last comments visibly — it lost them silently, which is worse: the page looked complete and was short by a quarter.
func (*Client) Tree ¶
func (c *Client) Tree(ctx context.Context, ref forge.Ref, path, rev string) ([]forge.TreeEntry, error)
Tree lists the entries directly under a path.