Documentation
¶
Overview ¶
Package source resolves command-line arguments into a ReviewSource: something that yields a parsed set of file diffs, a human title, and a stable key for draft persistence. It unifies the patch-file / stdin path with the local-git path; pull-request references are resolved by the CLI layer into a PRSource before Resolve is consulted.
Index ¶
- func InferPRRef(ctx context.Context, dir string, ref forge.PullRequestRef) (forge.PullRequestRef, error)
- type ContextContenter
- type ExchangeSource
- func (s *ExchangeSource) Exchange() *review.Exchange
- func (s *ExchangeSource) Files(context.Context) ([]diff.FileDiff, error)
- func (s *ExchangeSource) HeadOID(context.Context) string
- func (s *ExchangeSource) Key() string
- func (s *ExchangeSource) Path() string
- func (s *ExchangeSource) RawPatch(context.Context) ([]byte, error)
- func (s *ExchangeSource) Title() string
- type Options
- type PRSource
- func (s *PRSource) Attachment(ctx context.Context, url string) ([]byte, error)
- func (s *PRSource) ContextContent(ctx context.Context, path string, side diff.Side) ([]byte, error)
- func (s *PRSource) ContextKey(_ context.Context, path string, side diff.Side) string
- func (s *PRSource) Files(ctx context.Context) ([]diff.FileDiff, error)
- func (s *PRSource) Forge() forge.Forge
- func (s *PRSource) GeneralComments(ctx context.Context) ([]forge.Comment, error)
- func (s *PRSource) HeadOID(context.Context) string
- func (s *PRSource) Key() string
- func (s *PRSource) PullRequest() *forge.PullRequest
- func (s *PRSource) RawPatch(ctx context.Context) ([]byte, error)
- func (s *PRSource) Ref() forge.PullRequestRef
- func (s *PRSource) Threads(ctx context.Context) ([]forge.Thread, error)
- func (s *PRSource) Title() string
- type RawPatcher
- type ReviewSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InferPRRef ¶
func InferPRRef(ctx context.Context, dir string, ref forge.PullRequestRef) (forge.PullRequestRef, error)
InferPRRef fills in a missing owner/repo (and host) from the origin remote of the repository at dir, so a bare PR number resolves inside a checkout. It is a no-op when owner and repo are already set (e.g. from a full URL).
Types ¶
type ContextContenter ¶ added in v0.0.4
type ContextContenter interface {
ContextKey(ctx context.Context, path string, side diff.Side) string
ContextContent(ctx context.Context, path string, side diff.Side) ([]byte, error)
}
ContextContenter is implemented by sources that can produce the full content of a file on either side of the diff — new side for the TUI's full-file context view, old side additionally for whole-file syntax highlighting of deletions. ContextKey is the content's cache identity (cheap to compute; "" means uncacheable — typically mutable local state like the working tree), and ContextContent performs the actual, possibly expensive, fetch. Callers pass the path as spelled on that side (renames).
type ExchangeSource ¶ added in v0.0.2
type ExchangeSource struct {
// contains filtered or unexported fields
}
ExchangeSource is a ReviewSource backed by a review-exchange file: the diff under review is the patch embedded in the document, and the document's comments seed the draft. It keeps the file path so the session can write the updated conversation back to the same place — the file, not the draft store, is the medium the two sides of the conversation share.
func (*ExchangeSource) Exchange ¶ added in v0.0.2
func (s *ExchangeSource) Exchange() *review.Exchange
Exchange exposes the parsed document so the CLI can seed the draft from it.
func (*ExchangeSource) Files ¶ added in v0.0.2
Files parses the embedded patch — the only diff the conversation's line numbers are meaningful against.
func (*ExchangeSource) HeadOID ¶ added in v0.0.2
func (s *ExchangeSource) HeadOID(context.Context) string
HeadOID is empty: the embedded patch carries no commit identity, and relocation across patch versions happens on import instead.
func (*ExchangeSource) Key ¶ added in v0.0.2
func (s *ExchangeSource) Key() string
Key seeds the draft store's filename; path-based so round trips resume.
func (*ExchangeSource) Path ¶ added in v0.0.2
func (s *ExchangeSource) Path() string
Path is where the conversation lives on disk — the writeback target.
func (*ExchangeSource) RawPatch ¶ added in v0.0.2
func (s *ExchangeSource) RawPatch(context.Context) ([]byte, error)
RawPatch returns the embedded patch for re-embedding on writeback.
func (*ExchangeSource) Title ¶ added in v0.0.2
func (s *ExchangeSource) Title() string
Title is the document's title, or the filename when it has none.
type Options ¶
type Options struct {
Args []string // positional arguments
Base string // --base <ref>
Staged bool // --staged
Context int // -U context lines
Stdin io.Reader // stdin, used when the argument is "-"
Dir string // working directory (defaults to process CWD)
}
Options are the parsed CLI inputs used to resolve a source.
type PRSource ¶
type PRSource struct {
// contains filtered or unexported fields
}
PRSource is a ReviewSource backed by a forge pull request. It uses the host's canonical diff (the representation comments must align with) and exposes the forge, ref, and threads so the TUI can reply and submit reviews.
func NewPRSource ¶
NewPRSource fetches pull-request metadata and returns a ready source. The metadata call establishes the title and head commit up front.
func (*PRSource) Attachment ¶ added in v0.0.6
Attachment fetches a comment-attachment URL through the forge's authentication — comment images on private repos are unreachable without it.
func (*PRSource) ContextContent ¶ added in v0.0.4
ContextContent fetches the file at the side's commit through the forge.
func (*PRSource) ContextKey ¶ added in v0.0.4
ContextKey is commit + path: PR file content is immutable per commit, so a force-push or new commit changes the key rather than any cache state.
func (*PRSource) GeneralComments ¶ added in v0.0.8
GeneralComments fetches the PR's conversation-level comments.
func (*PRSource) HeadOID ¶
HeadOID returns the PR head commit captured at construction. It is recorded in the draft so that, on the next session, a changed head triggers comment relocation against the new diff.
func (*PRSource) Key ¶
Key seeds the draft store's filename, so it must be stable across sessions and filesystem-safe: the host is made explicit (an empty host means github.com) and any "/" in the owner (GitLab nested groups) is flattened.
func (*PRSource) PullRequest ¶
func (s *PRSource) PullRequest() *forge.PullRequest
PullRequest returns the metadata fetched at construction; the TUI uses it for the PR-info overlay (title, description, author) without another network round-trip.
func (*PRSource) RawPatch ¶ added in v0.0.2
RawPatch returns the host's canonical diff verbatim, enabling exchange export with the exact bytes review positions are anchored to.
func (*PRSource) Ref ¶
func (s *PRSource) Ref() forge.PullRequestRef
Ref returns the pull-request reference; the TUI's PR context passes it back on every forge call (threads, replies, review submission).
type RawPatcher ¶ added in v0.0.2
RawPatcher is implemented by sources that can hand out the raw unified patch they were built from. The review-exchange export needs the literal patch text (parsed FileDiffs cannot be serialised back verbatim), so exchange export is available exactly where this interface is.
type ReviewSource ¶
type ReviewSource interface {
// Files parses and returns the diff for this source.
Files(ctx context.Context) ([]diff.FileDiff, error)
// Title is a short human description shown in the status bar.
Title() string
// Key is a stable identifier used to namespace persisted drafts.
Key() string
// HeadOID returns the head commit the source was captured against, or "".
HeadOID(ctx context.Context) string
}
ReviewSource is a resolved, ready-to-load set of changes under review.