Documentation
¶
Overview ¶
Package github implements api.Tracker over the GitHub issue thread, which is the only state the factory keeps. It also holds the comment marker codec, the ChatOps parser with its trust rule, and the PR body renderer; all three are ported from the v8 TypeScript runner and keep its wire formats.
Index ¶
- Constants
- Variables
- func AllowedBot(actor, list string) bool
- func BotLogin(login string) string
- func CheckActor(ctx context.Context, kindOf KindOf, actor, allowedBots string) (bool, error)
- func Epic(t *Tracker) plancmd.EpicFunc
- func IssueRef(n int) string
- func OwnsLabel(name string) bool
- func PlanApproval(ctx context.Context, tr *Trust, cs []Comment) int64
- func Redact(s string) string
- func RenderPRBody(body string, p PRParts) string
- func RenderWhatChanged(goal string, files []string, proof *Proof) string
- func SameLogin(a, b string) bool
- func Unsigned(body string) string
- type Command
- type CommandKind
- type Comment
- type Config
- type Event
- type EventKind
- type KindOf
- type PRParts
- type Proof
- type Role
- type Tracker
- func (t *Tracker) Ack(ctx context.Context, id api.TicketID, ref int64) error
- func (t *Tracker) Active(ctx context.Context) ([]api.Ticket, error)
- func (t *Tracker) Commands(ctx context.Context, id api.TicketID) ([]observe.Command, error)
- func (t *Tracker) Comment(ctx context.Context, id api.TicketID, body string) (err error)
- func (t *Tracker) Comments(ctx context.Context, id api.TicketID) ([]string, error)
- func (t *Tracker) Create(ctx context.Context, tk api.Ticket) (out api.TicketID, err error)
- func (t *Tracker) Find(ctx context.Context, title string) (api.TicketID, bool, error)
- func (t *Tracker) Get(ctx context.Context, id api.TicketID) (api.Ticket, error)
- func (t *Tracker) InPhase(ctx context.Context, p api.Phase) ([]api.TicketID, error)
- func (t *Tracker) LoadPosition(ctx context.Context, id api.TicketID) (observe.Position, bool, error)
- func (t *Tracker) Name() string
- func (t *Tracker) OpenPR(ctx context.Context, id api.TicketID, branch, base string, files []string) (num int, err error)
- func (t *Tracker) Parked(ctx context.Context) ([]api.Ticket, error)
- func (t *Tracker) PutSpendComment(ctx context.Context, id api.TicketID, body string) (err error)
- func (t *Tracker) Ready(ctx context.Context) ([]api.Ticket, error)
- func (t *Tracker) RecordStatus(ctx context.Context, id api.TicketID, p api.Phase) (err error)
- func (t *Tracker) SavePosition(ctx context.Context, id api.TicketID, p observe.Position) (err error)
- func (t *Tracker) SetPhase(ctx context.Context, id api.TicketID, p api.Phase) (err error)
- func (t *Tracker) SpendComment(ctx context.Context, id api.TicketID) (string, error)
- func (t *Tracker) Thread(ctx context.Context, id api.TicketID) (store.Thread, error)
- type TriggerConfig
- type Trust
Constants ¶
const ( LabelReady = "factory:ready" LabelBlocked = "factory:blocked" LabelOverlap = "factory:overlap" LabelTriaging = "factory:triaging" LabelPlanning = "factory:planning" LabelAwaitingApproval = "factory:awaiting-approval" LabelBuilding = "factory:building" LabelVerifying = "factory:verifying" LabelInReview = "factory:in-review" LabelNeedsInfo = "factory:needs-info" LabelNeedsHuman = "factory:needs-human" LabelFailed = "factory:failed" LabelMonitor = "factory:monitor" LabelLedger = "factory:ledger" )
Label names, ported from src/labels.ts. They are the only place a factory label is spelled.
const RequestMarker = "request"
RequestMarker names the hidden marker whose payload is a hash of the whole request a ticket was filed from.
const RoleCacheTTL = 5 * time.Minute
RoleCacheTTL is how long a login's role is remembered, so a waiting issue does not cost an API call per poll.
Variables ¶
var ErrNoSuchUser = errors.New("github tracker: no such user")
ErrNoSuchUser is what a KindOf lookup returns for an actor GitHub cannot resolve, such as an App without a backing user account.
Functions ¶
func AllowedBot ¶
AllowedBot reports whether actor is on the comma-separated allow list, or the list is "*".
func BotLogin ¶
BotLogin returns login lower-cased with the "[bot]" suffix REST uses, which GraphQL leaves off.
func CheckActor ¶
CheckActor reports whether actor is a human, or a bot on the allow list. The allow list never applies to a User account. A failed lookup is an error and refuses the actor.
func Epic ¶
Epic returns how `factory plan --epic n` reads epic issue n: its body. A missing issue is a "not found" error that names the epic.
func PlanApproval ¶
PlanApproval returns the id of the comment that approves the latest plan in the thread, or 0. Approval is a trusted `/factory approve` comment posted after that plan and not yet handled, and no later revise or cancel has voided it. The task text, an earlier comment, a plain-text "ok" or a UI toggle never count, so act cannot start in the turn that wrote the plan.
func RenderPRBody ¶
RenderPRBody assembles the PR body: What changed, the pr stage's text, Acceptance, the closing line and the pointer to the run-details comment. It carries no footer, and Redact runs over the result so no model name, token count, cost or claude.ai link reaches the PR (#210).
func RenderWhatChanged ¶
RenderWhatChanged builds the body's opening section from the goal, the diff and the proof (src/engine/pr-body.ts).
Types ¶
type Command ¶
type Command struct {
Kind CommandKind
Text string
Force bool
Step string
}
Command is a parsed comment. Text is revise feedback or an answer; Force and Step belong to retry.
func ParseChatOps ¶
ParseChatOps turns a comment body into a command: a `/factory <verb>` line, or else a plain-text answer. It does no trust check; use Trust.Command for that.
type CommandKind ¶
type CommandKind string
CommandKind names what a comment asks for.
const ( CmdApprove CommandKind = "approve" CmdRevise CommandKind = "revise" CmdRetry CommandKind = "retry" CmdCancel CommandKind = "cancel" CmdAnswer CommandKind = "answer" )
The ChatOps verbs, plus a plain-text answer to the latest open question.
type Comment ¶
type Comment struct {
ID int64
Author string
// Actor is who last created or edited the comment when that is known; empty means the author.
Actor string
Body string
CreatedAt time.Time
}
Comment is one issue comment as the codec and trust rules see it.
func FindStatus ¶
FindStatus returns the latest comment that carries the status marker.
type Config ¶
type Config struct {
Owner, Repo string
// HTTPClient carries the credentials; nil uses http.DefaultClient.
HTTPClient *http.Client
// BaseURL overrides the API root (GitHub Enterprise, or a test server). Empty means api.github.com.
BaseURL string
// Now is the clock for status times and the role cache; nil uses time.Now.
Now func() time.Time
// AllowedBots is a comma-separated list of bot logins whose comments count, or "*". Empty trusts humans only.
AllowedBots string
}
Config says which repository to track and how to reach GitHub. Auth lives in HTTPClient (an injected transport), never in this package.
type Event ¶
Event is the part of a GitHub event the trigger rules read. Actor is who caused it; Author wrote the comment or review; Label and Assignee are those the event names.
func (Event) Fires ¶
func (e Event) Fires(cfg TriggerConfig) bool
Fires reports whether e may start a run. Deleting or editing someone else's comment or review fires an event with the moderator as actor, so the text must come from the actor; a label or an assignment fires only when it is the configured one.
type PRParts ¶
type PRParts struct {
WhatChanged string
Acceptance string
Closes string
// RunDetails names the issue holding the run-details comment (see IssueRef).
RunDetails string
}
PRParts is what the PR body is built from beyond the pr stage's own text. Each piece is already rendered.
type Role ¶
type Role string
Role is a login's permission on the repository.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker is the GitHub issue thread as an api.Tracker.
func (*Tracker) Active ¶
Active lists open issues labeled factory:building or factory:verifying, oldest first, in one paged query (the issues API cannot OR labels, so the label test is made here). Ready, in-review and parked issues are not active. Pull requests are skipped.
func (*Tracker) Commands ¶
Commands returns the retry, cancel, approve and revise commands trusted humans wrote that the loop has not yet acknowledged, oldest first. A comment from anyone else, or one that only looks like a command inside a marker, is ignored.
func (*Tracker) Comment ¶
Comment posts body on the issue thread through sanitize.Publication (which drops every `<!--`), unless ctx came from marker.Allow: the caller then built body itself and its markers go out as written.
func (*Tracker) Comments ¶
Comments returns the bodies of the issue's comments, oldest first. A comment carrying a queue marker is kept only when the tracker's own login wrote it: the merge queue merges the PR a marker names, so a marker anyone else posts (naming a fork PR, say) must never reach it.
func (*Tracker) Create ¶
Create files t as an open issue and returns its number. The body is posted as given, so a planned body v1 (with its Files and Blocked by lines) reaches GitHub byte for byte. With no labels the issue gets factory:ready. A title already filed, found by search or created by this Tracker, returns the first id and posts nothing. A body carrying a request marker is matched on title and marker together, so two requests with the same first line stay two issues.
func (*Tracker) Find ¶
Find searches the repository's open issues for one with exactly this title. The search API matches loosely, so each hit is compared exactly and pull requests are ignored.
func (*Tracker) InPhase ¶
InPhase lists the open issues that show phase p, in the order they entered it: by when the phase label was added, read from the issue timeline. Phases that share a label are told apart only for queued, where the issue must also carry a queue marker comment and its first marker's time is the entry time (done and queued tickets share factory:in-review). Pull requests are skipped.
func (*Tracker) LoadPosition ¶
func (t *Tracker) LoadPosition(ctx context.Context, id api.TicketID) (observe.Position, bool, error)
LoadPosition reads the position the runner last wrote on the issue.
func (*Tracker) OpenPR ¶
func (t *Tracker) OpenPR(ctx context.Context, id api.TicketID, branch, base string, files []string) (num int, err error)
OpenPR opens the draft pull request for a finished branch, its body rendered from the plan, the verdict and the pr stage's text in the thread. It returns 0 without opening when the branch has had a pull request, open or closed.
func (*Tracker) Parked ¶
Parked lists the open issues that carry the factory:needs-human label, oldest first.
func (*Tracker) PutSpendComment ¶
PutSpendComment edits the issue's spend ledger comment in place, or posts it the first time.
func (*Tracker) Ready ¶
Ready lists the open issues that carry the factory:ready label, oldest first. Pull requests are skipped.
func (*Tracker) RecordStatus ¶
RecordStatus writes the phase into the status comment, creating it on first use. Running sets the first dispatch time once; Merged sets the merge time; other phases only update the phase.
func (*Tracker) SavePosition ¶
func (t *Tracker) SavePosition(ctx context.Context, id api.TicketID, p observe.Position) (err error)
SavePosition writes the workflow position into one comment, edited in place, posted the first time.
func (*Tracker) SetPhase ¶
SetPhase swaps the issue's lifecycle label for the one that shows phase. It removes only labels the factory owns (see OwnsLabel) and leaves type, provenance and human labels alone.
func (*Tracker) SpendComment ¶
SpendComment returns the body of the spend ledger comment on the issue, or "" when none exists.
type TriggerConfig ¶
type TriggerConfig struct{ Label, Assignee string }
TriggerConfig names the label and assignee that start a run. An empty one never matches.
type Trust ¶
type Trust struct {
// contains filtered or unexported fields
}
Trust decides whose comments count. One rule for labels and commands: the runner's own login, or write access or higher. An author association alone is not enough, since a read-only collaborator is a COLLABORATOR too.
func NewTrust ¶
func NewTrust(self string, roleOf func(ctx context.Context, login string) (Role, error), now func() time.Time) *Trust
NewTrust builds a Trust for the runner login self. roleOf looks a login up on the repository; a failed lookup trusts nobody.
func (*Trust) Command ¶
Command parses c when a trusted author wrote it and it is not one of the runner's own marker comments. Anyone else's words are ignored (ok is false), so a read-only collaborator's text never becomes a command or an answer.
func (*Trust) Trusted ¶
Trusted reports whether login is the runner or has write access or higher, and, once WithActors is set, a human or an allow-listed bot.
func (*Trust) TrustedOnly ¶
TrustedOnly keeps the comments the runner or a writer wrote, whatever their bodies say.