Documentation
¶
Overview ¶
Package forge is the factory's view of GitHub, through the factory's own App (C6): one repository per instance (OD-6). GitHub is the adapter, forgetest holds the test double for the packages that consume it; each consumer declares the interface it needs (AGENTS.md) — Merger is the one exception the owner ruled (2026-09-27; R16), because its key must reach only the factory, and a seam defined here keeps it out of every consumer's hands. Logins are REST-shaped: a bot is always "name[bot]", from REST or from GraphQL.
Index ¶
- Constants
- Variables
- func BaseLines(patch string) ([]int, error)
- func MergerPermissions(rerun, label, status bool) map[string]string
- func SameLogin(a, b string) bool
- type Absent
- func (Absent) AddLabels(context.Context, int, ...string) error
- func (Absent) BlameAtParent(context.Context, string, string) ([]BlameRange, error)
- func (Absent) ChangedFiles(context.Context, string, string) ([]string, error)
- func (Absent) CheckAnnotations(context.Context, int64) ([]Annotation, error)
- func (Absent) CommitChecks(context.Context, string) ([]Check, error)
- func (Absent) Diff(context.Context, string, string) (Diff, error)
- func (Absent) DisableAutoMerge(context.Context, string) error
- func (Absent) EnableAutoMerge(context.Context, string, string) error
- func (Absent) FileAt(context.Context, string, string) (string, error)
- func (Absent) IsAncestor(context.Context, string, string) (bool, error)
- func (Absent) Merge(context.Context, string, string) error
- func (Absent) MergedSince(context.Context, time.Time) ([]MergedPull, error)
- func (Absent) PullFiles(context.Context, int) ([]FilePatch, error)
- func (Absent) PullRequestChecks(context.Context, int) (Checks, error)
- func (Absent) PullsWithLabel(context.Context, string) ([]LabelledPull, error)
- func (Absent) RerunCheck(context.Context, int64) error
- func (Absent) RevertPR(context.Context, RevertOf) (Revert, error)
- func (Absent) RunArtifact(context.Context, int64, string, string) ([]byte, error)
- func (Absent) SetStatus(context.Context, string, string, string, string) error
- func (Absent) WorkflowRuns(context.Context, string) ([]WorkflowRun, error)
- type AgentPull
- type Annotation
- type BlameRange
- type Check
- type Checks
- type Comment
- type Commit
- type Diff
- type FileContent
- type FilePatch
- type FileStat
- type GitHub
- func (g *GitHub) AddLabels(ctx context.Context, number int, labels ...string) error
- func (g *GitHub) AddSubIssue(ctx context.Context, parent int, childID int64) error
- func (g *GitHub) AgentPulls(ctx context.Context) ([]AgentPull, error)
- func (g *GitHub) AllComments(ctx context.Context, number int) ([]Comment, error)
- func (g *GitHub) AnyMerged(ctx context.Context, filter string) (bool, error)
- func (g *GitHub) BlameAtParent(ctx context.Context, mergeSHA, path string) ([]BlameRange, error)
- func (g *GitHub) BranchActivity(ctx context.Context, branch string) ([]Push, error)
- func (g *GitHub) ChangedFiles(ctx context.Context, base, head string) ([]string, error)
- func (g *GitHub) CheckAnnotations(ctx context.Context, id int64) ([]Annotation, error)
- func (g *GitHub) Checked() bool
- func (g *GitHub) CloseIssue(ctx context.Context, number int) error
- func (g *GitHub) ClosePR(ctx context.Context, number int) error
- func (g *GitHub) Comment(ctx context.Context, number int, body string) error
- func (g *GitHub) CommentWithID(ctx context.Context, number int, body string) (int64, error)
- func (g *GitHub) Commit(ctx context.Context, sha string) (Commit, error)
- func (g *GitHub) CommitChecks(ctx context.Context, sha string) ([]Check, error)
- func (g *GitHub) CreateIssue(ctx context.Context, title, body string, labels []string) (Issue, error)
- func (g *GitHub) DefaultBranchFile(ctx context.Context, path string) (text, sha string, found bool, err error)
- func (g *GitHub) Diff(ctx context.Context, base, head string) (Diff, error)
- func (g *GitHub) DisableAutoMerge(ctx context.Context, nodeID string) error
- func (g *GitHub) EditComment(ctx context.Context, id int64, body string) error
- func (g *GitHub) EnableAutoMerge(ctx context.Context, nodeID, expectedHeadSHA string) error
- func (g *GitHub) FenceFile(ctx context.Context) ([]byte, bool, error)
- func (g *GitHub) FileAt(ctx context.Context, path, ref string) (string, error)
- func (g *GitHub) FileAtCommit(ctx context.Context, sha, path string) (FileContent, bool, error)
- func (g *GitHub) Healthy(now time.Time) bool
- func (g *GitHub) IsAncestor(ctx context.Context, ancestor, sha string) (bool, error)
- func (g *GitHub) Issue(ctx context.Context, number int) (Issue, error)
- func (g *GitHub) IssuesLabelled(ctx context.Context, label string) ([]Issue, error)
- func (g *GitHub) IssuesLabelledSince(ctx context.Context, label string, since time.Time) ([]Issue, error)
- func (g *GitHub) LabelEvents(ctx context.Context, number int, label string) ([]LabelEvent, error)
- func (g *GitHub) Labeled(ctx context.Context, label string) ([]Item, error)
- func (g *GitHub) Merge(ctx context.Context, nodeID, head string) error
- func (g *GitHub) MergedRecords(ctx context.Context, filter string) ([]evidence.PR, error)
- func (g *GitHub) MergedSince(ctx context.Context, since time.Time) ([]MergedPull, error)
- func (g *GitHub) OpenPullRequests(ctx context.Context) ([]PRSummary, error)
- func (g *GitHub) Permission(ctx context.Context, login string) (string, error)
- func (g *GitHub) Ping(ctx context.Context) error
- func (g *GitHub) Public(ctx context.Context) (bool, error)
- func (g *GitHub) PullFiles(ctx context.Context, number int) ([]FilePatch, error)
- func (g *GitHub) PullRequest(ctx context.Context, number int) (PR, error)
- func (g *GitHub) PullRequestChecks(ctx context.Context, number int) (Checks, error)
- func (g *GitHub) PullRequestCommits(ctx context.Context, number int) ([]Commit, error)
- func (g *GitHub) PullRequestForBranch(ctx context.Context, branch string) (int, error)
- func (g *GitHub) PullsWithLabel(ctx context.Context, label string) ([]LabelledPull, error)
- func (g *GitHub) RecentComments(ctx context.Context, number int) ([]Comment, error)
- func (g *GitHub) RemoveLabel(ctx context.Context, number int, label string) error
- func (g *GitHub) RenderMarkdown(ctx context.Context, text string) (string, error)
- func (g *GitHub) Repository() string
- func (g *GitHub) RepositoryInfo(ctx context.Context) (RepositoryInfo, error)
- func (g *GitHub) RerunCheck(ctx context.Context, id int64) error
- func (g *GitHub) RevertPR(ctx context.Context, of RevertOf) (Revert, error)
- func (g *GitHub) RevertRecords(ctx context.Context) ([]evidence.Revert, error)
- func (g *GitHub) RunArtifact(ctx context.Context, runID int64, name, file string) ([]byte, error)
- func (g *GitHub) SetStatus(ctx context.Context, sha, state, statusContext, description string) error
- func (g *GitHub) UserLogin(ctx context.Context, id int64) (string, error)
- func (g *GitHub) WorkflowRuns(ctx context.Context, workflow string) ([]WorkflowRun, error)
- type Issue
- type Item
- type LabelEvent
- type LabelledPull
- type MergedPull
- type Merger
- type MintOptions
- type Options
- type PR
- type PRSummary
- type PermanentError
- type Push
- type RepositoryInfo
- type Revert
- type RevertOf
- type Review
- type ReviewComment
- type Status
- type Token
- type WorkflowRun
Constants ¶
const ActionsApp int64 = 15368
ActionsApp is GitHub Actions' App id on github.com, the one classic protection pins required checks to (15368).
const CheckListTruncated = "maku: check listing truncated"
CheckListTruncated names the marker check CommitChecks appends, State "PENDING", when the listing reached maxCheckPages: checks past the cap were never read, so the commit cannot read green through MainState whatever names it watches.
Variables ¶
var ( ErrHeadMoved = errors.New("forge: the pull request's head moved since the decision") ErrNotMergeable = errors.New("forge: GitHub does not allow the merge as it stands") )
ErrHeadMoved and ErrNotMergeable are GitHub's refusals of a merge at merge time (ruling R52): expectedHeadOid is no longer the head — a push landed after the decision (HTTP 409) — or the pull request cannot be merged as it stands: protections, an approval it lacks (HTTP 405). Both are decisions the factory can make, so they are typed; anything else is a plain error.
var ErrActivityTruncated = errors.New("forge: a branch's activity past the page cap is unread")
ErrActivityTruncated is BranchActivity reaching its page cap before the branch's creation: the pushes before what was read are unknown.
var ErrCommitsTruncated = errors.New("forge: a pull request's commits past GitHub's 250 are unread")
ErrCommitsTruncated is PullRequestCommits reaching GitHub's 250-commit cap: commits past it are never listed, so the list read is not known to be the whole pull request.
var ErrDiffTooLarge = errors.New("forge: a diff past what one compare lists, the rest unread")
ErrDiffTooLarge is a compare listing as many files as GitHub lists (maxChangedFiles, 300), or more commits than one page: the files past it are unseen, so the diff cannot be judged. The merge path hands such a pull request to a human (patch_too_large).
var ErrEventsTruncated = errors.New("forge: label events past the page cap are unread")
ErrEventsTruncated is LabelEvents reaching its page cap: the newest events are unread.
var ErrMergedTruncated = errors.New("forge: a window of 100 merged pull requests, the rest unread")
ErrMergedTruncated is MergedSince filling its window of 100: pull requests past it are unread, so the caller narrows since and reads again.
var ErrNoBlame = errors.New("forge: nothing to blame at the parent for the path")
ErrNoBlame is BlameAtParent finding nothing to blame: the path is not in the parent, or GitHub returned no blame for it. It is not "no overlap": the caller treats it as inconclusive.
var ErrNoMerger = errors.New("forge: the merger App is not configured (github.mergerAppIDFile): nothing can read checks or merge")
ErrNoMerger is what every call on Absent answers: the merger App's key is not mounted.
var ErrNoPatch = errors.New("forge: GitHub omitted the file's patch, the lines it changed are unknown")
ErrNoPatch is the base lines of a file whose patch GitHub omitted (a large or binary diff): which lines changed is unknown, never "none".
var ErrNotAFile = errors.New("forge: the path is not a readable file")
ErrNotAFile is DefaultBranchFile or FileAtCommit at a path that is never a readable file: a directory, a file over the contents API's 1 MB, a symlink or a submodule. It does not heal by retrying.
var ErrNotDescendant = errors.New("forge: the head is not a descendant of the base")
ErrNotDescendant is ChangedFiles on a head that GitHub does not call ahead of the base (behind, diverged, identical): the compare's file list says nothing about what changed since the base.
var ErrRecordsTruncated = errors.New("forge: more pull request records than the evidence reads")
ErrRecordsTruncated is a promotion-evidence read past its bound: records past it are unread, so the evidence would be short and is refused instead (stage 6).
Functions ¶
func BaseLines ¶
BaseLines are the base-side line numbers a unified patch removes or rewrites: the lines of the file as it was that the pull request changed (merge gate R35). A pure addition changes none. The result is sorted and deduplicated, nil when there is none. A hunk header that does not parse is an error: dropping the hunk would read as "no change".
func MergerPermissions ¶
MergerPermissions is the merger App's installation-token scope (TW4, R16): the merge-side calls read checks and statuses, write contents on the merger's own revert branches, and arm and merge pull requests — and nothing else. Like the factory's, it is the App's ceiling: a mint asking for more fails. rerun adds actions: write for RerunCheck: it is asked only when merge.checkReruns is on, so an App that was not granted it keeps minting. label adds issues: write for the breaker's labels (v2 D1) and the monitor's outcome labels (merge gate R30), written once a class is live or declares a monitor: an App with neither keeps minting without it, and still reads them (pull_requests covers the read). status raises statuses to write for the gate's own commit status, asked only when merge.gateStatus is on.
Types ¶
type Absent ¶
type Absent struct{}
Absent is the Merger of a factory started without the merger App's key, allowed only while no class is live or in shadow (config.NeedsMerger). It fails closed: a task that reaches the merge gate errors and retries, and no other identity reads checks or merges in its place.
func (Absent) BlameAtParent ¶
BlameAtParent implements the Merger's BlameAtParent and fails closed.
func (Absent) ChangedFiles ¶
ChangedFiles implements the Merger's ChangedFiles and fails closed.
func (Absent) CheckAnnotations ¶ added in v0.36.0
CheckAnnotations implements the Merger's CheckAnnotations and fails closed: a brief says it could not read the failing check, rather than quoting nothing as if the check had said nothing.
func (Absent) CommitChecks ¶
CommitChecks implements the Merger's CommitChecks and fails closed.
func (Absent) DisableAutoMerge ¶
DisableAutoMerge implements the Merger's DisableAutoMerge and fails closed.
func (Absent) EnableAutoMerge ¶
EnableAutoMerge implements the Merger's EnableAutoMerge and fails closed.
func (Absent) IsAncestor ¶
IsAncestor implements the Merger's IsAncestor and fails closed.
func (Absent) MergedSince ¶
MergedSince implements the Merger's MergedSince and fails closed.
func (Absent) PullRequestChecks ¶
PullRequestChecks implements the Merger's PullRequestChecks and fails closed.
func (Absent) PullsWithLabel ¶
PullsWithLabel implements the Merger's PullsWithLabel and fails closed.
func (Absent) RerunCheck ¶
RerunCheck implements Merger.
func (Absent) RunArtifact ¶
RunArtifact implements the Merger's RunArtifact and fails closed.
func (Absent) SetStatus ¶ added in v0.35.0
SetStatus implements the Merger's SetStatus and fails closed.
func (Absent) WorkflowRuns ¶
WorkflowRuns implements the Merger's WorkflowRuns and fails closed.
type AgentPull ¶
AgentPull is one open pull request from an `agent/` branch, as the orphan scan reads it (R51): the head branch, its labels, and whether that branch is this repository's own — a fork's never is, so its pull requests are never the factory's to judge.
type Annotation ¶ added in v0.36.0
Annotation is one line a check run annotated on a commit: GitHub's path and start line, its level (failure, warning, notice) and what it said.
The message is the check's own text, and a check may write anything a workflow or a pull request's author makes it write, so it is untrusted: a revision brief quotes it as data, bounded by the read and made inert where it is rendered (CD12). StartLine is 0 when GitHub named none.
type BlameRange ¶
BlameRange is a run of lines, Start to End inclusive, last changed by Commit.
type Check ¶
type Check struct {
ID int64 // the check run's database id, which is its Actions job id
Name string
State string // SUCCESS | FAILURE | CANCELLED | PENDING
// App is the database id of the GitHub App whose check suite holds the run: GitHub Actions
// is ActionsApp. 0 when GitHub did not say, and always 0 on the checks CommitChecks reads (main's
// CI), which carry no App.
App int64
// Conclusion is the check run's raw conclusion (SUCCESS, NEUTRAL, SKIPPED, FAILURE…), "" while
// it runs. State folds NEUTRAL and SKIPPED into SUCCESS, as classic protection does; a gate
// that needs the job to have run reads this.
Conclusion string
}
Check is one CI check run on a commit: SUCCESS, FAILURE, CANCELLED or PENDING. CANCELLED is apart from FAILURE because nothing failed: the runner or a concurrency group stopped the job.
type Checks ¶
type Checks struct {
Runs []Check
Statuses []Status
// Truncated: the rollup has more contexts than the one page read, so a check may be unseen.
Truncated bool
}
Checks is a head commit's rollup: check runs (CI) and commit statuses (policy-bot).
func (Checks) DescriptionOf ¶ added in v0.35.0
DescriptionOf is the description of the named commit status; "" when it is absent.
type Comment ¶
Comment is an issue or pull request comment. Edited: its body changed after it was posted, perhaps by someone other than its author, so a command in it is never acted on.
type Commit ¶
type Commit struct {
SHA string
Author string // the login GitHub matched the author's email to, "" when none: never proof
Message string
// Parents and Stats are read only by Commit (one commit by sha): its parents' shas and the files
// it changes against them, each with its status (added, modified, removed, renamed...). FilesTruncated is a full page of files.
Parents []string
Stats []FileStat
FilesTruncated bool
}
Commit is one commit of a pull request, as GitHub lists them.
type Diff ¶
Diff is what a squash merge of head applies (R52): each changed file's content at the merge base and at head, "" where it is absent, and GitHub's own list of the changed files.
type FileContent ¶ added in v0.39.0
FileContent is one file as the contents API served it at a ref: its path, git blob sha, bytes and the size GitHub declared (v4 MR7). A caller that needs proof recomputes the digests.
type FilePatch ¶
type FilePatch struct {
Path string
Previous string
Status string
Patch string
// PatchMissing: GitHub omitted the patch although the file changed (a large or binary diff),
// so BaseLines is unknown.
PatchMissing bool
}
FilePatch is one file a pull request changed: its path, its previous path on a rename, GitHub's status for it and its unified patch ("" for a binary, a rename alone or a patch GitHub omits).
type FileStat ¶
FileStat is one changed file as GitHub's compare lists it: its status (added, removed, modified, renamed, copied, changed, unchanged), its previous name on a rename, and its line counts, which policy-bot's modified_lines sums.
type GitHub ¶
type GitHub struct {
// contains filtered or unexported fields
}
GitHub is the forge on one repository, as one App installation.
func Connect ¶
Connect authenticates as the App, finds its installation on the repository and mints the first installation token, so a key GitHub refuses or an App not installed fails startup. Every later call goes through o.HTTP, as that installation. It refuses anything but an https API URL.
func (*GitHub) AddSubIssue ¶
AddSubIssue shows child under parent as a GitHub sub-issue, by the child's numeric id: a view for people (splitter SL8); the labels are the record.
func (*GitHub) AgentPulls ¶
AgentPulls are the repository's open pull requests from `agent/` branches (R51's orphan scan), newest first, one page of 100: the head branch, its labels, and whether the head is this repository's own branch. GitHub's pullRequests connection does not accept headRefPrefix (it is a search argument; verified against the live API 2026-10-04), so the newest 100 open PRs of ANY prefix are fetched and filtered client-side to `agent/` heads. Tradeoff: an `agent/` PR pushed out of the newest-100 window by 100+ newer non-agent PRs is missed for that poll; the window slides every poll and labelling shrinks the set, so any backlog is walked, and this repository's volume makes the miss theoretical. The scan judges the rest.
func (*GitHub) AllComments ¶ added in v0.41.1
AllComments are every comment on an issue or pull request, newest first, with no recent-items cap.
func (*GitHub) AnyMerged ¶ added in v0.40.0
AnyMerged is whether a merged pull request matches filter: one follow-up search of the script.
func (*GitHub) BlameAtParent ¶
BlameAtParent is who last changed each line of path as the first parent of mergeSHA had it: the file as the merged pull request found it (a squash merge's parent is the base; see Merger). A file the parent does not have, or a null blame, is ErrNoBlame; a commit without a parent, or any other failure, is an error too.
func (*GitHub) BranchActivity ¶
BranchActivity is the branch's activity newest first, back to its latest creation and no further: what precedes it is an earlier branch of the same name. GitHub's repository activity API (contents: read) pages by cursor; a history whose creation is not reached within maxActivityPages returns ErrActivityTruncated.
func (*GitHub) ChangedFiles ¶
ChangedFiles lists the paths changed from base to head, never their contents (row 2c reads only the names). GitHub's compare is three-dot, so it names what changed since the merge base: only a head ahead of base makes that "since base". Behind or diverged (a rebase) is ErrNotDescendant.
func (*GitHub) CheckAnnotations ¶ added in v0.36.0
CheckAnnotations is what a check run annotated, in GitHub's order, at most maxAnnotations of them: the evidence of a failure that a revision brief quotes (CD12).
It is evidence, never a gate, so the read is bounded rather than fail-closed: one page, and each message cut to maxAnnotationMessage runes on a rune boundary, marked with "…" so half a sentence never reads as the whole of what the check said. Annotations past the page and messages past the cut are unread, and the caller says the factory could not read a check rather than claiming it said nothing. The text itself stays as GitHub wrote it: making it inert is the renderer's one job (roomview, reconciler text), not this read's.
The endpoint answers a bare array (GitHub's OpenAPI response for this operation), which is what go-github's Checks.ListCheckRunAnnotations decodes, so the typed call is the whole read.
func (*GitHub) Checked ¶ added in v0.41.0
Checked is whether any call was made yet: before the first, Healthy's false says nothing about GitHub.
func (*GitHub) CloseIssue ¶
CloseIssue closes an issue as completed (splitter SL12: a parent whose parts all merged).
func (*GitHub) CommentWithID ¶ added in v0.41.1
CommentWithID posts body on an issue or pull request and returns the created comment's stable id.
func (*GitHub) Commit ¶
Commit is one commit by sha, with its message: the tester's contract commit (R14).
func (*GitHub) CommitChecks ¶
CommitChecks are the check runs on one commit: main's CI after a merge, where no pull request carries the verdict anymore. Every page is read, up to maxCheckPages (D3). A listing still going at the cap returns each run it read that is not FAILURE as PENDING, plus the CheckListTruncated marker: the commit reads as still running, never green, while a failure read stays a failure.
func (*GitHub) CreateIssue ¶
func (g *GitHub) CreateIssue(ctx context.Context, title, body string, labels []string) (Issue, error)
CreateIssue opens an issue with these labels and returns it, with its number and the numeric id the sub-issues API takes (FA-8: the RunLore intake proposes one per finding; splitter SL8: a split opens its parts). issues:write is in the factory App's scope already.
func (*GitHub) DefaultBranchFile ¶
func (g *GitHub) DefaultBranchFile(ctx context.Context, path string) (text, sha string, found bool, err error)
DefaultBranchFile is path on the default branch, its text and git blob sha; found is false on GitHub's 404. A path that is never a readable file (a directory, over 1 MB, a symlink, a submodule) is ErrNotAFile, with the sha when GitHub gave one. Any other failure (5xx, 403, network) is a retryable error: triage retries rather than read "no note" (SC4).
func (*GitHub) Diff ¶
Diff is the contents of every file head changes since it forked from base, read at their merge base and at head — what a squash merge applies, not head against base's tip: an added file's base side and a deleted file's head side read "", so the maps' union is the changed set. A rename reads as its delete beside its add — which is right: a rename is not a link retarget. §5.1's links-only test for the docs classes (R52) decides on these.
func (*GitHub) DisableAutoMerge ¶
DisableAutoMerge disarms a revert that never went green (§6.4): the stalled revert is handed to a maintainer rather than left armed indefinitely. The decision path never arms, so it never disarms (R52).
func (*GitHub) EditComment ¶ added in v0.41.1
EditComment replaces the body of the issue or pull request comment with id.
func (*GitHub) EnableAutoMerge ¶
EnableAutoMerge arms GitHub's native auto-merge — for the revert PR alone (R52): it waits for every required check and merges even with the factory down, which for a revert of red main (§6.4) is the safety net, not the fail-open the decision path must not be. The revert branch is the merger App's own, so no later push can move the head it merges.
func (*GitHub) FenceFile ¶
FenceFile is the ownership fence (v2 D7) on the default branch, found false when the repository has none. Any failure other than GitHub's 404 is an error: the caller keeps its last answer.
func (*GitHub) FileAt ¶
FileAt is path's content at ref, "" when absent there: the dead-links probe reads a finding's file on main.
func (*GitHub) FileAtCommit ¶ added in v0.39.0
FileAtCommit is path at commit sha exactly (v4 MR7): the contents API's semantics as DefaultBranchFile's, ErrNotAFile included, but at a 40-hex commit only, so neither a branch name nor a short sha can stand in for a landed merge commit.
func (*GitHub) Healthy ¶
Healthy backs /readyz ("App token fresh", §6.5): a call succeeded in the freshFor before now.
func (*GitHub) IsAncestor ¶
IsAncestor reports whether ancestor is sha or one of its ancestors: GitHub's compare of ancestor...sha is "ahead" when sha descends from it and "identical" when they are one commit. One file per page, since only the status is read; any other status is an error.
func (*GitHub) Issue ¶
Issue is one GraphQL snapshot of an issue: text, labels, the body's last edit and the last title rename.
func (*GitHub) IssuesLabelled ¶
IssuesLabelled are the issues carrying label, open or closed: one page of 100, since a split opens at most five parts under one label. Pull requests are left out.
func (*GitHub) IssuesLabelledSince ¶
func (g *GitHub) IssuesLabelledSince(ctx context.Context, label string, since time.Time) ([]Issue, error)
IssuesLabelledSince are the issues carrying label, open or closed, updated at or after since: up to issuesSincePages pages of 100, for a label that accumulates (factory/proposed). Beyond the cap it is an error, as IssuesLabelled's second page is. Pull requests are left out.
func (*GitHub) LabelEvents ¶
LabelEvents are the times label was added to an issue, oldest first; at most ten pages of 100. Past them it returns what it read and ErrEventsTruncated: GitHub lists events oldest first, so the unread ones are the newest.
func (*GitHub) Labeled ¶
Labeled lists the issues and pull requests carrying label: one page of 100, since the factory removes the trigger label on every decision (R4).
func (*GitHub) Merge ¶
Merge merges the pull request now, at the decided head (external review R02, ruling R52): mergePullRequest with expectedHeadOid checks the head at merge time, so a push that lands after the decision refuses the merge instead of merging on the old decision — which is what enablePullRequestAutoMerge's enable-time-only check failed to guarantee. GitHub answers a moved head or a disallowed merge with 409 or 405, or with 200 and an errors[] message (F-1, testdata/merge-*.json); the sentinels are what the reconciler decides on. squash always: the factory's one commit per task is the history.
func (*GitHub) MergedRecords ¶ added in v0.40.0
MergedRecords are the merged pull requests matching filter (search qualifiers the caller builds from config, never from a request), in the shape shadow-merge-tally.sh reads from gh.
func (*GitHub) MergedSince ¶
MergedSince lists the pull requests merged at or after since, in the order GitHub's search gives (it has no sort). A full window of 100, or a pull request with more labels than were read, returns ErrMergedTruncated: the caller narrows since and reads again. The search is eventually consistent, so a pull request merged moments ago may be missing: callers overlap their windows.
func (*GitHub) OpenPullRequests ¶
OpenPullRequests are the repository's open pull requests, one page of 100: the factory App's read of the queue (the merger reads PR state through Merger, not here).
func (*GitHub) Permission ¶
Permission is login's permission on the repository as GitHub's collaborator API states it (admin, maintain, write, triage, read or none); GitHub's 404 — a login it does not know, or one with no access — is "none" (v2 D4, D5). Any other failure is an error, never an answer.
func (*GitHub) Ping ¶
Ping runs on every replica every minute; the rate-limit endpoint costs no quota.
func (*GitHub) Public ¶ added in v0.35.0
Public reports whether the repository is public, read live from GET repos/{owner}/{repo}. A failed read, or a reply without the private flag, is an error and never "public": demo mode serves public repositories only and fails closed.
func (*GitHub) PullFiles ¶
PullFiles lists the files a pull request changed, with their patches. GitHub lists 3,000 at most, so a list that reaches it may be missing files and is an error.
func (*GitHub) PullRequest ¶
PullRequest is one GraphQL query per PR per poll (§1: "each active PR every 30 s in one GraphQL query"): state, reviews, comments and the head commit's message.
func (*GitHub) PullRequestChecks ¶
PullRequestChecks is the head commit's rollup, one GraphQL query. It needs checks: read and statuses: read (R16), hence the merger App's own method.
func (*GitHub) PullRequestCommits ¶
PullRequestCommits are the pull request's commits, oldest first: three pages of 100 at most. A list that reaches GitHub's 250 is returned with ErrCommitsTruncated — it may be all of them, or the first 250 of more, and GitHub does not say which.
func (*GitHub) PullRequestForBranch ¶
PullRequestForBranch is the newest pull request from branch in the repository, 0 when none.
func (*GitHub) PullsWithLabel ¶
PullsWithLabel lists the newest 100 pull requests carrying label, by creation, in every state. The breaker reads a window of 10 merges, so a class's 100 newest labelled ones hold it.
func (*GitHub) RecentComments ¶
RecentComments are the 50 newest comments, newest first (R22 searches them for its marker). GitHub lists an issue's comments by ascending id and ignores sort and direction there (review R1), so the newest are on the last page, and on the one before it when the last is short: one to three calls.
func (*GitHub) RemoveLabel ¶
RemoveLabel removes a label; one already gone (404) is not an error.
func (*GitHub) RenderMarkdown ¶ added in v0.33.0
RenderMarkdown is text as GitHub would show it in an issue of this repository: mode gfm, the repository as context, so mentions and references resolve as they would once filed. It writes nothing and notifies nobody. A refusal, a rate limit among them, is an error.
func (*GitHub) Repository ¶
Repository is the owner/name this connection is bound to.
func (*GitHub) RepositoryInfo ¶ added in v0.39.0
func (g *GitHub) RepositoryInfo(ctx context.Context) (RepositoryInfo, error)
RepositoryInfo reads GET repos/{owner}/{repo} through this connection. A failed read, or a reply without its full name or private flag, is an error and never an answer.
func (*GitHub) RerunCheck ¶
RerunCheck re-runs the Actions job whose id is the check run's. Re-running a job whose run is not complete is refused by GitHub (403), which the reconciler reads as a failed attempt.
func (*GitHub) RevertPR ¶
RevertPR produces the revert PR GitHub's own button would (§6.4); its revert-<n>-<head> branch is created by the merger App, which is why only that App bypasses agent-merge (R16). A revert already open on such a branch by of.By is the one a previous call opened and lost the answer of (F-11): it is returned, never doubled, since a second revert would count twice against the breaker. The list is one page of 100 open pull requests, newest first, where a revert just opened is.
func (*GitHub) RevertRecords ¶ added in v0.40.0
RevertRecords are the pull requests titled Revert, any state: the script's reverts_of.
func (*GitHub) RunArtifact ¶
RunArtifact is file inside run runID's unexpired artifact name. GitHub's API answers the download with a redirect to its storage (productionresultssa*.blob.core.windows.net); the zip is fetched there through the plain egress client, without the installation token, and read whole within maxArtifactBytes.
func (*GitHub) SetStatus ¶ added in v0.35.0
func (g *GitHub) SetStatus(ctx context.Context, sha, state, statusContext, description string) error
SetStatus posts a commit status on sha. It needs statuses: write.
func (*GitHub) UserLogin ¶
UserLogin is GitHub user id's current login. The id is stable across a rename, the login is not, so the D4 lookup resolves the id each time its cache expires.
func (*GitHub) WorkflowRuns ¶
WorkflowRuns are the newest completed runs of workflow, a file under .github/workflows, on main: one page of 20, newest first. The dead-links probe reads the newest two a schedule or a maintainer started. It needs actions: read, which the merger App holds (runbook 12).
type Issue ¶
type Issue struct {
Number int
// ID is REST's numeric id, which the sub-issues API takes (splitter SL8); 0 when read through
// GraphQL (Issue).
ID int64
URL string
Title string
Body string
State string // OPEN | CLOSED
Author string // a bot's with "[bot]", as REST writes it
Labels []string
LastEditedAt time.Time // the body's last edit; zero when never edited
// The last title rename (a RenamedTitleEvent): lastEditedAt does not cover the title,
// which is part of the snapshot (R5).
TitleEditedAt time.Time
}
Issue is the snapshot's source (§1, R5).
type LabelEvent ¶
LabelEvent is one time a label was added, and by whom (R4: only maintainers' count).
type LabelledPull ¶
type LabelledPull struct {
Number int
State string // OPEN | CLOSED | MERGED
MergedAt time.Time
Labels []string
}
LabelledPull is one pull request carrying a label, as the merge breaker's ledger reads it (v2 D1): its state, once merged when, and its labels (the first 30: a drill revert, AM6).
type MergedPull ¶
type MergedPull struct {
Number int
Author string // REST-shaped: a bot's with "[bot]"
HeadRef string
MergeCommitSHA string
Title string
MergedAt time.Time
Labels []string
// Commits is how many commits the pull request had; ParentPulls the pull requests its merge
// commit's first parent belongs to. Together they tell a rebase merge of several commits (the
// first parent is then one of its own commits, not the base) from a squash.
Commits int
ParentPulls []int
}
MergedPull is one merged pull request, as the merge monitor's follow-up scan reads it: who authored it, from which branch, the commit it became on the default branch, when, and its labels.
func (MergedPull) MultiCommitRebase ¶
func (p MergedPull) MultiCommitRebase() bool
MultiCommitRebase reports a pull request that may have been merged by rebasing more than one commit: its merge commit's first parent is a commit of the same pull request, or GitHub has not yet said which pull requests the parent belongs to (a lagging answer must not read as a squash). A single-commit rebase has the base for parent, as a squash does.
type Merger ¶
type Merger interface {
PullRequestChecks(ctx context.Context, number int) (Checks, error)
// SetStatus posts a classic commit status on sha (state: error, failure, pending or success;
// description at most 140 characters). It needs statuses: write, asked only with
// merge.gateStatus.
SetStatus(ctx context.Context, sha, state, context, description string) error
CommitChecks(ctx context.Context, sha string) ([]Check, error)
// IsAncestor reports whether ancestor is sha or one of its ancestors: the monitor asks it
// whether a later main commit carries a merge.
IsAncestor(ctx context.Context, ancestor, sha string) (bool, error)
// RerunCheck re-runs the Actions job a check run is. It needs actions: write, beyond what
// the merger App held until merge.checkReruns was turned on.
RerunCheck(ctx context.Context, id int64) error
// CheckAnnotations is what a check run annotated: the paths, lines and messages a revision
// brief quotes as the evidence of a failure (CD12). It is evidence, never a gate, so it is
// bounded — one page of annotations, and each message cut — and a caller that cannot read it
// says so rather than failing the pass.
CheckAnnotations(ctx context.Context, id int64) ([]Annotation, error)
Diff(ctx context.Context, base, head string) (Diff, error)
// ChangedFiles is the path of every file changed between base and head, without contents
// (a rename lists both names). A head not ahead of base is ErrNotDescendant; a full page of
// files is ErrDiffTooLarge (R21: fail closed).
ChangedFiles(ctx context.Context, base, head string) ([]string, error)
Merge(ctx context.Context, nodeID, head string) error
EnableAutoMerge(ctx context.Context, nodeID, expectedHeadSHA string) error
DisableAutoMerge(ctx context.Context, nodeID string) error
RevertPR(ctx context.Context, of RevertOf) (Revert, error)
// AddLabels and PullsWithLabel are the merge breaker's ledger on GitHub (v2 D1): the merger
// labels what it merged and the reverts it opened, so the breaker's state survives a rebuild
// that loses every Task, and only the merger's key writes it. It needs issues: write, GitHub's
// permission for a pull request's labels.
AddLabels(ctx context.Context, number int, labels ...string) error
PullsWithLabel(ctx context.Context, label string) ([]LabelledPull, error)
// WorkflowRuns, RunArtifact and FileAt are the dead-links probe's reads (merge gate MC5):
// the detector's runs on main, their findings, and a finding's file there.
WorkflowRuns(ctx context.Context, workflow string) ([]WorkflowRun, error)
RunArtifact(ctx context.Context, runID int64, name, file string) ([]byte, error)
FileAt(ctx context.Context, path, ref string) (string, error)
// MergedSince, PullFiles and BlameAtParent are the monitor's follow-up reads: the pull
// requests merged since a time, one pull request's patches, and who last changed a file's
// lines before a merge. All three fail closed: an incomplete answer is an error.
//
// BlameAtParent blames at mergeSHA's first parent, which is the base only for a squash merge
// (the factory's); a rebase merge's first parent is the previous rebased commit. The caller
// blames at the follow-up's own merge commit, with FilePatch.BlamePath, so a file the original
// pull request created is blamed where it exists. ErrNoBlame means nothing could be blamed.
MergedSince(ctx context.Context, since time.Time) ([]MergedPull, error)
PullFiles(ctx context.Context, number int) ([]FilePatch, error)
BlameAtParent(ctx context.Context, mergeSHA, path string) ([]BlameRange, error)
}
Merger is GitHub through the merger App (owner, 2026-09-27; R16): the only identity that reads checks, statuses and the changed files of a decision, merges on a decision and opens and arms reverts. Its key lives in the factory alone; the factory App, whose key the broker shares, never gets these powers.
Merge replaces arming auto-merge for the factory's decision (external review R02, ruling R52): GitHub checks the head at merge time here, while auto-merge's expectedHeadOid is only an enable-time check and a disarm-by-polling path fails open while the factory is down. EnableAutoMerge stays for one use — the revert PR of §6.4 — where waiting for green and merging without the factory is the point: main is red, the branch is the merger's own, and no push can move it after the arm.
type MintOptions ¶ added in v0.35.0
type MintOptions struct {
AppIDFile, KeyFile string
Owner string // the installation's account
Repositories []string // names only, no owner
Permissions map[string]string // e.g. {"contents": "write"}
}
MintOptions names the App, the repositories and the permissions of one installation token.
type Options ¶
type Options struct {
Repository string // owner/name: config.repository
AppIDFile string // config.github.appIDFile, read at each token mint
PrivateKeyFile string // config.github.privateKeyFile, read at each token mint
APIURL string // https://api.github.com/ in the cluster; a test server in tests
UserAgent string
HTTP *http.Client // httpx.New: the one audited egress client
Now func() time.Time
// Permissions is the installation token's scope (TW4). nil keeps the factory App's
// permissions(); the merger connection passes MergerPermissions(), so no factory token
// ever asks for checks:read the factory App does not hold — a mint beyond the App's
// scope fails, which would break the factory with it.
Permissions map[string]string
}
Options is how Connect reaches GitHub as the factory App.
type PR ¶
type PR struct {
Number int
NodeID string
URL string
Title string
Body string // the description: a claim by whoever wrote it
State string // OPEN | CLOSED | MERGED
Author string
HeadRef string
HeadSHA string
HeadMessage string
// ReviewsTruncated: GitHub has more reviews than the page read, so one may be unseen.
ReviewsTruncated bool
// CrossRepository: the head is a branch of a fork, not of this repository.
CrossRepository bool
// The head commit's committer date: set by whoever committed, so a claim like Trailer's.
HeadCommittedAt time.Time
MergedBy string
MergedAt time.Time // zero while unmerged
MergeCommitSHA string
AutoMerge bool
Labels []string
Reviews []Review
Comments []Comment
}
PR is one GraphQL snapshot of a pull request. Checks and statuses are a separate query on the Merger: reading them needs checks and statuses read, which only the merger App holds (R16).
func (PR) Trailer ¶
Trailer is what the head commit claims for a git trailer, "" when the exact key is absent; the last occurrence wins. Only the message's last paragraph holds trailers, as git reads them, and never its subject.
It is a claim, never authentication (review B1). The harness's commit-msg hook marks every other Agent-* line, in any case, as the model's, then appends the real ones with `git interpret-trailers --if-exists add`, so the hook's own is the last occurrence. But an agent with a shell can skip or rewrite the hook, and anyone can copy a run's trailer: run IDs are public, and an amend or a cherry-pick keeps it (#76). Callers must fail closed on an absent, foreign, duplicated or case-variant Agent-Run, and a matching one proves only that the commit claims to be the run's.
type PRSummary ¶
type PRSummary struct {
Number int
Author string
Created time.Time
// HeadRef and HeadSHA are the head branch and commit as the list read them (the adopt
// poller's membership read; the merge gate reads the pull request again).
HeadRef string
HeadSHA string
// BaseRef is the branch the pull request targets; CrossRepository: its head is a fork's (or a
// deleted one's), read from the head's repository against the base's.
BaseRef string
CrossRepository bool
// NodeID and URL are the pull request's GraphQL id and page: an adopted revert needs no second read.
NodeID string
URL string
// Labels are the names of the labels the pull request carries, in GitHub's order.
Labels []string
}
PRSummary is one open pull request: enough to find the live ones without reading each in full.
type PermanentError ¶ added in v0.33.0
PermanentError is GitHub refusing a write for good: the issue or pull request is gone (404, 410) or locked (a 403 saying so). A retry gets the same answer, so the caller drops the write (F-3).
func (*PermanentError) Error ¶ added in v0.33.0
func (e *PermanentError) Error() string
func (*PermanentError) Unwrap ¶ added in v0.33.0
func (e *PermanentError) Unwrap() error
Unwrap returns the refusal as the client reported it.
type Push ¶
type Push struct {
Type string // push | force_push | branch_creation | branch_deletion | pr_merge | merge_queue_merge
Actor string
Before string
After string
At time.Time
}
Push is one move of a branch, as GitHub's repository activity records it (#76): Actor is the account whose credential moved the ref from Before to After, "" when GitHub names none. Unlike a commit's author or trailer, the pusher is GitHub's record, not the pusher's claim.
type RepositoryInfo ¶ added in v0.39.0
RepositoryInfo is the repository as its App connection reads it, live: a successful read is the installation check (v4 MR6), and its full name and private flag are GitHub's, not config's.
type RevertOf ¶ added in v0.33.0
RevertOf is what RevertPR reverts: the merged pull request (GitHub names the revert's branch revert-<Number>-<head>) and the merger App's login, the only author whose open revert is adopted.
type Review ¶
type Review struct {
ID int64
Author string
State string // APPROVED | CHANGES_REQUESTED | COMMENTED | DISMISSED
// Association is the author's relation to the repository (GitHub's authorAssociation: OWNER,
// MEMBER, COLLABORATOR, CONTRIBUTOR, FIRST_TIME_CONTRIBUTOR, FIRST_TIMER, MANNEQUIN, NONE); ""
// when GitHub did not say.
Association string
// Commit is GitHub's review.commit: the head the review was submitted on, until a force push
// moves it to an equivalent new head (ai-native-ref#250, REST's commit_id alike), and the head
// at submission when the review named none. Row 3 arms on an approval of the current head only
// (human path AM1), and only when the head's push dates it (reconciler approvesHead); "" never
// matches a head.
Commit string
Body string
At time.Time
Comments []ReviewComment
}
Review is a pull request review.
type ReviewComment ¶
ReviewComment is a review's comment on one line of the diff.
type Status ¶
type Status struct {
Context string
State string
Creator string
// Description is the status's own line, as its poster wrote it.
Description string
}
Status is one classic commit status, policy-bot's among them.
type Token ¶ added in v0.35.0
Token is an installation token and when GitHub says it expires.
type WorkflowRun ¶
type WorkflowRun struct {
ID int64
RunAttempt int // 1, then one more per re-run of the same run ID
Event string // schedule | workflow_dispatch | pull_request | push | …
Branch string // the run's head branch
Actor string // the login that triggered it
Conclusion string // success | failure | cancelled | …
Created time.Time
}
WorkflowRun is one completed run of a workflow, as the dead-links probe reads it: what triggered it, on which branch, by whom, and how it ended.