ghcli

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package ghcli implements the forge.Forge interface by shelling out to the GitHub CLI (`gh`). Wrapping `gh` means authentication, enterprise hosts, and token storage are already solved by a tool the user has configured. The command runner is injectable so the client is unit-testable without network access or a real `gh` binary.

Index

Constants

View Source
const DefaultListFilter = "is:open review-requested:@me"

DefaultListFilter is the gh engine's default search: open pull requests waiting for the authenticated user's review.

Variables

This section is empty.

Functions

func ExecRunner

func ExecRunner(ctx context.Context, stdin []byte, args ...string) ([]byte, error)

ExecRunner runs `gh` with the given arguments, optionally feeding stdin.

Types

type Client

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

Client is a forge.Forge backed by the `gh` CLI.

func New

func New() *Client

New returns a Client that shells out to the real `gh` binary.

func NewWithRunner

func NewWithRunner(r Runner) *Client

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 comment through the issues endpoint — the API surface general PR comments actually live on.

func (*Client) Attachment added in v0.0.6

func (c *Client) Attachment(ctx context.Context, _ forge.PullRequestRef, url string) ([]byte, error)

Attachment fetches a comment attachment. Signed asset URLs (what resolveAttachments substitutes into bodies) and other public links are plain, size-capped fetches; only api.* URLs go through gh, which attaches credentials. Deliberately NOT gh for github.com/user-attachments URLs: those answer API credentials with an HTML viewer page, not the asset.

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 all comments as one review with the given event, grouping them atomically rather than posting unrelated immediate comments.

func (*Client) Diff

func (c *Client) Diff(ctx context.Context, ref forge.PullRequestRef) ([]byte, error)

Diff fetches the canonical PR diff (the representation comments must align with) by requesting the diff media type from the pulls endpoint.

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 contents API with the raw media type, so the bytes arrive verbatim instead of base64-wrapped JSON.

func (*Client) GeneralComments added in v0.0.8

func (c *Client) GeneralComments(ctx context.Context, ref forge.PullRequestRef) ([]forge.Comment, error)

GeneralComments lists the PR's conversation comments. GitHub models them as issue comments — a PR is an issue with code attached — so this is the issues endpoint, not pulls.

func (*Client) List

func (c *Client) List(ctx context.Context, filter string) ([]forge.ListedRequest, error)

List discovers pull requests via `gh search prs`. The filter is a GitHub search query (qualifiers like "review-requested:@me", "author:x", "repo:owner/name"); an empty filter applies DefaultListFilter.

func (*Client) PullRequest

func (c *Client) PullRequest(ctx context.Context, ref forge.PullRequestRef) (*forge.PullRequest, error)

PullRequest fetches pull-request metadata via `gh 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 to an existing review comment.

func (*Client) Threads

func (c *Client) Threads(ctx context.Context, ref forge.PullRequestRef) ([]forge.Thread, error)

Threads lists the PR's review comments and groups them into threads: root comments (those not replying to another) with their replies attached. The GitHub API is "outdated" when a comment's line no longer maps to the current diff (line is null but original_line is set).

type Runner

type Runner func(ctx context.Context, stdin []byte, args ...string) ([]byte, error)

Runner executes a `gh` invocation and returns its stdout. stdin, when non-nil, is fed to the process (used to send JSON request bodies). Tests substitute a fake; production uses ExecRunner.

Jump to

Keyboard shortcuts

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