facts

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package facts serves a pull request's facts (review.Facts) to the desktop app's PR page while the pull request has no saved review: its change size, checks, sessions, commits, conversation and the agent reviews posted on it, read the way generation reads them and with no model.

Facts are built only when a page asks for them, never in the background, and are kept in memory only: they are never a version in the store. While the page keeps asking about the same head, GitHub is read again at most once per window, and never while the host's rate limit is paused.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder func(ctx context.Context, clone repos.Clone, number int) (Built, error)

Builder reads a pull request's facts from GitHub, its clone and the sessions on this machine.

type Built

type Built struct {
	// Document is the encoded review.Facts.
	Document []byte
	// Head and Base are the commits the facts describe.
	Head, Base string
}

Built is one pull request's facts.

type Local

type Local struct {
	Client assemble.GitHub
	Config config.Config
}

Local builds facts with the sources generation assembles its bundle from: the GitHub client, the clone (fetching a pull request commit it lacks, as generation does) and the local session stores.

func (Local) Build

func (l Local) Build(ctx context.Context, clone repos.Clone, number int) (Built, error)

Build assembles the pull request's bundle in facts mode and derives its facts.

type Service

type Service struct {
	Build Builder
	// Window is how long facts stand before a request about the same head
	// reads GitHub again; zero is the background refresh's default interval.
	// A failed build stands for ten seconds at most, a rate-limited one for
	// the whole window.
	Window time.Duration
	// Paused is when the host's GitHub rate limit lets reads resume, as the
	// background refresh keeps it; nil never pauses.
	Paused func(host string) time.Time
	// Limited records a rate limit a build hit, so the background refresh
	// waits it out too.
	Limited func(host string, until time.Time)
	Now     func() time.Time
	// contains filtered or unexported fields
}

Service builds facts on demand and keeps the latest of each pull request, per clone, repository and pull request; a new head or base replaces them.

func (*Service) Cached

func (s *Service) Cached(clone repos.Clone, number int) ([]byte, string)

Cached is the latest facts built for the pull request and the head they describe, nil when there are none. It never reads GitHub: a page's patches and sessions are read against the facts it was shown.

func (*Service) Facts

func (s *Service) Facts(ctx context.Context, clone repos.Clone, number int, head string) ([]byte, error)

Facts answers the pull request's facts at head, the head the page shows ("" for whichever is current). It builds them when it has none for that head, or when the latest build is older than the window; concurrent requests share one build whichever head they ask about, as a build reads the head GitHub reports. A paused rate limit answers the facts it has for that head, else a *github.RateLimitedError.

Jump to

Keyboard shortcuts

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