Documentation
¶
Overview ¶
Package forge is ynf's port to where code lives (ADR-003, ADR-007): pull requests, their checks and reviews, branches and files, and the writes only ynf makes. GitHub is the first provider. Where work items live is the tracker port; a forge that also tracks issues, as GitHub does, serves it through IssueTracker.
Index ¶
- Variables
- func IssueKey(repo string, number int) string
- func IssueTracker(i Issues) tracker.Tracker
- func ParseIssueKey(key string) (repo string, number int, err error)
- type Fix
- type Fixes
- type Forge
- type GitHub
- func (g *GitHub) Comment(ctx context.Context, repo string, number int, marker, body string) error
- func (g *GitHub) DefaultBranch(ctx context.Context, repo string) (string, error)
- func (g *GitHub) File(ctx context.Context, repo, ref, path string) ([]byte, error)
- func (g *GitHub) FindPR(ctx context.Context, repo, branch string) (int, error)
- func (g *GitHub) FixFor(ctx context.Context, repo string, number int) (Fix, error)
- func (g *GitHub) GraphQLURL() string
- func (g *GitHub) Head(ctx context.Context, repo, branch string) (string, error)
- func (g *GitHub) Host() string
- func (g *GitHub) OpenPR(ctx context.Context, repo string, n NewPR) (int, error)
- func (g *GitHub) PullRequest(ctx context.Context, repo string, number int) (*facts.PR, error)
- func (g *GitHub) RequiredChecks(ctx context.Context, repo, branch string) Required
- func (g *GitHub) Search(ctx context.Context, query string) ([]Hit, error)
- func (g *GitHub) SetLabels(ctx context.Context, repo string, number int, add, remove []string) error
- func (g *GitHub) Ticket(ctx context.Context, repo string, number int) (facts.Ticket, Text, error)
- func (g *GitHub) Workflows(ctx context.Context, repo, ref string) (int, error)
- type Hit
- type Issues
- type NewPR
- type Required
- type RequiredCheck
- type RequiredReader
- type Text
- type WorkflowReader
Constants ¶
This section is empty.
Variables ¶
var ErrNoFix = errors.New("forge: no merged pull request closed it")
ErrNoFix means a closed ticket was not closed by a merged pull request: it was closed by hand, by a commit with no pull request, or by a pull request that was not merged.
var ErrNotFound = errors.New("forge: not found")
ErrNotFound means the forge has no such object.
var ErrRebased = errors.New("forge: rebase-merged; base unknown")
ErrRebased means a merged pull request was rebase merged, so its merge commit is only the last of its commits and the commit before the change cannot be taken from it.
Functions ¶
func IssueTracker ¶
IssueTracker serves a forge's issues through the tracker port. Keys are owner/name#number; a pull request is an issue here too, so an adopted pull request is its own ticket.
Types ¶
type Fixes ¶
Fixes is what a forge that records what closed an issue offers: the merged pull request whose merge closed it, or ErrNoFix. Shadow mode reads it to find the answer a ticket's history holds.
type Forge ¶
type Forge interface {
Search(ctx context.Context, query string) ([]Hit, error)
PullRequest(ctx context.Context, repo string, number int) (*facts.PR, error)
// FindPR returns the open pull request whose head is branch, or 0.
FindPR(ctx context.Context, repo, branch string) (int, error)
OpenPR(ctx context.Context, repo string, pr NewPR) (int, error)
// Comment posts body on a pull request unless a comment containing marker exists: side
// effects are idempotent per step (ADR-005).
Comment(ctx context.Context, repo string, number int, marker, body string) error
DefaultBranch(ctx context.Context, repo string) (string, error)
// Head is the commit a branch points at, so policy is read at a resolved commit (ADR-006).
Head(ctx context.Context, repo, branch string) (string, error)
// File reads a file at ref; ErrNotFound if it does not exist.
File(ctx context.Context, repo, ref, path string) ([]byte, error)
}
Forge is the port the engine uses.
type GitHub ¶
type GitHub struct {
// Log receives the warning that a repository's required checks could not be read; the default
// logger when nil.
Log *slog.Logger
// contains filtered or unexported fields
}
GitHub is the GitHub provider.
func NewGitHub ¶
NewGitHub returns a GitHub forge authenticated with token. baseURL is for tests; "" is api.github.com.
func (*GitHub) DefaultBranch ¶
DefaultBranch implements Forge.
func (*GitHub) FixFor ¶
FixFor implements Fixes. GitHub's GraphQL ClosedEvent names what closed the issue, which the REST timeline does not: a merged pull request gives the fix with its merge commit; a commit is looked up for the merged pull request that made it; an issue closed by hand, or by a pull request that was not merged, is ErrNoFix. A pull request that was rebase merged has no merge commit to take a base from, and is ErrRebased.
func (*GitHub) GraphQLURL ¶
GraphQLURL is the GraphQL endpoint beside the REST base: <base>graphql on api.github.com (and a test server), <host>/api/graphql on GitHub Enterprise Server, whose REST base ends /api/v3/.
func (*GitHub) Host ¶
Host is the forge instance's host, as item keys name it: github.com for the public service.
func (*GitHub) PullRequest ¶
PullRequest implements Forge: state, checks on the head (check runs and commit statuses, every page of each), the base branch's required checks marked, and the latest review per reviewer. A required check that has not reported is listed too, with status "expected", so the pull request cannot read as green while it is missing.
func (*GitHub) RequiredChecks ¶
RequiredChecks reads the checks branch requires: the union of classic branch protection and the rulesets that apply to it. An unprotected branch is known to require none. Only when both sources fail to be read is the answer unknown.
func (*GitHub) SetLabels ¶
func (g *GitHub) SetLabels(ctx context.Context, repo string, number int, add, remove []string) error
SetLabels implements Issues: labels already present or already absent are left alone.
type Issues ¶
type Issues interface {
Ticket(ctx context.Context, repo string, number int) (facts.Ticket, Text, error)
Comment(ctx context.Context, repo string, number int, marker, body string) error
SetLabels(ctx context.Context, repo string, number int, add, remove []string) error
}
Issues is what a forge that also tracks issues offers, keyed by repository and number.
type Required ¶
type Required struct {
Checks []RequiredCheck
// Known is false when neither source could be read. Checks is then empty, which says nothing
// about what the branch requires.
Known bool
// Detail says how it was read, or why it could not be.
Detail string
}
Required is what a branch requires before it merges, from classic branch protection and from the repository rulesets that apply to it, together.
type RequiredCheck ¶
RequiredCheck is a check a branch requires: its name, and the GitHub App it must come from, or 0 for any source.
type RequiredReader ¶
RequiredReader is what a forge offers that can say which checks a branch requires.
type WorkflowReader ¶
type WorkflowReader interface {
// Workflows counts the workflow files at ref; a repository with none has zero, not an error.
Workflows(ctx context.Context, repo, ref string) (int, error)
}
WorkflowReader is what a forge offers that can say whether a branch has CI workflow files.