Documentation
¶
Overview ¶
Package ciloop is the CI-aware PR loop (docs/ci-loop.md): once Lectern opens a pull request for a task or session on a project that opted in, it watches the PR's checks through the target's own `gh`, and when they fail it sends the owning agent a short failure report — failing job names and a trimmed, redacted log tail — asking it to fix them. A session's agent pushes its own fix; a task's headless follow-up usually cannot run git, so Lectern commits and pushes what it leaves (commit.go). It stops on pass, merge, close or the attempt cap, and pushes a phone notification when CI goes green after fixes or when it gives up.
There are no webhooks (Lectern is tailnet-only). The loop polls, with backoff, and only while a PR still has pending or failing checks.
Index ¶
- Constants
- Variables
- func FindPRURL(output string) string
- func IsActionsLink(link string) bool
- func JobLog(ctx context.Context, ex executor.Executor, prURL, link string) (string, bool)
- func Label(cw *store.CIWatch) string
- func Redact(s string) string
- func TrimForAgent(raw string) string
- func ValidPRURL(s string) bool
- func ViewLog(raw string) string
- type Notifier
- type Owner
- type SessionSender
- type View
- type Watcher
- func (w *Watcher) Arm(o Owner, prURL string, force bool) (*store.CIWatch, error)
- func (w *Watcher) ArmAsked(o Owner, prURL, headSHA string) (*store.CIWatch, error)
- func (w *Watcher) AttemptFinished(att *store.Attempt)
- func (w *Watcher) FixReport(ctx context.Context, ex executor.Executor, prURL, branch string, ...) (report, headSHA string, err error)
- func (w *Watcher) Poll(ctx context.Context, id int64)
- func (w *Watcher) Pushed(o Owner)
- func (w *Watcher) Tick(ctx context.Context)
- func (w *Watcher) Watching(prURL string) *View
Constants ¶
const ( StatePending = "pending" // checks running, or not reported yet StateFailing = "failing" // failed; a fix request was sent, waiting for a push StatePassed = "passed" StateCapped = "capped" // still failing after max_attempts fix requests StateMerged = "merged" StateClosed = "closed" StateNone = "none" // the PR never reported any checks StateError = "error" // gh cannot do the job (not signed in, not installed, …) StateStalled = "stalled" // no progress for StallAfter )
Watch states stored in ci_watches.state. pending and failing are the active ones; everything else is terminal.
const ( DefaultMinInterval = 30 * time.Second DefaultMaxInterval = 10 * time.Minute DefaultStallAfter = 24 * time.Hour DefaultNoChecksAfter = 15 * time.Minute )
Defaults for the poll schedule.
Variables ¶
var ErrAlreadyWatched = errors.New("the CI loop is already working on this pull request")
ErrAlreadyWatched is ArmAsked's answer when the loop is already working on the PR for someone else.
var ErrChecksNotFailing = errors.New("no checks are failing on this pull request")
ErrChecksNotFailing is FixReport's answer for a PR with nothing to fix.
var ErrNotEnabled = errors.New("the CI loop is not enabled for this project")
ErrNotEnabled is Arm's answer for a project that has not opted in.
Functions ¶
func FindPRURL ¶
FindPRURL pulls a PR URL out of gh output — `gh pr create` prints it on success, and names the existing one when a PR for the branch already exists.
func IsActionsLink ¶ added in v2.6.0
IsActionsLink reports whether a check link is a GitHub Actions job, the only kind JobLog can read.
func JobLog ¶ added in v2.6.0
JobLog fetches one GitHub Actions job's log for a person to read (the pull request page's check drill-down): the failed steps when there are any, else the whole job. It shares failedLog's command and repository resolution; ok is false for a check that is not an Actions job.
func TrimForAgent ¶ added in v2.6.0
TrimForAgent is the loop's own per-job trimming, for a failure report built outside the loop (a GitLab job's log in "Fix checks with agent").
func ValidPRURL ¶
ValidPRURL reports whether s looks like a pull request URL.
Types ¶
type SessionSender ¶
SessionSender delivers a message into a live session's agent. It is agent-agnostic: *sessions.Manager types it into the tmux pane, which is how every CLI Lectern runs receives a message.
type View ¶
type View struct {
ID int64 `json:"id"`
TaskID *int64 `json:"task_id,omitempty"`
SessionID *int64 `json:"session_id,omitempty"`
PRURL string `json:"pr_url"`
State string `json:"state"`
Attempts int `json:"attempts"`
MaxAttempts int `json:"max_attempts"`
Failing []string `json:"failing"`
Detail string `json:"detail,omitempty"`
Label string `json:"label"`
Active bool `json:"active"`
UpdatedAt float64 `json:"updated_at"`
}
View is the compact form a task or session card renders.
type Watcher ¶
type Watcher struct {
DB *store.DB
Reg *executor.Registry
Bus *bus.Bus
Notifier Notifier
Sessions SessionSender
Log *slog.Logger
MinInterval, MaxInterval, StallAfter, NoChecksAfter time.Duration
// Now is the clock, replaceable in tests.
Now func() float64
// Sync polls due watches inline in Tick instead of on goroutines.
Sync bool
// contains filtered or unexported fields
}
Watcher owns every ci_watches row.
func New ¶
func New(db *store.DB, reg *executor.Registry, b *bus.Bus, n Notifier, s SessionSender, log *slog.Logger) *Watcher
New builds a Watcher with the default schedule.
func (*Watcher) Arm ¶
Arm starts watching prURL for owner. Unless force is set (a human asking for it explicitly), the owner's project must have opted in; otherwise it returns ErrNotEnabled and records nothing.
func (*Watcher) ArmAsked ¶ added in v2.6.0
ArmAsked starts watching prURL for o as though fix request 1 had already been delivered for headSHA: the loop waits for a push, then carries on. A PR the loop is already actively watching is left alone.
func (*Watcher) AttemptFinished ¶
AttemptFinished is the scheduler telling the loop that a task attempt ended. If it was a CI fix, the watch looks again now rather than after its backoff, so Lectern commits and pushes the fix straight away.
func (*Watcher) FixReport ¶ added in v2.6.0
func (w *Watcher) FixReport(ctx context.Context, ex executor.Executor, prURL, branch string, maxAttempts int) (report, headSHA string, err error)
FixReport reads the PR and its checks through the target's gh and builds fix request 1 of maxAttempts, the same report the loop itself sends.
func (*Watcher) Poll ¶
Poll is one observation of one watch: read the PR and its checks, decide, act, and schedule the next look.
func (*Watcher) Pushed ¶
Pushed is Lectern having pushed an owner's branch (the Commit → Push button): its active watches look again now, with their backoff reset.