Transport for the GitHub REST API.
Per-call credentials. Every API-calling function in this package
takes an optional trailing opts Map, resolved by resolve: opts
first, then the github.token context variable, then the defaults.
Nothing from opts is written to ctx, so one run can act for many
tenants and parallel flows don't share credentials.
token: a PAT or installation token for this callapp-id,private-key,installation-id: act as a GitHub App installation. The token is minted once and cached for the run by::github::app/cached-installation-token.base-url: another API root, such as GitHub Enterprise Server'shttps://ghe.example.com/api/v3. It needs a credential in the sameopts:github.tokenis never sent to a per-call URL.api-version: theX-GitHub-Api-Versionfor this call
When opts has a token or App identity, github.token is ignored
for that call. A token in opts wins over an App identity. One of
those keys present but blank or null is an error, never a fallback to
github.token.
Context Vars
github.token
Values
CREDENTIAL_KEYS
CREDENTIAL_KEYS: Vec [
"token",
"app-id",
"private-key",
"installation-id"
]
Functions
blank-credential
fn (opts: Map, names: Vec): Str?
The first of names that opts has but with a blank or null value,
else null. Such a key is an error, never a fallback to context: a tenant
whose key is missing must not run on the project's credentials.
Example
::github::api/blank-credential({token: ""}, ["token", "app-id"]) // "token"
::github::api/blank-credential({token: "test-token"}, ["token", "app-id"]) // null
build-request
fn (method: Str, path: Str, additional-headers: Map, body: Any, resolved: Map): ::hot::http/HttpRequest
The outgoing HttpRequest from resolved settings (see resolve).
additional-headers win over the defaults, and a "" body sends no
Content-Type. Pure; exposed for testing.
Example
resolved {token: "test-token", base-url: "https://api.github.com", api-version: "2026-03-10"}
req ::github::api/build-request("GET", "/user", {}, "", resolved)
req.url // "https://api.github.com/user"
req.headers.Authorization // "Bearer test-token"
download
fn (path: Str): Any
fn (path: Str, opts: Map): Any
Make an authenticated GET request for a GitHub download endpoint.
Returns the downloaded text or Bytes on 2xx, and an Err carrying
HttpError otherwise. The HTTP transport follows GitHub's temporary
redirect for Actions logs and artifacts.
Example
log ::github::api/download("/repos/acme/api/actions/jobs/9876543210/logs")
length(log)
json
fn (method: Str, path: Str): Any
fn (method: Str, path: Str, additional-headers: Map, body: Any): Any
fn (method: Str, path: Str, additional-headers: Map, body: Any, token: Str): Any
fn (method: Str, path: Str, additional-headers: Map, body: Any, opts: Map): Any
Like request, but unwraps: returns the decoded JSON body on 2xx, null
for a no-content response, or an Err carrying HttpError. The shape
used by all github endpoint functions.
Example
me ::github::api/json("GET", "/user")
me.login
// A POST with a JSON body, for one tenant
issue ::github::api/json("POST", "/repos/acme/api/issues", {}, {title: "Timeout"}, {token: ::hot::ctx/get("acme.github-token")})
issue.number
json-response
fn (method: Str, path: Str): GitHubResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any): GitHubResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any, token: Str): GitHubResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any, opts: Map): GitHubResponse
Like json, but preserve successful response metadata as
GitHubResponse({status, headers, data}). Use this when an agent needs
pagination links, request ids, or rate-limit headers.
Example
::api ::github::api
page ::api/json-response("GET", "/repos/acme/api/issues?per_page=100")
length(page.data)
get(page.headers, "x-ratelimit-remaining")
// Walk to the following page, or null on the last one
::api/next-page(page)
link-url
fn (headers: Map, relation: Str): Str?
Extract one relation URL (for example "next") from a GitHub link
response header. Returns null when the relation is absent.
Example
headers {link: `<https://api.github.com/repos/acme/api/issues?page=9>; rel="last"`}
::github::api/link-url(headers, "last") // "https://api.github.com/repos/acme/api/issues?page=9"
::github::api/link-url(headers, "next") // null
next-page
fn (response: GitHubResponse): GitHubResponse?
fn (response: GitHubResponse, token: Str): GitHubResponse?
fn (response: GitHubResponse, opts: Map): GitHubResponse?
Fetch the next page represented by a GitHubResponse, preserving the next
response's metadata. Returns null when the supplied page is the last one.
Pass an explicit token or the same opts Map as the second argument when
the first page used one. A pagination link outside the API root is an Err.
Example
::api ::github::api
first-page ::api/json-response("GET", "/repos/acme/api/pulls?per_page=100")
second-page ::api/next-page(first-page)
if(is-null(second-page), [], second-page.data)
next-page-path
fn (headers: Map): Str?
fn (headers: Map, base-url: Str): Str?
Return the relative API path from a GitHub response's rel="next" link,
or null on the final page. Rejects pagination links outside base-url
(api.github.com by default).
Example
headers {link: `<https://api.github.com/repos/acme/api/issues?page=2>; rel="next"`}
::github::api/next-page-path(headers) // "/repos/acme/api/issues?page=2"
::github::api/next-page-path({}) // null
paginate-key
fn (path: Str, key: Str): Vec
fn (path: Str, key: Str, token: Str): Vec
fn (path: Str, key: Str, opts: Map): Vec
Fetch every page for an endpoint whose item Vec is nested under key,
such as "check_runs" or "items". Pass an explicit token or an opts
Map as the third argument for a per-call identity.
Example
checks ::github::api/paginate-key("/repos/acme/api/commits/main/check-runs?per_page=100", "check_runs")
map(checks, %.name)
paginate-list
fn (path: Str): Vec
fn (path: Str, token: Str): Vec
fn (path: Str, opts: Map): Vec
Fetch every page for an endpoint whose body is a Vec. Pagination follows
GitHub's link header serially. Prefer manual json-response/next-page
when the result may be very large. Pass an explicit token or an opts Map
as the second argument for a per-call identity.
Example
issues ::github::api/paginate-list("/repos/acme/api/issues?state=all&per_page=100")
length(issues)
// For one tenant
pulls ::github::api/paginate-list("/repos/acme/api/pulls?per_page=100", {token: ::hot::ctx/get("acme.github-token")})
map(pulls, %.number)
present
fn (value: Any): Any
value with surrounding whitespace removed when it's a Str, null when
it's blank or null. Ids may be Ints and pass through.
Example
::github::api/present(" acme ") // "acme"
::github::api/present(" ") // null
::github::api/present(42) // 42
request
fn (method: Str, path: Str): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any, token: Str): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any, opts: Map): ::hot::http/HttpResponse
Make an authenticated request to the GitHub REST API. path is
relative to api.github.com (e.g. /repos/hot-dev/hot/issues). Sends
the standard Accept, X-GitHub-Api-Version, and User-Agent
headers (GitHub rejects requests without a User-Agent).
Example
response ::github::api/request("GET", "/user")
response.body.login
// Per-call credentials
other ::github::api/request("GET", "/user", {}, "", {token: "ghp_tenant_b"})
resolve
fn (opts: Map): Map
Credentials and settings for one call (see resolve-from): returns
{token, base-url, api-version} or an Err. A GitHub App identity in
opts is exchanged for an installation token here, cached by a hash
of the identity. opts values are never written to ctx. The token, the
private key and a token minted from them are masked in the run's call
records.
Example
::github::api/resolve({token: "ghp_tenant_b"}).api-version // "2026-03-10"
github.token
resolve-from
fn (opts: Map, ctx-values: Map): Map
The one resolver, pure: credentials and settings for a call from
opts first, then ctx-values (a Map of context variables), then
defaults. Returns {token, base-url, api-version}, or
{app: {app-id, private-key, installation-id}, base-url, api-version}
for a GitHub App identity that resolve still has to exchange for a
token. An Err when there is no credential, the App identity is
incomplete, a credential key in opts is blank or null, or opts has
base-url without a credential. Exposed for testing; resolve feeds it the context.
Example
::github::api/resolve-from({token: "test-token"}, {}).token // "test-token"
::github::api/resolve-from({}, {"github.token": "ctx-token"}).token // "ctx-token"
is-err(::github::api/resolve-from({token: ""}, {"github.token": "ctx-token"})) // true
response-body
fn (response: ::hot::http/HttpResponse): Any
Return a response's decoded body, falling back to its wire bytes when the transport has no decoded body. Text logs remain Str values while binary archives remain Bytes.
Example
response ::hot::http/HttpResponse({status: 200, headers: {}, body: "log text"})
::github::api/response-body(response) // "log text"
settings-from
fn (opts: Map): Map
The non-credential settings of a call (pure): {base-url, api-version}
from opts, else the package defaults. base-url loses any trailing
slash.
Example
settings ::github::api/settings-from({base-url: "https://ghe.example.com/api/v3/"})
settings.base-url // "https://ghe.example.com/api/v3"
settings.api-version // "2026-03-10"
Types
GitHubResponse
GitHubResponse type {
status: Int,
headers: Map,
data: Any
}
HttpError
HttpError type {
status: Int,
headers: Map,
body: Any
}