codehost

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package codehost is the CodeHost port: Pull Requests and review state on the code host, which is the source of truth for review state.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when the PR does not exist or is not visible.
	ErrNotFound = errors.New("not found")
	// ErrOffline is returned when the code host is unreachable and there is
	// no cached copy to serve instead.
	ErrOffline = errors.New("code host unreachable")
	// ErrUnauthorized is returned when the code host rejects the
	// credentials, e.g. an expired or revoked `gh auth` token.
	ErrUnauthorized = errors.New("code host rejected the credentials")
)

Functions

This section is empty.

Types

type CodeHost

type CodeHost interface {
	PullRequest(ctx context.Context, ref domain.PRRef) (domain.PullRequest, error)
	// Commits lists the PR's commits, oldest first.
	Commits(ctx context.Context, ref domain.PRRef) ([]domain.Commit, error)
	// Dashboard lists the open PRs awaiting the viewer's review and those
	// they authored.
	Dashboard(ctx context.Context) (Dashboard, error)

	// Checks reads the Checks on the PR's head commit and its MergeState.
	Checks(ctx context.Context, ref domain.PRRef) (domain.Checks, error)
	// Status reports reachability and rate limits. Reads are served from
	// cache while the code host is unreachable.
	Status() Status

	// ReviewState reads the PR's Review Threads, Conversation Comments,
	// Reactions, the viewer's Pending Review and Viewed files.
	ReviewState(ctx context.Context, ref domain.PRRef) (domain.ReviewState, error)
	// Forget drops whatever the code host adapter has cached locally for
	// the PR. Nothing on the code host itself changes.
	Forget(ctx context.Context, ref domain.PRRef) error
	// StartReview creates a Pending Review anchored to commit.
	StartReview(ctx context.Context, prID string, commit domain.SHA) (reviewID string, err error)
	// AddThread adds a Review Thread to a Pending Review.
	AddThread(ctx context.Context, reviewID string, t NewThread) error
	// Reply adds a Review Comment to a thread, within a Pending Review.
	Reply(ctx context.Context, reviewID, threadID, body string) error
	SetThreadResolved(ctx context.Context, threadID string, resolved bool) error
	// EditReviewComment replaces a Review Comment's body, pending or not.
	EditReviewComment(ctx context.Context, commentID, body string) error
	// DeleteReviewComment deletes a Review Comment; a thread left with no
	// comments goes with it.
	DeleteReviewComment(ctx context.Context, commentID string) error
	// AddConversationComment posts a Conversation Comment immediately.
	AddConversationComment(ctx context.Context, prID, body string) error
	// EditConversationComment replaces a Conversation Comment's body.
	EditConversationComment(ctx context.Context, commentID, body string) error
	DeleteConversationComment(ctx context.Context, commentID string) error
	// SetReaction adds or removes the viewer's Reaction on a comment or PR.
	SetReaction(ctx context.Context, subjectID string, r domain.Reaction, on bool) error
	// SubmitReview submits the Pending Review, or when reviewID is empty
	// creates and submits a review at commit in one step.
	SubmitReview(ctx context.Context, prID, reviewID string, commit domain.SHA, event domain.ReviewEvent, body string) error
	SetViewed(ctx context.Context, prID, path string, viewed bool) error
	// RenderMarkdown renders a comment body as the code host would show it,
	// sanitised, with references resolved against the PR's repo.
	RenderMarkdown(ctx context.Context, repo domain.Repo, body string) (string, error)
}

CodeHost reads Pull Requests and their review state, and writes review activity. Writes return only errors: callers re-read ReviewState, keeping the code host the single source of truth.

type Dashboard

type Dashboard struct {
	ReviewRequested []domain.PRSummary
	Authored        []domain.PRSummary
}

Dashboard is the set of PR lists shown on the Dashboard.

type Fake

type Fake struct {
	PRs         map[domain.PRRef]domain.PullRequest
	CommitsOf   map[domain.PRRef][]domain.Commit
	Dash        Dashboard
	States      map[domain.PRRef]*domain.ReviewState
	Submissions []Submission
	ChecksOf    map[domain.PRRef]domain.Checks
	Health      Status
	// Forgotten lists the PRs Forget was called for.
	Forgotten []domain.PRRef
	// FailAddThread, when set, makes AddThread fail with it.
	FailAddThread error
	// contains filtered or unexported fields
}

Fake is an in-memory CodeHost for tests. Its review writes update States the way GitHub would, so tests can read the effect back.

func NewFake

func NewFake() *Fake

func (*Fake) AddConversationComment

func (f *Fake) AddConversationComment(_ context.Context, prID, body string) error

func (*Fake) AddThread

func (f *Fake) AddThread(_ context.Context, reviewID string, t NewThread) error

func (*Fake) Checks

func (f *Fake) Checks(_ context.Context, ref domain.PRRef) (domain.Checks, error)

func (*Fake) Commits

func (f *Fake) Commits(_ context.Context, ref domain.PRRef) ([]domain.Commit, error)

func (*Fake) Dashboard

func (f *Fake) Dashboard(ctx context.Context) (Dashboard, error)

func (*Fake) DeleteConversationComment

func (f *Fake) DeleteConversationComment(_ context.Context, commentID string) error

func (*Fake) DeleteReviewComment

func (f *Fake) DeleteReviewComment(_ context.Context, commentID string) error

DeleteReviewComment removes the comment, and its thread once empty, as GitHub does.

func (*Fake) EditConversationComment

func (f *Fake) EditConversationComment(_ context.Context, commentID, body string) error

func (*Fake) EditReviewComment

func (f *Fake) EditReviewComment(_ context.Context, commentID, body string) error

func (*Fake) Forget

func (f *Fake) Forget(_ context.Context, ref domain.PRRef) error

func (*Fake) PullRequest

func (f *Fake) PullRequest(_ context.Context, ref domain.PRRef) (domain.PullRequest, error)

func (*Fake) RenderMarkdown

func (f *Fake) RenderMarkdown(_ context.Context, _ domain.Repo, body string) (string, error)

func (*Fake) Reply

func (f *Fake) Reply(_ context.Context, reviewID, threadID, body string) error

func (*Fake) ReviewState

func (f *Fake) ReviewState(_ context.Context, ref domain.PRRef) (domain.ReviewState, error)

func (*Fake) SetOnline

func (f *Fake) SetOnline(online bool)

SetOnline sets whether the Fake behaves as reachable. Unreachable, it acts like the GitHub adapter: REST reads (PRs, commits, Dashboard) still succeed as if served from cache, while GraphQL reads and all writes fail with ErrOffline.

func (*Fake) SetReaction

func (f *Fake) SetReaction(_ context.Context, subjectID string, r domain.Reaction, on bool) error

func (*Fake) SetThreadResolved

func (f *Fake) SetThreadResolved(_ context.Context, threadID string, resolved bool) error

func (*Fake) SetViewed

func (f *Fake) SetViewed(_ context.Context, prID, path string, viewed bool) error

func (*Fake) StartReview

func (f *Fake) StartReview(_ context.Context, prID string, commit domain.SHA) (string, error)

func (*Fake) State

func (f *Fake) State(ref domain.PRRef) *domain.ReviewState

State returns the review state for ref, creating an empty one.

func (*Fake) Status

func (f *Fake) Status() Status

func (*Fake) SubmitReview

func (f *Fake) SubmitReview(_ context.Context, prID, reviewID string, commit domain.SHA, event domain.ReviewEvent, body string) error

type NewThread

type NewThread struct {
	Path            string
	Line, StartLine int
	Side, StartSide domain.DiffSide
	Body            string
}

NewThread is a Review Thread to add to a Pending Review. StartLine is zero for a single-line thread.

type RateLimit

type RateLimit struct {
	Remaining, Limit int
	Reset            time.Time
	Resource         string // which limit, e.g. "core", "graphql" or "search"
}

RateLimit is an API rate limit's state.

func (RateLimit) Low

func (r RateLimit) Low() bool

Low reports whether less than 10% of the limit remains.

type Status

type Status struct {
	Online bool
	// Unauthorized is set while the code host rejects the credentials.
	Unauthorized bool
	// RateLimit is the most constrained limit seen; Limit is zero before
	// any response has reported one.
	RateLimit RateLimit
}

Status is the code host connection's health as of the last request.

type Submission

type Submission struct {
	PR     domain.PRRef
	Commit domain.SHA
	Event  domain.ReviewEvent
	Body   string
}

Submission records a review submitted to the Fake.

Directories

Path Synopsis
Package github is the CodeHost adapter for github.com: REST reads with ETag conditional requests cached in the Cache port, and GraphQL for review state and writes.
Package github is the CodeHost adapter for github.com: REST reads with ETag conditional requests cached in the Cache port, and GraphQL for review state and writes.

Jump to

Keyboard shortcuts

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