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 ¶
- Variables
- type CodeHost
- type Dashboard
- type Fake
- func (f *Fake) AddConversationComment(_ context.Context, prID, body string) error
- func (f *Fake) AddThread(_ context.Context, reviewID string, t NewThread) error
- func (f *Fake) Checks(_ context.Context, ref domain.PRRef) (domain.Checks, error)
- func (f *Fake) Commits(_ context.Context, ref domain.PRRef) ([]domain.Commit, error)
- func (f *Fake) Dashboard(ctx context.Context) (Dashboard, error)
- func (f *Fake) DeleteConversationComment(_ context.Context, commentID string) error
- func (f *Fake) DeleteReviewComment(_ context.Context, commentID string) error
- func (f *Fake) EditConversationComment(_ context.Context, commentID, body string) error
- func (f *Fake) EditReviewComment(_ context.Context, commentID, body string) error
- func (f *Fake) Forget(_ context.Context, ref domain.PRRef) error
- func (f *Fake) PullRequest(_ context.Context, ref domain.PRRef) (domain.PullRequest, error)
- func (f *Fake) RenderMarkdown(_ context.Context, _ domain.Repo, body string) (string, error)
- func (f *Fake) Reply(_ context.Context, reviewID, threadID, body string) error
- func (f *Fake) ReviewState(_ context.Context, ref domain.PRRef) (domain.ReviewState, error)
- func (f *Fake) SetOnline(online bool)
- func (f *Fake) SetReaction(_ context.Context, subjectID string, r domain.Reaction, on bool) error
- func (f *Fake) SetThreadResolved(_ context.Context, threadID string, resolved bool) error
- func (f *Fake) SetViewed(_ context.Context, prID, path string, viewed bool) error
- func (f *Fake) StartReview(_ context.Context, prID string, commit domain.SHA) (string, error)
- func (f *Fake) State(ref domain.PRRef) *domain.ReviewState
- func (f *Fake) Status() Status
- func (f *Fake) SubmitReview(_ context.Context, prID, reviewID string, commit domain.SHA, ...) error
- type NewThread
- type RateLimit
- type Status
- type Submission
Constants ¶
This section is empty.
Variables ¶
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") // 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 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 (*Fake) AddConversationComment ¶
func (*Fake) DeleteConversationComment ¶
func (*Fake) DeleteReviewComment ¶
DeleteReviewComment removes the comment, and its thread once empty, as GitHub does.
func (*Fake) EditConversationComment ¶
func (*Fake) EditReviewComment ¶
func (*Fake) PullRequest ¶
func (*Fake) RenderMarkdown ¶
func (*Fake) ReviewState ¶
func (*Fake) SetOnline ¶
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 (*Fake) SetThreadResolved ¶
func (*Fake) StartReview ¶
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.
type Status ¶
type Status struct {
Online bool
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 ¶
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. |