forge

package
v0.32.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const ActionsApp int64 = 15368

ActionsApp is GitHub Actions' App id on github.com, the one classic protection pins required checks to (15368).

Variables

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

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

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

View Source
var ErrDiffTooLarge = errors.New("forge: a diff of a full page of files, the rest unread")

ErrDiffTooLarge is Diff reaching a full page of files: 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).

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

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

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

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

View Source
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".

View Source
var ErrNotAFile = errors.New("forge: the path is not a readable file")

ErrNotAFile is DefaultBranchFile 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.

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

Functions

func BaseLines

func BaseLines(patch string) ([]int, error)

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

func MergerPermissions(rerun, label bool) map[string]string

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

func SameLogin

func SameLogin(a, b string) bool

SameLogin compares GitHub logins, which GitHub treats as case-insensitive; every login comparison at the merge gate goes through it (review 2026-10-15, F7).

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

func (Absent) AddLabels(context.Context, int, ...string) error

AddLabels implements the Merger's AddLabels and fails closed.

func (Absent) BlameAtParent

func (Absent) BlameAtParent(context.Context, string, string) ([]BlameRange, error)

BlameAtParent implements the Merger's BlameAtParent and fails closed.

func (Absent) ChangedFiles

func (Absent) ChangedFiles(context.Context, string, string) ([]string, error)

ChangedFiles implements the Merger's ChangedFiles and fails closed.

func (Absent) CommitChecks

func (Absent) CommitChecks(context.Context, string) ([]Check, error)

CommitChecks implements the Merger's CommitChecks and fails closed.

func (Absent) Diff

Diff implements the Merger's Diff and fails closed.

func (Absent) DisableAutoMerge

func (Absent) DisableAutoMerge(context.Context, string) error

DisableAutoMerge implements the Merger's DisableAutoMerge and fails closed.

func (Absent) EnableAutoMerge

func (Absent) EnableAutoMerge(context.Context, string, string) error

EnableAutoMerge implements the Merger's EnableAutoMerge and fails closed.

func (Absent) FileAt

FileAt implements the Merger's FileAt and fails closed.

func (Absent) IsAncestor

func (Absent) IsAncestor(context.Context, string, string) (bool, error)

IsAncestor implements the Merger's IsAncestor and fails closed.

func (Absent) Merge

Merge implements the Merger's Merge and fails closed.

func (Absent) MergedSince

func (Absent) MergedSince(context.Context, time.Time) ([]MergedPull, error)

MergedSince implements the Merger's MergedSince and fails closed.

func (Absent) PullFiles

func (Absent) PullFiles(context.Context, int) ([]FilePatch, error)

PullFiles implements the Merger's PullFiles and fails closed.

func (Absent) PullRequestChecks

func (Absent) PullRequestChecks(context.Context, int) (Checks, error)

PullRequestChecks implements the Merger's PullRequestChecks and fails closed.

func (Absent) PullsWithLabel

func (Absent) PullsWithLabel(context.Context, string) ([]LabelledPull, error)

PullsWithLabel implements the Merger's PullsWithLabel and fails closed.

func (Absent) RerunCheck

func (Absent) RerunCheck(context.Context, int64) error

RerunCheck implements Merger.

func (Absent) RevertPR

RevertPR implements the Merger's RevertPR and fails closed.

func (Absent) RunArtifact

func (Absent) RunArtifact(context.Context, int64, string, string) ([]byte, error)

RunArtifact implements the Merger's RunArtifact and fails closed.

func (Absent) WorkflowRuns

func (Absent) WorkflowRuns(context.Context, string) ([]WorkflowRun, error)

WorkflowRuns implements the Merger's WorkflowRuns and fails closed.

type AgentPull

type AgentPull struct {
	Number  int
	HeadRef string
	Labels  []string
	Fork    bool
}

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 BlameRange

type BlameRange struct {
	Start, End int
	Commit     string
}

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

func (c Checks) StatusOf(context string) (state, creator string)

StatusOf is the state and creator of the named commit status; "", "" when it is absent.

type Comment

type Comment struct {
	ID     int64
	Author string
	Body   string
	At     time.Time
	Edited bool
}

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.

func (Commit) Subject

func (c Commit) Subject() string

Subject is the message's first line.

func (Commit) Trailer

func (c Commit) Trailer(key string) string

Trailer is what the commit claims for a git trailer, as PR.Trailer reads the head's.

func (Commit) Trailers

func (c Commit) Trailers(key string) []string

Trailers is every value the commit claims for a git trailer, in order: one per line of the message's last paragraph, as Trailer reads it, and none from the body.

type Diff

type Diff struct {
	Base, Head map[string]string
	Files      []FileStat
}

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

func (FilePatch) BaseLines

func (f FilePatch) BaseLines() ([]int, error)

BaseLines is BaseLines of the file's patch, or ErrNoPatch when GitHub omitted it.

func (FilePatch) BlamePath

func (f FilePatch) BlamePath() string

BlamePath is the name to blame the file under at the parent: its previous name on a rename.

type FileStat

type FileStat struct {
	Path      string
	Previous  string
	Status    string
	Additions int
	Deletions int
}

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

func Connect(ctx context.Context, o Options) (*GitHub, error)

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

func (g *GitHub) AddLabels(ctx context.Context, number int, labels ...string) error

AddLabels adds labels to an issue or pull request.

func (*GitHub) AddSubIssue

func (g *GitHub) AddSubIssue(ctx context.Context, parent int, childID int64) error

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

func (g *GitHub) AgentPulls(ctx context.Context) ([]AgentPull, error)

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

func (g *GitHub) BlameAtParent(ctx context.Context, mergeSHA, path string) ([]BlameRange, error)

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

func (g *GitHub) BranchActivity(ctx context.Context, branch string) ([]Push, error)

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

func (g *GitHub) ChangedFiles(ctx context.Context, base, head string) ([]string, error)

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

func (g *GitHub) CloseIssue(ctx context.Context, number int) error

CloseIssue closes an issue as completed (splitter SL12: a parent whose parts all merged).

func (*GitHub) ClosePR

func (g *GitHub) ClosePR(ctx context.Context, number int) error

ClosePR closes a pull request without merging it (§6.3's stale close).

func (*GitHub) Comment

func (g *GitHub) Comment(ctx context.Context, number int, body string) error

Comment posts body on an issue or pull request.

func (*GitHub) Commit

func (g *GitHub) Commit(ctx context.Context, sha string) (Commit, error)

Commit is one commit by sha, with its message: the tester's contract commit (R14).

func (*GitHub) CommitChecks

func (g *GitHub) CommitChecks(ctx context.Context, sha string) ([]Check, error)

CommitChecks are the check runs on one commit: main's CI after a merge, where no pull request carries the verdict anymore.

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

func (g *GitHub) Diff(ctx context.Context, base, head string) (Diff, error)

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

func (g *GitHub) DisableAutoMerge(ctx context.Context, nodeID string) error

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

func (g *GitHub) EnableAutoMerge(ctx context.Context, nodeID, expectedHeadSHA string) error

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

func (g *GitHub) FenceFile(ctx context.Context) ([]byte, bool, error)

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

func (g *GitHub) FileAt(ctx context.Context, path, ref string) (string, error)

FileAt is path's content at ref, "" when absent there: the dead-links probe reads a finding's file on main.

func (*GitHub) Healthy

func (g *GitHub) Healthy(now time.Time) bool

Healthy backs /readyz ("App token fresh", §6.5): a call succeeded in the freshFor before now.

func (*GitHub) IsAncestor

func (g *GitHub) IsAncestor(ctx context.Context, ancestor, sha string) (bool, error)

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

func (g *GitHub) Issue(ctx context.Context, number int) (Issue, error)

Issue is one GraphQL snapshot of an issue: text, labels, the body's last edit and the last title rename.

func (*GitHub) IssuesLabelled

func (g *GitHub) IssuesLabelled(ctx context.Context, label string) ([]Issue, error)

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

func (g *GitHub) LabelEvents(ctx context.Context, number int, label string) ([]LabelEvent, error)

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

func (g *GitHub) Labeled(ctx context.Context, label string) ([]Item, error)

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

func (g *GitHub) Merge(ctx context.Context, nodeID, head string) error

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 with 409 and a disallowed merge with 405; the sentinels are what the reconciler decides on. squash always: the factory's one commit per task is the history.

func (*GitHub) MergedSince

func (g *GitHub) MergedSince(ctx context.Context, since time.Time) ([]MergedPull, error)

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

func (g *GitHub) OpenPullRequests(ctx context.Context) ([]PRSummary, error)

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

func (g *GitHub) Permission(ctx context.Context, login string) (string, error)

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

func (g *GitHub) Ping(ctx context.Context) error

Ping runs on every replica every minute; the rate-limit endpoint costs no quota.

func (*GitHub) PullFiles

func (g *GitHub) PullFiles(ctx context.Context, number int) ([]FilePatch, error)

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

func (g *GitHub) PullRequest(ctx context.Context, number int) (PR, error)

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

func (g *GitHub) PullRequestChecks(ctx context.Context, number int) (Checks, error)

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

func (g *GitHub) PullRequestCommits(ctx context.Context, number int) ([]Commit, error)

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

func (g *GitHub) PullRequestForBranch(ctx context.Context, branch string) (int, error)

PullRequestForBranch is the newest pull request from branch in the repository, 0 when none.

func (*GitHub) PullsWithLabel

func (g *GitHub) PullsWithLabel(ctx context.Context, label string) ([]LabelledPull, error)

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

func (g *GitHub) RecentComments(ctx context.Context, number int) ([]Comment, error)

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

func (g *GitHub) RemoveLabel(ctx context.Context, number int, label string) error

RemoveLabel removes a label; one already gone (404) is not an error.

func (*GitHub) Repository

func (g *GitHub) Repository() string

Repository is the owner/name this connection is bound to.

func (*GitHub) RerunCheck

func (g *GitHub) RerunCheck(ctx context.Context, id int64) error

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

func (g *GitHub) RevertPR(ctx context.Context, nodeID, title, body string) (Revert, error)

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

func (*GitHub) RunArtifact

func (g *GitHub) RunArtifact(ctx context.Context, runID int64, name, file string) ([]byte, error)

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

func (g *GitHub) UserLogin(ctx context.Context, id int64) (string, error)

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

func (g *GitHub) WorkflowRuns(ctx context.Context, workflow string) ([]WorkflowRun, error)

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 Item

type Item struct {
	Number      int
	PullRequest bool
}

Item is an open issue or pull request carrying a label.

type LabelEvent

type LabelEvent struct {
	Actor string
	Label string
	At    time.Time
}

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)
	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
	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, nodeID, title, body string) (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 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

func (p PR) Trailer(key string) string

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
}

PRSummary is one open pull request: enough to find the live ones without reading each in full.

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 Revert

type Revert struct {
	Number int
	URL    string
	NodeID string
}

Revert is the pull request RevertPR opened.

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

type ReviewComment struct {
	Path string
	Line int
	Body string
}

ReviewComment is a review's comment on one line of the diff.

type Status

type Status struct {
	Context string
	State   string
	Creator string
}

Status is one classic commit status, policy-bot's among them.

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.

Directories

Path Synopsis
Package forgetest holds the in-memory forge fake for the tests of the packages that consume one.
Package forgetest holds the in-memory forge fake for the tests of the packages that consume one.

Jump to

Keyboard shortcuts

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