Documentation
¶
Overview ¶
Package glabcli implements the forge.Forge interface by shelling out to the GitLab CLI (`glab`), whose `api` subcommand is a deliberate port of `gh api` (same --method/--input/--hostname/--paginate flags). Wrapping glab keeps authentication and self-hosted instances the user's problem to configure once, not ours. The command runner is injectable so the client is unit-testable without network access or a real glab binary.
Terminology note: GitLab calls them merge requests and models review discussion as "discussions" containing "notes"; this package maps those onto the forge vocabulary (PullRequest, Thread, Comment).
Index ¶
- Constants
- func ExecRunner(ctx context.Context, stdin []byte, args ...string) ([]byte, error)
- type Client
- func (c *Client) AddGeneralComment(ctx context.Context, ref forge.PullRequestRef, body string) (*forge.Comment, error)
- func (c *Client) Attachment(ctx context.Context, ref forge.PullRequestRef, url string) ([]byte, error)
- func (c *Client) CreateReview(ctx context.Context, ref forge.PullRequestRef, event forge.ReviewEvent, ...) (*forge.SubmittedReview, error)
- func (c *Client) Diff(ctx context.Context, ref forge.PullRequestRef) ([]byte, error)
- func (c *Client) FileContent(ctx context.Context, ref forge.PullRequestRef, path, rev string) ([]byte, error)
- func (c *Client) GeneralComments(ctx context.Context, ref forge.PullRequestRef) ([]forge.Comment, error)
- func (c *Client) List(ctx context.Context, filter string) ([]forge.ListedRequest, error)
- func (c *Client) PullRequest(ctx context.Context, ref forge.PullRequestRef) (*forge.PullRequest, error)
- func (c *Client) Reply(ctx context.Context, ref forge.PullRequestRef, commentID int64, body string) (*forge.Comment, error)
- func (c *Client) Threads(ctx context.Context, ref forge.PullRequestRef) ([]forge.Thread, error)
- func (c *Client) UploadAttachment(ctx context.Context, ref forge.PullRequestRef, path string) (string, error)
- type Runner
Constants ¶
const DefaultListFilter = "state=opened&reviewer_username=@me"
DefaultListFilter is the glab engine's default listing: open merge requests waiting for the authenticated user's review. "@me" is substituted with the authenticated username before the request.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a forge.Forge backed by the `glab` CLI.
func NewWithRunner ¶
NewWithRunner returns a Client using a custom runner (for tests).
func (*Client) AddGeneralComment ¶ added in v0.0.13
func (c *Client) AddGeneralComment(ctx context.Context, ref forge.PullRequestRef, body string) (*forge.Comment, error)
AddGeneralComment posts a conversation-level note on the merge request.
func (*Client) Attachment ¶ added in v0.0.6
func (c *Client) Attachment(ctx context.Context, ref forge.PullRequestRef, url string) ([]byte, error)
Attachment fetches a comment attachment. GitLab embeds uploads as project-relative /uploads/<secret>/<file> paths, served by the project uploads API with the user's authentication; absolute URLs fall back to a plain, size-capped HTTP fetch.
func (*Client) CreateReview ¶
func (c *Client) CreateReview(ctx context.Context, ref forge.PullRequestRef, event forge.ReviewEvent, summary string, comments []forge.ReviewComment) (*forge.SubmittedReview, error)
CreateReview submits the review to GitLab. GitLab's REST API has no atomic review-with-comments endpoint (that is a GitHub concept), so this maps the forge contract onto GitLab's model: each line comment becomes a positioned diff discussion, the summary becomes a merge-request note, and the event maps to an approval (APPROVE) or a "Changes requested" note (REQUEST_CHANGES). Comments are posted in order; on the first failure the error reports how many were already published so the reviewer is not left guessing.
func (*Client) Diff ¶
Diff fetches the merge request's changes and synthesizes a unified git-style patch from them (GitLab's `diff` field carries only the hunks, so the per-file headers are reconstructed here). This is GitLab's canonical diff representation — the one review-comment positions must align with.
func (*Client) FileContent ¶ added in v0.0.4
func (c *Client) FileContent(ctx context.Context, ref forge.PullRequestRef, path, rev string) ([]byte, error)
FileContent fetches path at rev via the repository files raw endpoint; GitLab addresses the file as one URL-encoded path segment, unlike GitHub's slash-preserving contents API.
func (*Client) GeneralComments ¶ added in v0.0.8
func (c *Client) GeneralComments(ctx context.Context, ref forge.PullRequestRef) ([]forge.Comment, error)
GeneralComments lists the MR's human conversation notes, oldest first.
func (*Client) List ¶
List discovers merge requests via the global merge_requests endpoint. The filter is a REST query string ("state=opened&labels=x"); an empty filter applies DefaultListFilter, and any "@me" value is replaced with the authenticated user's name.
func (*Client) PullRequest ¶
func (c *Client) PullRequest(ctx context.Context, ref forge.PullRequestRef) (*forge.PullRequest, error)
PullRequest fetches merge-request metadata via `glab api`.
func (*Client) Reply ¶
func (c *Client) Reply(ctx context.Context, ref forge.PullRequestRef, commentID int64, body string) (*forge.Comment, error)
Reply posts a reply into the discussion that contains the given note. GitLab keys replies by discussion id (a string), so the discussion list is consulted to find the thread the note belongs to.
func (*Client) Threads ¶
Threads lists the merge request's discussions as forge threads. System notes (e.g. "added 3 commits") are skipped; the first human note of a discussion is the root and the rest are replies. A diff position with neither line resolved marks the thread outdated.
func (*Client) UploadAttachment ¶ added in v0.0.16
func (c *Client) UploadAttachment(ctx context.Context, ref forge.PullRequestRef, path string) (string, error)
UploadAttachment sends a local file to the project's Markdown uploads endpoint (multipart via glab's --form) and returns the project-relative /uploads reference GitLab resolves inside MR notes and descriptions — exactly the form the attachment fetcher already knows how to read back.