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
- 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, _ 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)
- type Runner
Constants ¶
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 ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a forge.Forge backed by the `gh` 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 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 ¶
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 ¶
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.