forge

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 3 Imported by: 1 module, 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 port for pull-request operations. It is vendor neutral: GitHub via gh, GitHub via the REST API and GitLab are adapters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckSummary added in v0.2.0

type CheckSummary struct {
	// Failing checks finished without passing (failed, errored, timed
	// out, cancelled, needing action).
	Failing []string `json:"failing,omitempty"`
	// Pending checks are queued, waiting or still running.
	Pending []string `json:"pending,omitempty"`
}

CheckSummary is where the checks on a pull request's head commit stand, by name. Checks that passed, or were skipped or neutral, aren't listed.

func (CheckSummary) Clean added in v0.2.0

func (c CheckSummary) Clean() bool

Clean reports whether nothing is failing or still running.

type CreatePR

type CreatePR struct {
	Head, Base  string
	Title, Body string
	Draft       bool
}

CreatePR describes a new pull request.

type Forge

type Forge interface {
	// ListPRs returns every pull request whose head is a branch of this
	// repository, in one call.
	ListPRs(ctx context.Context, repo git.Repo) ([]PullRequest, error)
	CreatePR(ctx context.Context, repo git.Repo, in CreatePR) (PullRequest, error)
	UpdatePR(ctx context.Context, repo git.Repo, number int, in UpdatePR) error
	// MergeStack merges pull request number together with every open pull
	// request below it in its stack, all or nothing, and waits until the
	// forge reports the result (or has queued it). A refusal, such as a
	// draft in the way or a failed check, comes back as a *stack.Error.
	MergeStack(ctx context.Context, repo git.Repo, number int, method MergeMethod) (MergeOutcome, error)
	// Checks reports the checks on the current head commit of each pull
	// request in numbers, asking the forge about all of them together
	// rather than one at a time. A pull request with no checks at all may
	// be missing from the map.
	Checks(ctx context.Context, repo git.Repo, numbers []int) (map[int]CheckSummary, error)
	// CreateStack groups pull requests into a stack on the forge, bottom
	// to top. GitHub needs at least two, none of them already in a stack,
	// each based on the head of the one before. A refusal comes back as a
	// *stack.Error of kind api_failure carrying the forge's message.
	CreateStack(ctx context.Context, repo git.Repo, numbers []int) (StackRef, error)
	// ClosePR closes pull request number without merging it, leaving
	// comment on it first. One that is already closed or merged is not an
	// error.
	ClosePR(ctx context.Context, repo git.Repo, number int, comment string) error
	// RenameBranch renames branch from to to on the forge, which keeps its
	// pull request attached and retargets the pull requests based on it. A
	// refusal (the name is taken, no permission) comes back as a
	// *stack.Error of kind api_failure carrying the forge's message.
	RenameBranch(ctx context.Context, repo git.Repo, from, to string) error
	// PullRequestURL is the web address of pull request number, worked out
	// from local configuration only (never the network), so output can
	// link a PR the forge hasn't been asked about. "" when it can't tell.
	PullRequestURL(ctx context.Context, repo git.Repo, number int) (string, error)
}

Forge performs pull-request operations for the repository's remote.

type MergeMethod added in v0.1.5

type MergeMethod string

MergeMethod says how a pull request lands on its base.

const (
	// MergeDefault leaves the choice to the repository's settings.
	MergeDefault MergeMethod = ""
	MergeMerge   MergeMethod = "merge"
	MergeSquash  MergeMethod = "squash"
	MergeRebase  MergeMethod = "rebase"
)

type MergeOutcome added in v0.1.5

type MergeOutcome struct {
	Status MergeStatus
	// SHA is the merge commit on the base branch; empty when enqueued.
	SHA string
	// Message is the forge's own description of the outcome, if any.
	Message string
}

MergeOutcome reports a finished stack merge.

type MergeStatus added in v0.1.5

type MergeStatus string

MergeStatus is where a stack merge ended up.

const (
	// MergeMerged: the pull requests are on the base branch.
	MergeMerged MergeStatus = "merged"
	// MergeEnqueued: the base branch uses a merge queue and the pull
	// requests are in it; they land when the queue gets to them.
	MergeEnqueued MergeStatus = "enqueued"
)

type PullRequest

type PullRequest struct {
	Number int    `json:"number"`
	URL    string `json:"url"`
	Title  string `json:"title"`
	Body   string `json:"body,omitempty"`
	State  State  `json:"state"`
	Head   string `json:"head"`
	Base   string `json:"base"`
	// HeadSHA is the head commit the forge last saw for this PR.
	HeadSHA string `json:"headSha,omitempty"`
	// MergeCommit is the commit the PR was merged as, "" unless merged.
	MergeCommit string    `json:"mergeCommit,omitempty"`
	UpdatedAt   time.Time `json:"updatedAt"`
}

PullRequest is a forge-neutral pull request.

type StackRef added in v0.3.0

type StackRef struct {
	// ID is the forge's identifier for the stack.
	ID string
	// Number is the stack's number within the repository.
	Number int
}

StackRef names a stack of pull requests on the forge.

type State

type State string

State of a pull request.

const (
	StateOpen   State = "open"
	StateDraft  State = "draft"
	StateMerged State = "merged"
	StateClosed State = "closed"
	// StateUnknown is used when only a number is known (e.g. from a backend
	// snapshot) and the forge has not been consulted.
	StateUnknown State = ""
)

type UpdatePR

type UpdatePR struct {
	Title *string
	Body  *string
	Base  *string
	// Ready marks a draft ready for review when true.
	Ready *bool
}

UpdatePR carries optional changes; nil fields are left untouched.

Directories

Path Synopsis
Package github implements forge.Forge with the gh CLI.
Package github implements forge.Forge with the gh CLI.

Jump to

Keyboard shortcuts

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