Skip to main content

Module github

Module github 

Source
Expand description

GitHub tokens for an agent’s git and gh.

  • git-credential <get|store|erase>: git’s credential helper protocol. srv puts it in the environment of an agent whose person connected GitHub through AgentMux Cloud (credential.https://github.com.helper), after an empty helper that clears the list, so no other helper’s login (the person’s, a stored token) is ever asked. For get it asks srv for the AgentMux GitHub App’s token for the repository in the request’s path; store and erase do nothing, so a token is never written down.
  • github-token -- <gh args>: what the gh shell function this wrapper exports calls (shim_functions.rs). It finds the repository the command is about (-R, GH_REPO, the path of gh api repos/o/r/…, else the working directory’s origin) and prints a token for it, or prints nothing and says why on stderr. The function then runs gh with that token, or with none: never with another credential.

Both ask POST /api/v1/github/token; who is asking is decided by srv from the agent’s token (AGENTMUX_AGENT_TOKEN), and the answer is the narrowed installation token or a sentence for the person. The token is never logged here.

Structs§

Granted
What POST /api/v1/github/token granted: the token, who the App’s bot is, and who the agent works for (the account’s own GitHub id and login).

Enums§

Answer
The answer of POST /api/v1/github/token: a token, or what to tell the person.

Constants§

ASK_TIMEOUT 🔒
srv may call AgentMux Cloud twice (a revalidation, then the mint), or wait on the host’s gh-agent for a fresh token (up to 50 s, identity::gh_agent_token), and then says why it has none: this waits a little longer than that, so the answer reaches the command. A stuck call still must not hold a git push forever.
NO_REPOSITORY 🔒
What a command that acts on a repository, and found none, is told: where the repository comes from.
PURPOSE_GIT 🔒
What git’s credential helper says the token is for: a push. srv gives a container a token that writes contents only to this ask, and never believes it for more than that.

Functions§

acts_on_a_repository 🔒
Whether a gh command is one that acts on a repository (a pull request, an issue, a run, a release, an API call…), so a repository it does not name and the working directory does not give leaves it with no token. gh --version, gh auth status, gh search and the like need none.
ask
Ask srv for the token a gh command uses for owner/repo.
ask_for
Ask srv for a token for owner/repo; purpose says what it is for (git from the credential helper).
credential_response
What git is told when srv gave a token.
default_repo_source
The repository gh itself would act on, as a remote’s URL or an OWNER/REPO: the one it was told (gh repo set-default, a cloned fork’s parent), else origin’s. cwd is where git -C points.
field 🔒
owner_repo_of_path
The repository named by a git credential request’s path: owner/repo or owner/repo.git.
owner_tag
What marks a PR as the work of a person’s agent: the id of the GitHub account it works for.
parse_request
key=value lines up to a blank line, as git writes them.
positional_repo 🔒
The repository gh repo <verb> OWNER/REPO is about, when it takes one as an argument.
read_body_file 🔒
The text of a PR body file, if it is small enough to go on a command line.
repo_of_command_here 🔒
The repository a gh command is about, for run_github_token and run_github_owner_tag.
repo_of_default
The repository for what default_repo_source found: a remote’s URL, or an OWNER/REPO set with gh repo set-default.
repo_of_gh_command
The repository gh is about to act on, from its arguments and environment, else from the working directory’s origin. None when the command names no repository (e.g. gh --version).
repo_of_remote
owner/repo of a GitHub remote URL (https, scp-style ssh or ssh://), for github.com only.
repo_of_spec
[HOST/]OWNER/REPO; a host other than github.com is not ours.
resolved_default
What gh takes as the default repository, from the lines of git config --get-regexp '^remote\..*\.gh-resolved$' (gh repo set-default, and a fork cloned with gh repo clone): Ok(OWNER/REPO) as set, Err(remote) for “the repository of that remote”.
rewrite_pr_body
gh pr create / gh pr edit arguments with tag added to the PR’s body: --body/-b text, or a --body-file/-F file, whose text (read by read_file) becomes the --body (stdin can’t be read twice, and a file too big to pass stays as it is). Arguments that give no body (--fill, a prompt) are left alone.
run_git_credential
git-credential <op>: git’s helper protocol. Exit code 0 with the credential on stdout, or 1.
run_github_owner_tag
github-owner-tag -- <gh args>: the arguments of a gh pr create or gh pr edit with the owner tag in its body, each followed by a NUL byte, for the gh function to run gh with. The arguments unchanged when there is no owner to name or no body to put it in.
run_github_token
github-token -- <gh args>: print a token for the repository the gh command is about; with none, say why on stderr (when there is a repository, or the command needed one) and print nothing.
url_repo 🔒
The repository of a https://github.com/OWNER/REPO/… argument (gh pr view <url>).
with_tag 🔒