forge

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 13 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 defines remote repository observations and publication inputs shared by forge adapters and their consumers.

Its contracts describe tags, releases, repository identity, pull requests, and remote failures. Adapters translate service responses into these values; upstream selects releases, and the engine's submit applies publication policy.

Index

Constants

View Source
const (
	GitHub = "github"
	GitLab = "gitlab"
)

Forge names as recorded on releases, destinations, and pull requests.

Variables

View Source
var ErrAccessUnknown = errors.New("your repository permissions could not be determined with this login")

ErrAccessUnknown is a role on a repository the forge wouldn't say, as GitHub won't to a fine-grained token not granted the repository (403 "Resource not accessible by personal access token").

View Source
var ErrAppRestricted = errors.New("the organization restricts which apps may act for it")

ErrAppRestricted is an organization refusing the app a client acts as, one it hasn't approved, as GitHub's OAuth App access restrictions do. Another app it has approved may do what this one can't.

View Source
var ErrAuthentication error = refusal.New(refusal.Auth, "a login is required")

ErrAuthentication is a forge refusing who's asking, or no one to ask as: a refusal of the auth kind, which every error wrapping it is. Where no login is found, the forge's own refusal says the way on, as github.ErrNoCredentials does.

View Source
var ErrIncomplete = errors.New("the repository returned incomplete information")
View Source
var ErrNotFound = errors.New("the requested object was not found")
View Source
var ErrPullRequestExists = errors.New("a pull request is already open for this head")

ErrPullRequestExists is a create the forge refused because a pull request is already open for its head: it says one exists, not that nothing was opened, so a create whose earlier answer was lost reads it back rather than taking it as a refusal (docs/designs/publication-record.md at 0e0ad767). It is returned wrapping ErrRejected too, which every caller before it handled.

View Source
var ErrRejected = errors.New("the remote write was rejected")

The forge's sentinels are said to a person where they surface, so their words lead with what happened, never the package's name: serve said "could not read pull requests: forge: authentication is required" (D-C3 on rc8, 2026-10-29).

Functions

func AbbreviatedCommit added in v0.9.0

func AbbreviatedCommit(s string) bool

AbbreviatedCommit reports whether s is a commit abbreviated as a forge shows it: seven to thirty-nine lowercase hex digits.

func AssetName added in v0.9.0

func AssetName(name string) bool

AssetName reports a name a release asset can have: one file's, not empty, with no path in it.

func AwaitingResponse added in v0.9.0

func AwaitingResponse(comments []Comment, account string, complete bool) (by string, at time.Time, settled bool)

AwaitingResponse finds the newest human word, ignoring bots. complete says whether older comments were read; an unseen older page cannot change a decision already made by a newer human (#248).

func FullCommit added in v0.9.0

func FullCommit(s string) bool

FullCommit reports whether s is a commit as a forge names it whole: forty lowercase hex digits, as a Portfile pins one and a forge's API returns it. It is narrower than git.ValidObjectID, which accepts any object ID Git can read.

func ServedURL added in v0.9.0

func ServedURL(address string) bool

ServedURL reports a URL an asset can be downloaded from: absolute, over HTTPS or HTTP, with a host.

func ValidGitHubRepositoryName added in v0.9.0

func ValidGitHubRepositoryName(value string) bool

ValidGitHubRepositoryName reports whether value is a GitHub repository's owner/name, each in the characters GitHub allows: letters, digits, '-', '_' and '.', neither "." nor "..". github.ValidRepositoryName asks it.

func ValidGitLabInstance added in v0.9.0

func ValidGitLabInstance(parsed *url.URL) bool

ValidGitLabInstance reports whether a parsed address can be a GitLab instance: http or https, a host, and no user, query, or fragment. A path names the instance's root below its host.

func ValidGitLabProjectPath added in v0.9.0

func ValidGitLabProjectPath(value string) bool

ValidGitLabProjectPath reports whether a name is a GitLab project path: two segments or more, none empty, "." or "..", and none holding space, a control character, or one of ?#%\.

Types

type Account added in v0.7.0

type Account struct {
	Exists    bool
	CreatedAt time.Time
}

Account is a login as a forge has it now: whether it names an account, and when that account was made, which says whether a repository's old owner name now belongs to someone else.

type AllowanceReader added in v0.6.0

type AllowanceReader interface {
	RequestsLeft(context.Context) (left int, resets time.Time, err error)
}

AllowanceReader says what's left of the hour's requests to the forge, and when the count starts again, without spending one, as GitHub's rate_limit endpoint does. A forge that can't say is simply not one.

type AnsweringRepository added in v0.7.0

type AnsweringRepository interface {
	AnswersAs() string
}

DatedRepository reports when a commit was made, its committer's date, so discovery can tell an old tag from a new one however it is spelled. AnsweringRepository is a repository that says the name its forge answered a listing as, read from the URLs in what it listed with no request of its own: GitHub redirects a moved or renamed repository's API, and its answers name where it went. Empty where nothing listed said, or it answered as itself.

type ArchiveRepository

type ArchiveRepository interface {
	Archive(ctx context.Context, commit string, into io.Writer, limit int64) error
}

ArchiveRepository writes the forge's archive of the repository's files at a commit, a gzipped tarball, bounded by limit bytes: for comparing a Git-fetched port's source from one commit to another, which a Git fetch downloads no archive of (the assessment design, D). It's the commit's files as the forge archives them, submodules left out, never what a build's clone checked out.

type AssetRepository

type AssetRepository interface {
	Assets(ctx context.Context, tag string) ([]model.ReleaseAsset, error)
}

AssetRepository describes the files a release carries, by its tag: each one's name, the URL the forge serves it at, and its size where known. A name that isn't one file's, a duplicate, or an asset without a URL the forge serves is an incomplete observation, never partly answered.

type CIJob added in v0.5.0

type CIJob struct {
	ID, Run int64
	Attempt int
	Name    string
}

CIJob is one of a head's CI jobs that failed, as the forge runs them: the job, the run it's of, which attempt of the run it was, and its name, as its check is named.

type CheckSummary

type CheckSummary struct {
	Total, Passed, Failed, Pending int
	// Failing names the checks that concluded unsuccessfully.
	Failing []string `json:",omitempty"`
}

CheckSummary counts the checks and statuses reported for a pull request's head.

type Comment added in v0.9.0

type Comment struct {
	Login string
	Kind  CommentKind
	At    time.Time
}

Comment is the author and creation time of a conversation comment.

type CommentKind added in v0.9.0

type CommentKind string

CommentKind distinguishes a human, a bot, and an unidentifiable author.

const (
	CommentUser    CommentKind = "user"
	CommentBot     CommentKind = "bot"
	CommentUnknown CommentKind = "unknown"
)

type CommitRepository

type CommitRepository interface {
	HasCommit(ctx context.Context, commit string) (bool, error)
}

CommitRepository reports whether the repository has a commit, named in full or by a leading part of its name, as gitrevisions(7) abbreviates it: as a Generated-By trailer's build names the commit it was built from, which nobody else can find where the forge doesn't have it.

type DatedRepository

type DatedRepository interface {
	CommitTime(ctx context.Context, commit string) (time.Time, error)
}

type Description

type Description struct {
	// Name is the repository's full name as the forge names it now,
	// which a renamed repository's differs from the name it was asked by.
	Name        string
	Description string
	Homepage    string
	License     string
	// CreatedAt is when the repository was made, where the forge said.
	CreatedAt time.Time
}

Description is what a forge says about a repository: its one-line description, its homepage, and the license it detected, as an SPDX identifier.

type Documents

type Documents interface {
	Document(ctx context.Context, url string, headers http.Header) (body []byte, served bool, err error)
}

Documents is a forge client that fetches a livecheck document from the forge it serves through its own client, so the user's credentials and the forge's rate-limit handling apply, sending the given request headers in place of the client's own. served is false for a URL the forge does not serve, and the plain fetch is used instead.

type FileRepository

type FileRepository interface {
	File(ctx context.Context, commit, path string, limit int64) ([]byte, error)
}

FileRepository reads one file of the repository at a commit, for manifests such as go.mod that a git-fetched port never downloads. An absent file reports ErrNotFound; the read is bounded by limit bytes.

type Login added in v0.4.0

type Login struct {
	Account string
	Source  string
	From    string
}

Login is who a forge's requests are made as, and where its token comes from: Source as the forge names it, and From as a person reads it.

type MoveFinder added in v0.8.0

type MoveFinder interface {
	FindMove(ctx context.Context)
}

MoveFinder is a repository that learns the name its forge answers by, where nothing it listed said, outside the forge's API, as GitHub's web page redirects a moved repository's: asked before AnswersAs where no release would be shipped. It never fails; what it can't learn stays unsaid.

type NameConfirmer added in v0.8.0

type NameConfirmer interface {
	ConfirmName(ctx context.Context) error
}

NameConfirmer is a repository that reads the name its forge answers by when nothing it listed said, as one whose tags came from git: asked before AnswersAs where a release would be shipped.

type PullRequest

type PullRequest struct {
	HeadRepository string
	HeadBranch     string
	BaseBranch     string
	Ref            PullRequestRef
	State          PullRequestState
	// RemoteHead is its head commit as observed. Recording it does not
	// imply that the object is available in the local Git repository.
	RemoteHead model.ObjectID
	// Commits is how many commits it has, as the forge counts them; zero
	// where the forge didn't say.
	Commits int `json:",omitempty"`
	Title   string
	Body    string
	// Author is who opened it, and MaintainerCanModify whether they let
	// the repository's maintainers push to its head branch.
	Author              string `json:",omitempty"`
	MaintainerCanModify bool   `json:",omitempty"`
	// CreatedAt is when it was opened, which MacPorts' maintainer timeout
	// counts from, and Mentions the logins its description mentions, as
	// the forge reads a mention, each once in the order written, which is
	// what's read of who was notified of it (macports.MergeFitness).
	CreatedAt time.Time `json:",omitzero"`
	Mentions  []string  `json:",omitempty"`
}

PullRequest is a pull request as the forge reports it.

type PullRequestContent

type PullRequestContent struct {
	Head  model.ObjectID
	Title string
	Body  string
}

PullRequestContent is what a pull request should hold: its head commit, title, and description.

type PullRequestInput

type PullRequestInput struct {
	Repository     string
	BaseBranch     string
	HeadBranch     string
	HeadRepository string
	ExistingPR     *PullRequestRef
	Desired        PullRequestContent
	// Draft opens a new pull request as a draft.
	Draft bool
}

PullRequestInput is a pull request to open, or an existing one to update, and what it should hold.

type PullRequestObservation

type PullRequestObservation struct {
	Found       bool
	PullRequest PullRequest
}

type PullRequestQuery

type PullRequestQuery struct{ Repository, HeadRepository, HeadBranch, BaseBranch string }

type PullRequestReader added in v0.4.0

type PullRequestReader interface {
	ReadPullRequests(context.Context, []PullRequestRef) ([]PullRequestReading, error)
}

PullRequestReader reads many pull requests in a few requests, with their reviews and checks, as GitHub's GraphQL API does, where Observe and Inspect take about five a pull request. A forge that can't is simply not a reader.

type PullRequestReading added in v0.4.0

type PullRequestReading struct {
	Ref         PullRequestRef
	Found       bool
	Partial     bool
	PullRequest PullRequest
	Status      PullRequestStatus
}

PullRequestReading is a pull request as one read over many gives it: its state and head, and, while it's open, its draft, reviews, and checks. Found is false where the forge hasn't it; Partial, where the read couldn't say all of its reviews or checks, and Inspect must.

type PullRequestRef

type PullRequestRef struct {
	Forge      string
	Repository string
	Number     int
	URL        string
}

PullRequestRef locates a pull request on a forge: Repository and Number identify it within the named forge.

type PullRequestState

type PullRequestState string

PullRequestState is a pull request's disposition on the forge.

const (
	// PullRequestOpen means it is open for review.
	PullRequestOpen PullRequestState = "open"
	// PullRequestClosed means it was closed without merging.
	PullRequestClosed PullRequestState = "closed"
	// PullRequestMerged means the forge reports it merged.
	PullRequestMerged PullRequestState = "merged"
)

type PullRequestStatus

type PullRequestStatus struct {
	Draft bool `json:",omitempty"`
	// Head is the commit the pull request was at when this was read; empty
	// where the forge didn't say.
	Head model.ObjectID `json:",omitempty"`
	// Mergeable is "yes", "no", or "unknown" while the forge is still
	// computing it.
	Mergeable string
	// MergeableDetail is the forge's finer state, such as clean, dirty,
	// blocked, behind, or unstable.
	MergeableDetail string `json:",omitempty"`
	// Review is "approved", "changes-requested", or "none".
	Review           string
	Approvals        int `json:",omitempty"`
	ChangesRequested int `json:",omitempty"`
	// ChangesRequestedBy are the logins whose latest review requests
	// changes, sorted, and ApprovedBy those whose latest approves it.
	ChangesRequestedBy []string `json:",omitempty"`
	ApprovedBy         []string `json:",omitempty"`
	// ReviewedAt is when the latest review that sets Review was
	// submitted; zero where none does.
	ReviewedAt time.Time `json:",omitempty"`
	// Requested are the logins whose review is requested and still
	// pending, sorted, and RequestedRead whether that list is complete: a
	// reading that couldn't take it, or took it cut short, says so, and an
	// absent login then settles nothing (docs/designs/publication-record.md at 0e0ad767).
	Requested     []string `json:",omitempty"`
	RequestedRead bool     `json:",omitempty"`
	// LatestReview is when each login last reviewed it, a review of any
	// kind, a comment-only one included: the time a reviewer's own answer
	// is for, where ReviewedAt is the verdict's.
	LatestReview map[string]time.Time `json:",omitempty"`
	// CommentedBy is the newest human commenter when they are not the account
	// acting here. CommentsRead says whether the conversation settled it (#248).
	CommentedBy  string    `json:",omitempty"`
	CommentedAt  time.Time `json:",omitzero"`
	CommentsRead bool      `json:",omitempty"`
	Checks       CheckSummary
}

PullRequestStatus is what a forge reported about a pull request's head beyond its state. Mergeable and Review use small fixed vocabularies so reports and tests do not depend on one forge's spellings; MergeableDetail keeps the forge's own.

type PullRequestSummary

type PullRequestSummary struct {
	Number int
	Title  string
	URL    string
}

PullRequestSummary is an open pull request found by a search.

type RateLimitError

type RateLimitError struct {
	RetryAt time.Time
	Err     error
}

RateLimitError is a confirmed refusal to perform the requested operation. A write may be attempted again after RetryAt; transport failures do not qualify.

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

func (*RateLimitError) Unwrap

func (e *RateLimitError) Unwrap() error

type Release

type Release struct {
	Tag         string
	URL         string
	Draft       bool
	Prerelease  bool
	PublishedAt time.Time
}

type ReleaseRepository

type ReleaseRepository interface {
	Releases(context.Context) ([]Release, error)
}

type Repository

type Repository interface {
	Name() string
	Tag(context.Context, string) (Tag, error)
	ListTags(context.Context) ([]Tag, error)
}

Repository binds tag observations to one validated repository. Catalog methods return complete observations or an error, never partial success. Tag resolves an exact name to a commit; an absent ref reports ErrNotFound.

type RepositoryInfo

type RepositoryInfo struct{ Parent string }

type RepositoryMovedError

type RepositoryMovedError struct{ From, To, CloneURL string }

RepositoryMovedError is a repository the forge answers under another name, renamed or transferred, as it redirects the old one: what a remote still names isn't the repository, and dockhand pushes to no other than the one named (the rc8 full stage's F3).

func (*RepositoryMovedError) Error

func (e *RepositoryMovedError) Error() string

type ReviewComment

type ReviewComment struct {
	Path string
	Line int
	Body string
}

ReviewComment is a review's comment on one line of a changed file.

type ReviewInput

type ReviewInput struct {
	Ref    PullRequestRef
	Commit string
	// RequestChanges posts it as a request for changes; otherwise it is a
	// comment.
	RequestChanges bool
	Body           string
	Comments       []ReviewComment
}

ReviewInput is a review to post on a pull request, at the commit it reviewed.

type Tag

type Tag struct{ Name, Commit string }

Directories

Path Synopsis
Package forgetest is GitHub as the engine's and the command line's tests stand it in: one stateful fake, its fork a local bare repository and its pull requests in memory, so each package's tests drive the same behavior rather than a fake of their own (the test plan's step 1, 2026-10-02).
Package forgetest is GitHub as the engine's and the command line's tests stand it in: one stateful fake, its fork a local bare repository and its pull requests in memory, so each package's tests drive the same behavior rather than a fake of their own (the test plan's step 1, 2026-10-02).
Package github adapts GitHub repositories and pull requests to forge contracts.
Package github adapts GitHub repositories and pull requests to forge contracts.
Package gitlab adapts GitLab tag observations to forge contracts.
Package gitlab adapts GitLab tag observations to forge contracts.

Jump to

Keyboard shortcuts

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