GitHub
A program's side of GitHub, from the back end: repositories and their
files read and written, issues and pull requests and their comments,
reviews, check runs and commit statuses, releases and their assets, Actions
workflows dispatched and their runs listed, over GitHub's REST API page by
page; GitHub's GraphQL API through graphql; a GitHub App's
own token and its installations' tokens; and GitHub's webhooks, checked and
done once in a job. An extension: ordinary Mote
in extensions/github/. Back to the map.
use "pkg:github/webhooks.mote"use "pkg:github/app.mote"// A report from the program's page becomes an issue, written as the App.server fn report(title: string, words: string): number requires signedIn limit 5 per hour let me = auth.me()? return githubIssueCreate(env("SHOP_REPO"), {title, body: `${words}\n\nFrom ${me?.email ?? "someone"}.`, labels: ["from-the-site"]}, `installation:${env("SHOP_INSTALLATION")}`)?.number// Each push to main: a check run on its commit, done when the program has looked.fn githubPushed(p: GithubPush): bool if p.branch != "main" return true let token = `installation:${p.installation}` let c = githubCheckCreate(p.repo, {name: "shop/links", sha: p.after, status: "in_progress"}, token)? githubCheckUpdate(p.repo, c.id, {status: "completed", conclusion: "success", output: {title: "Links", summary: "Every link answers."}}, token)? return true[packages]github = "../mote/extensions/github"graphql = "../mote/extensions/graphql"GITHUB_APP_ID=123456 GITHUB_APP_KEY="$(cat app.private-key.pem)" GITHUB_WEBHOOK_SECRET=… \ SHOP_REPO=acme/shop SHOP_INSTALLATION=4242 bun dist/server/main.jsA program that acts as itself with one token says GITHUB_TOKEN (a
fine-grained personal access token, github_pat_…) and passes "" as
each call's token.
Not met GitHub. Written from GitHub's REST reference (API version
2022-11-28, sent as X-GitHub-Api-Version) and its GraphQL and webhook
docs as of 2026, and run against a stand-in that answers in GitHub's shapes,
pages two at a time, keeps files' shas, refuses what GitHub refuses
(a check run from a person's token, a stale sha, a missing field) and checks
the App's JWT with the App's public key (tests/svc_standin.mjs code). The
webhook's signature is checked against GitHub's own published example. The
steps to check it with a real App are below.
The settings#
GITHUB_TOKEN | A token (a secret), read by the default fn githubToken(): for the calls whose token is "". A program that only acts as an App, or with people's own tokens, declares its own githubToken and needs none. |
GITHUB_APP_ID | With app.mote: the App's id (its Client ID is taken too). |
GITHUB_APP_KEY | With app.mote: the App's private key, the .pem GitHub gave (PKCS #1) or PKCS #8. A secret, read by fn githubAppKey(). |
GITHUB_WEBHOOK_SECRET | With webhooks.mote: the webhook's secret. |
GITHUB_API | Another address: GitHub Enterprise Server's (https://ghe.example/api/v3), or a stand-in. |
GITHUB_GRAPHQL | The GraphQL address (unsaid: <GITHUB_API>/graphql; Enterprise Server's is /api/graphql). |
GITHUB_WAIT | The longest wait for a spent limit, in seconds (60 unsaid). |
GITHUB_AGENT | The User-Agent GitHub asks for (mote-github unsaid: say the app's name). |
Tokens#
Every call takes a token last:
"" | githubToken(): GITHUB_TOKEN unless the program says otherwise. |
"installation:4242" | That installation's token, with app.mote: made from the App's JWT (POST /app/installations/4242/access_tokens), kept in the program's database (GithubInstallToken) and used by every call and every back end until five minutes before its hour ends, then made again. A webhook's event says its installation (e.installation, p.installation). |
| anything else | Used as it is: a person's OAuth token (from the oauth extension's oauthToken(githubProvider(), user), below), an installation token made elsewhere. |
It is sent as Authorization: Bearer …, never logged.
app.mote also gives githubAppJwt() (RS256, a minute back, nine ahead,
iss the App's id), githubInstallationOf(repo) and
githubInstallations(most). A key GitHub gives is PKCS #1, which
crypto.jwt.sign takes as it is (PKCS #8 too). An installation's token is
kept in the database for its hour sealed (crypto.seal, bound to its
installation) with fn githubSealWith(), which is the App's key unless the
program declares another secret; one that no longer opens (the key was
changed) is asked for again.
In a person's name#
The calls#
Limits#
Webhooks#
Left out#
Checking it against GitHub#
docs/github.md