github

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 17 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 github is abcd's one door to GitHub's API: the `gh` runner every forge read and write goes through, and the parser that turns an origin URL into the only repository a request may name (spc-2610120557432880, step 1; one-canonical-primitive). It was lifted out of internal/core/ahoy, whose remote verbs, and the site verb through them, were its only callers, so the embargo verbs share it rather than growing a second runner.

The call goes through `gh` rather than a raw HTTP client on purpose: it inherits the caller's own authenticated identity, so abcd never handles a token and a write is made by the person who invoked it, which is what adr-44's "no uninvited remote mutation" rests on.

Index

Constants

View Source
const Host = "github.com"

Host is the API host every request names EXPLICITLY. Without it `gh api` picks its host from GH_HOST, or from whichever single host the caller's gh is authenticated to, so the github.com-only rule ParseRemote enforces would constrain the PATH while the environment chose the ENDPOINT. An ambient GH_HOST (a repo direnv file, a CI job, an agent harness) would then send an authenticated write, with whatever credential gh holds for that host, to a machine the origin URL never named.

View Source
const MaxOutputBytes = 1 << 20

MaxOutputBytes caps what is read back from `gh`, stdout and stderr each (trust boundary): the response is remote-controlled, and an unbounded read into memory is the shape a hostile or broken endpoint exploits.

Variables

View Source
var ErrNotGitHub = errors.New("the origin remote is not a github.com URL, and this verb speaks only the GitHub API")

ErrNotGitHub is ParseRemote's refusal of a URL that is not on github.com at all, told apart from a github.com URL that names no one repository.

View Source
var ErrRepositoryAnswer = errors.New("GitHub's answer did not say whether the repository is a fork")

ErrRepositoryAnswer is what Repository's error wraps when GitHub answered with something it cannot vouch for: not JSON, or a fork whose parent is not one plain owner and one plain name.

View Source
var ErrTimeout = errors.New("gh did not answer")

ErrTimeout is what Run's error wraps when gh did not answer within Timeout.

View Source
var Timeout = 30 * time.Second

Timeout bounds each `gh` call. A subprocess reading from the network with no bound is a verb that hangs a session indefinitely on a stalled connection.

Functions

func API

func API(cwd string, stdin []byte, args ...string) ([]byte, error)

API runs `gh api --hostname github.com <args...>` under cwd: Run with the host named by construction, so no caller can forget it.

func NamesHostedRepository added in v0.15.1

func NamesHostedRepository(url string) bool

NamesHostedRepository reports whether url names a network host and exactly two path parts, an owner and a name, on any host: the shape a github.com URL takes, so a caller can tell a repository on a host it does not recognise (an ssh host alias, another forge) from a local path.

func ParseRemote

func ParseRemote(url string) (owner, name string, err error)

ParseRemote splits a github.com remote URL into owner and repository. It accepts the forms git takes for github.com (SplitRemote): the three it writes (`https://github.com/owner/repo[.git]`, `git@github.com:owner/repo[.git]`, `ssh://git@github.com/owner/repo`), and with them userinfo, a port, `ssh.github.com` over ssh, ssh or scp with no user, and a host in any case. It refuses everything else, without echoing the URL's segments: the URL is repo-controlled input, and a refusal is output like any other.

func PlainName

func PlainName(s string) bool

PlainName reports whether s is an owner or repository name abcd will put into an API path.

func Run

func Run(cwd string, stdin []byte, args ...string) ([]byte, error)

Run executes one `gh` subcommand under cwd and returns its bounded stdout. The environment is passed through unchanged; scrubbing it would blind gh to the credentials that make the caller the actor. A missing gh is refused with the tool registry's explanation (itd-63): what gh is, that these verbs require it, and the exact install step.

func ValidRunURL added in v0.16.2

func ValidRunURL(s string) bool

ValidRunURL reports whether s has the shape of a run's page on the forge: the check an answer is held to when it arrives, and again when a kept copy is read.

Types

type Push added in v0.15.1

type Push struct {
	Before, After, Login string
	App                  bool
}

Push is one push the forge's activity record holds: the tip it moved the branch from (Before, forty zeros when the push made the branch) and to (After), and the pushing account's login. App is true when an app made the push (appActor): its login then says nothing of who sent what it carried.

func Pushers added in v0.15.1

func Pushers(ctx context.Context, cwd, ref string) (pushes []Push, partial bool, err error)

Pushers is the forge's record of who pushed to ref (a full ref under refs/heads/) on the repository origin names: its activity record's pushes (`GET /repos/{owner}/{repo}/activity`, the newest hundred of any type, read for the types in pushActivities), newest first (itd-2609151838312703 C17), and whether that page came back full (partial): older activities may then lie past it, unread, so a commit no push on it covers is one the record was not read far enough to say about. The query names no type, since it takes only one and a first push or a forced one would then never be answered. An entry with no actor, or a commit name that is not one, says nothing and is passed over; every login is the forge's text, which a caller holds to its own grammar before showing it. An origin that is not a github.com URL cannot be asked, and gh is not run for it. A push made by an app (appActor) is answered with App set: the forge cannot say which person it acted for, so it judges no commit, but it still names the tip the record has reached. gh is killed when ctx ends (runContext).

type Remote added in v0.15.1

type Remote struct {
	Form, User, Host, Port, Path string
}

Remote is a remote URL split into what names the repository it reaches: Form is "scp" for git's scp-like `[user@]host:path`, else the URL's scheme; User and Port are as written (a password is never kept); Host is lower-cased; Path is the repository's path with its slashes and a `.git` suffix trimmed.

func SplitRemote added in v0.15.1

func SplitRemote(raw string) (r Remote, ok bool)

SplitRemote splits a remote URL that names a network host, the forms git takes (spc-2610161044461448, step 10): the scp-like `[user@]host:path` and a scheme URL with a host, its userinfo and port included. A local path, a `file://` URL, and anything with no host are not one (ok false).

func (Remote) OnGitHub added in v0.15.1

func (r Remote) OnGitHub() bool

OnGitHub reports whether r reaches github.com by name: the host github.com in any form, or ssh.github.com (GitHub's ssh over port 443) over ssh.

type Repo added in v0.15.1

type Repo struct {
	Fork   bool
	Parent string
}

Repo is what the repository endpoint says of one repository: whether it is a fork, and when it is, the repository it was made from, as owner/name.

func Repository added in v0.15.1

func Repository(cwd, owner, name string) (Repo, error)

Repository asks the repository endpoint, through API, whether owner/name is a fork and of what (spc-2610161044461448, step 10). Both names are checked before anything runs, and the parent is returned only when both its halves are plain names, so it can be put into a command a person is told to run.

type ScheduledRun added in v0.16.2

type ScheduledRun struct {
	Conclusion string
	URL        string
	UpdatedAt  time.Time
}

ScheduledRun is one completed run of a workflow, as the forge reports it: its conclusion, its page and when it last changed, which for a completed run is when it ended.

func ScheduledRuns added in v0.16.2

func ScheduledRuns(ctx context.Context, cwd, workflow, branch string) ([]ScheduledRun, error)

ScheduledRuns asks the forge for the latest completed runs a schedule started of the workflow whose file is named workflow, on branch, in the repository origin names at cwd (GET /repos/{owner}/{repo}/actions/workflows/{file}/runs), newest first, at most scheduledRunsPage of them. It answers none and no error when the forge lists none. An answer holding anything that is not such a run, or does not read as one, is an error: only runs it can vouch for replace what a caller knew. gh is ended when ctx does.

Jump to

Keyboard shortcuts

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