provider

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package provider defines the Provider interface and URL-based registry that selects a GitHub or GitLab adapter. Lands in M2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodePages added in v0.3.0

func DecodePages[T any](data []byte) ([]T, error)

DecodePages unmarshals the output of `gh api --paginate` / `glab api --paginate` into one slice. Both CLIs emit each page as a SEPARATE top-level JSON array, back to back ("[...][...]"), so a plain json.Unmarshal into a slice works only for single-page responses and fails on exactly the busy targets where pagination kicks in (diffsmith-kjk). Decoding page-by-page handles one page and many identically; empty input yields an empty slice.

func DefaultRunner

func DefaultRunner(ctx context.Context, stdin io.Reader, name string, args ...string) ([]byte, error)

DefaultRunner runs the command via os/exec and returns stdout. The child inherits diffsmith's working directory. Use this for provider CLIs (gh/glab) that operate on explicit URLs and for any caller that genuinely needs the real cwd.

func IsBotLogin added in v0.4.0

func IsBotLogin(login string) bool

IsBotLogin reports whether a forge login belongs to an automated reviewer rather than a human. It is a best-effort heuristic used to keep the inbox's commenter list to humans (the "who's waiting on me" signal). GitHub callers should prefer the GraphQL __typename == "Bot" signal and use this only as a fallback; GitLab has no clean bot flag, so this is the primary filter there.

Types

type PRSummary

type PRSummary struct {
	Number    int
	Title     string
	Author    string
	URL       string // canonical, ready to hand to runReview
	UpdatedAt time.Time
	Draft     bool

	// Enrichment (display-only; populated by List, zero when not enriched).
	CommentCount      int      // conversation + inline comments, incl. bots
	ResolvedThreads   int      // ✔ review threads / resolvable discussions
	UnresolvedThreads int      // ✖
	HumanCommenters   []string // bot-filtered, deduped, excludes the PR author
	Enriched          bool     // false if enrichment failed for this row
}

PRSummary is one row in the inbox list. URL is the only field the review pipeline strictly needs; the rest are display-only.

type Provider

type Provider interface {
	Supports(rawURL string) bool
	Preflight(ctx context.Context) error
	Fetch(ctx context.Context, rawURL string) (*review.ReviewInput, error)

	// PreflightList is a stricter preflight required for List(). The
	// public-URL Fetch flow doesn't need auth, but listing typically
	// does. Implementations should verify `gh auth status` / `glab auth
	// status` (or equivalent) succeeds and return an actionable error
	// otherwise.
	PreflightList(ctx context.Context) error

	// List enumerates open PRs/MRs for the given repo. Returns at most
	// 30 results in v1 (no pagination).
	List(ctx context.Context, repo RepoCoord) ([]PRSummary, error)
}

Provider fetches review target data for one host family.

Callers must invoke Preflight before Fetch. Preflight verifies the runtime environment (required CLI present, authenticated) so the model is never invoked when the fetch path is doomed to fail.

type Registry

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

Registry dispatches a URL to the first Provider that supports it.

The order of providers passed to NewRegistry is the dispatch order; for v1 the order doesn't matter because GitHub and GitLab URLs don't overlap, but stable ordering keeps error messages deterministic.

func NewRegistry

func NewRegistry(ps ...Provider) *Registry

NewRegistry builds a Registry from a list of providers.

func (*Registry) ByHost

func (r *Registry) ByHost(host string) (Provider, error)

ByHost returns the provider that claims the given host, or an error if none does. Implementation: synthesize candidate PR/MR URLs and reuse each Provider's Supports method. Avoids adding a Host() method to the Provider interface just for this helper.

func (*Registry) Find

func (r *Registry) Find(rawURL string) (Provider, error)

Find returns the first provider that supports the URL, or an error listing the URL when nothing matches.

type RepoCoord

type RepoCoord struct {
	Host  string // "github.com", "gitlab.com", "gitlab.example.com"
	Owner string // "selyafi" or "my-group/sub-group" (GitLab nested)
	Name  string // "diffsmith"
}

RepoCoord identifies a repository hosted on a Git forge. Used by the inbox flow to enumerate PRs/MRs for a specific repo without first constructing a URL.

type Runner

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

Runner executes an external command and returns its stdout.

Modeled as a function type so tests inject canned responses without implementing an interface. Real implementations should use argv form (variadic args) — passing user-controlled values through `sh -c` is forbidden by docs/architecture.md § Process Execution.

Pass stdin as nil when the command takes no input. Adapters that pipe data to the child (e.g. codex via ADR 0007) provide a Reader here.

func IsolatedRunner added in v0.2.0

func IsolatedRunner() Runner

IsolatedRunner returns a Runner that executes each command in a fresh, empty temp directory (removed once the command returns). It exists for the model adapters (diffsmith-4tz): reviewer CLIs like codex/claude/agy autoload project context from their working directory — codex discovers .agents/skills/*/SKILL.md and may *activate* a project skill (e.g. one whose workflow posts review comments), claude onboards from AGENTS.md / CLAUDE.md, and agy (Antigravity) treats its cwd as a workspace. Running them in a neutral temp dir neutralizes that autoload, which protects diffsmith's no-auto-post guarantee and keeps reviews deterministic. The whole diff is piped via stdin, so reviewers need no access to the caller's cwd.

Only the working directory is isolated; user-level config and auth (e.g. ~/.codex, ~/.claude) live under $HOME and are found via the environment, not cwd, so they keep working.

Directories

Path Synopsis
Package githubgh implements the GitHub provider adapter by shelling out to the `gh` CLI.
Package githubgh implements the GitHub provider adapter by shelling out to the `gh` CLI.
Package gitlabglab implements the GitLab provider adapter by shelling out to the `glab` CLI.
Package gitlabglab implements the GitLab provider adapter by shelling out to the `glab` CLI.

Jump to

Keyboard shortcuts

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