{"modulePath":"github.com/intentdriven/abcd","version":"v0.17.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package github\n\nPackage 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.\n\nThe 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.\n\n## Constants\n\n```go\nconst ActivityPage = 100\n```\nActivityPage is how many activities one ask reads: the forge's one page.\n\n```go\nconst Host = \"github.com\"\n```\nHost 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.\n\n```go\nconst MaxOutputBytes = 1 \u003c\u003c 20\n```\nMaxOutputBytes 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.\n\n## Variables\n\n```go\nvar ErrNotGitHub = errors.New(\"the origin remote is not a github.com URL, and this verb speaks only the GitHub API\")\n```\nErrNotGitHub 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.\n\n```go\nvar ErrRepositoryAnswer = errors.New(\"GitHub's answer did not say whether the repository is a fork\")\n```\nErrRepositoryAnswer 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.\n\n```go\nvar ErrTimeout = errors.New(\"gh did not answer\")\n```\nErrTimeout is what Run's error wraps when gh did not answer within Timeout.\n\n```go\nvar Timeout = 30 * time.Second\n```\nTimeout 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.\n\n## Functions\n\n```go\nfunc API(cwd string, stdin []byte, args ...string) ([]byte, error)\n```\nAPI runs \\`gh api --hostname github.com \\\u003cargs...\u003e\\` under cwd: Run with the host named by construction, so no caller can forget it.\n\n```go\nfunc NamesHostedRepository(url string) bool\n```\nNamesHostedRepository 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.\n\n```go\nfunc ParseRemote(url string) (owner, name string, err error)\n```\nParseRemote 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]](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.\n\n```go\nfunc PlainName(s string) bool\n```\nPlainName reports whether s is an owner or repository name abcd will put into an API path.\n\n```go\nfunc Run(cwd string, stdin []byte, args ...string) ([]byte, error)\n```\nRun 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.\n\n```go\nfunc ValidRunURL(s string) bool\n```\nValidRunURL 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.\n\n## Types\n\n```go\ntype Push struct {\n\tBefore, After, Login string\n\tApp                  bool\n}\n```\nPush 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.\n\n```go\nfunc Pushers(ctx context.Context, cwd, ref string) (pushes []Push, partial bool, err error)\n```\nPushers is the forge's record of who pushed to ref (a full ref under refs/heads/) on the repository origin names, its newest page alone (PushersPage), and whether older activities may lie past it, unread (partial: the page came back full or names a page past it, whether or not abcd reads the cursor it names it by), so a commit no push on it covers is one the record was not read far enough to say about.\n\n```go\ntype PushPage struct {\n\tPushes     []Push\n\tNext       string\n\tNextUnread bool\n\tFull       bool\n}\n```\nPushPage is one page of the forge's activity record of pushes to a ref: its pushes, newest first; the cursor the page names for the activities past it (\"\" when it names none or one abcd does not read); whether the page names a page past it by a link whose cursor abcd does not read (NextUnread); and whether the page came back full.\n\n```go\nfunc PushersPage(ctx context.Context, cwd, ref, after string) (PushPage, error)\n```\nPushersPage is one page of 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\\`, up to ActivityPage activities of any type, read for the types in pushActivities), newest first (itd-2609151838312703 C17), from the cursor after (\"\" for the newest page). The cursor of the page past it is read from the answer's Link header (its rel=\"next\" link's after parameter, and nothing else of that link), so a caller reads on by asking again with it; a rel=\"next\" link whose cursor abcd does not read sets NextUnread, so the page still says more lie past it. 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. The read of origin's URL and gh are both ended when ctx ends (runContext).\n\n```go\nfunc (p PushPage) More() bool\n```\nMore reports whether older activities may lie past the page: it came back full, or it names a page past it, by a cursor abcd reads or by one it does not.\n\n```go\ntype Remote struct {\n\tForm, User, Host, Port, Path string\n}\n```\nRemote 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.\n\n```go\nfunc SplitRemote(raw string) (r Remote, ok bool)\n```\nSplitRemote 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).\n\n```go\nfunc (r Remote) OnGitHub() bool\n```\nOnGitHub 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.\n\n```go\ntype Repo struct {\n\tFork   bool\n\tParent string\n}\n```\nRepo 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.\n\n```go\nfunc Repository(cwd, owner, name string) (Repo, error)\n```\nRepository 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.\n\n```go\ntype ScheduledRun struct {\n\tConclusion string\n\tURL        string\n\tUpdatedAt  time.Time\n}\n```\nScheduledRun 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.\n\n```go\nfunc ScheduledRuns(ctx context.Context, cwd, workflow, branch string) ([]ScheduledRun, error)\n```\nScheduledRuns 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. The read of origin's URL and gh are both ended when ctx does.\n\n","path":"github.com/intentdriven/abcd/internal/core/github","name":"github","synopsis":"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).","isRedistributable":true}
