hookrefresh

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: 13 Imported by: 0

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

View Source
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 Registry

type Registry interface {
	List(context.Context) ([]repos.Clone, error)
	Preferences(context.Context) (repos.Preferences, error)
	RepositorySettings(ctx context.Context, repository string) (repos.Settings, bool, error)
}

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) Next

func (s *Service) Next() (time.Time, bool)

Next is when Step has work next.

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.

func (*Service) Step

func (s *Service) Step(ctx context.Context)

Step does what is due: it maps the collected events to pull requests, refreshes the pull requests whose time has come, and triggers the scheduler for repositories where a head moved. Exposed for tests.

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.

func LocalGit

func LocalGit(ctx context.Context, dir, repository, remote string) (Worktree, error)

LocalGit inspects the working tree containing dir with git: its common directory and, when remote is set, the repository that remote pushes to, else the work checked out (prlink.Local). It reads configuration only and contacts no remote.

Jump to

Keyboard shortcuts

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