Documentation
¶
Overview ¶
Package hookrefresh refreshes pull requests as soon as a hook reports they may have changed: a coding-agent session ending in a registered clone, or a push from one. It runs the same model-free refresh as background synchronization (background.Service.RefreshNow) instead of waiting for its next pass. When a refresh shows that a pull request's head moved and automatic generation could apply, it asks the automatic scheduler to look at the repository again (automatic.Scheduler.Trigger), which alone decides whether a job is queued. It never enqueues or invokes generation itself.
Index ¶
Constants ¶
const ( // Debounce is how long events are collected before any is acted on. Debounce = 3 * time.Second // PushDelay is how long after a pre-push hook ran its pull requests are // refreshed: the hook runs before the push reaches GitHub. PushDelay = 10 * time.Second // Recheck is how long after a refresh that did not show the pushed head // yet the pull request is refreshed once more. Recheck = 30 * time.Second // MaxChecks bounds the refreshes that wait for one pushed head. MaxChecks = 2 // Window is the least time between two refreshes of one pull request, // and between two discovery polls of one repository. Window = 30 * time.Second // MaxAge is the oldest event acted on: an event spooled while no daemon // ran is left to the periodic refresh. MaxAge = 10 * time.Minute // Buffer is how many events wait for the worker; the record drops (and // logs) what arrives while it is full. Buffer = 64 )
Timing. A burst of events (several pushes, sessions ending together) becomes at most one refresh of each pull request it names per Window, plus one recheck of a pushed head, and at most one discovery poll of each repository per Window.
Variables ¶
This section is empty.
Functions ¶
func Match ¶
func Match(e hookevents.Event) bool
Match accepts the events the service acts on: an agent session that ended, and a push Git went on with (a pre-push hook that exited 0). post-rewrite is not one: a rewrite changes nothing on GitHub until it is pushed.
Types ¶
type Service ¶
type Service struct {
Registry Registry
// Cached reads a repository's discovery snapshot from disk, without
// network access.
Cached func(context.Context, github.Repository) (discovery.Snapshot, error)
// Refresh refreshes some pull requests of one clone and returns what it
// observed: background.Service.RefreshNow.
Refresh func(context.Context, repos.Clone, []int) ([]discovery.Observation, error)
// Trigger has the automatic scheduler poll one repository and observe
// the result: automatic.Scheduler.Trigger.
Trigger func(context.Context, string) error
// Git inspects the working tree containing dir, a working tree of
// repository: its common directory and, with remote, the repository that
// remote fetches from, else the work checked out. Nil runs git
// (LocalGit).
Git func(ctx context.Context, dir, repository, remote string) (Worktree, error)
// Changed tells the app that discovery changed after a trigger.
Changed func()
Now func() time.Time
Log *slog.Logger
// contains filtered or unexported fields
}
Service turns hook events into refreshes. Run owns it; it is not safe for concurrent use.
func (*Service) Receive ¶
func (s *Service) Receive(record hookevents.Record)
Receive collects one event for the next Step after Debounce.
func (*Service) Run ¶
func (s *Service) Run(ctx context.Context, events <-chan hookevents.Record)
Run acts on events until ctx ends or events closes. Events come from a hookevents.Store subscription (Match, Buffer): the record never waits for this worker, and drops what does not fit while it refreshes.
type Worktree ¶
type Worktree struct {
// CommonDir is the shared git directory, the same for linked worktrees.
CommonDir string
// Work is what is checked out, read only when no remote was asked for.
Work prlink.Work
// Pushed is the repository the asked-for remote pushes to, as the
// registry names repositories; "" when there is no such remote or it is
// not on GitHub.
Pushed string
}
Worktree is what Git reports about the working tree a hook ran in.