Agent commands

How git and the GitHub CLI work for Agents: GitHub access through the Team owner's AirBuild GitHub App, gh access, the hint lines, and the co-author line on commits.

Agents use the ordinary git and gh (GitHub’s command-line tool). Both are already signed in to GitHub, so there is nothing to log in to or configure. AirBuild adds three things on top: the gh access command, a few hint: lines when a command fails, and an AirBuild co-author line on commits.

Where it runs

Both commands are available to Agents on a cloud Team and on a Mac Team. On a cloud Team the environment ships its own git and gh. On a Mac Team, gh comes with AirBuild (a gh you installed yourself is not used), and git is the Mac’s own, such as the one Xcode installs; when there is none, git stops with Error: git is not installed in this environment. Ask your user to install it and retry. See Choose where your Agents run.

Every argument is passed to the real git or gh unchanged, and their output and exit codes are theirs. AirBuild’s lines go to stderr only, so nothing that reads stdout sees them.

Where GitHub access comes from

The sign-in is the Team owner’s GitHub account, connected through the AirBuild GitHub App in Settings › GitHub. Being signed in is not the same as having access to a repository. GitHub checks, in order:

  1. GitHub is connected for the Team.
  2. The AirBuild GitHub App is installed on the account or organization that owns the repository.
  3. The repository is among the ones shared with that installation.
  4. Both the App and the connected account are allowed to write to it, for anything that writes.

So gh auth status can say “Logged in”, and a public repository can be read, while a push to it is still refused with a plain 403. After gh auth status, gh adds a note saying exactly this.

When access is missing, the Agent sends a request_github_repo card in the chat. The card asks the person for one repository, a whole account, or lets them pick a repository, and walks them through connecting GitHub first when it is not connected or the connection stopped working.

gh access

gh access [OWNER/REPO | OWNER]
gh access --help

gh access is AirBuild’s own command. It asks AirBuild which of the layers above a repository stops at for this Team, and whether a request_github_repo card can fix it.

Argument What it checks
None The repository of the current folder’s origin remote (it must be on github.com).
OWNER/REPO That repository. A github.com address or github.com/OWNER/REPO also works.
OWNER Whether the AirBuild GitHub App is installed on that account, and whether it shares every repository or selected ones.

The answer is one or two lines of plain text. What it can say:

Answer Can a card fix it?
Access is in place: the App covers the repository and can push, with the App’s permissions for contents, pull requests, issues, workflows and actions. No; nothing is missing. The answer lists what else refuses a push: a protected branch or ruleset, a change under .github/workflows without the App’s workflows permission, a rejected non-fast-forward push, or a wrong name. For a 403 from gh api, run it again with -i; the X-Accepted-GitHub-Permissions header names the permission the endpoint needs.
The App covers the repository, but its Contents permission on the owner is not write. No. If GitHub shows a permission request from AirBuild waiting on that account, accepting it allows pushing.
The App covers the repository, but the connected account itself cannot push to it. No. The account needs write access from the repository’s owner, or the work goes to a repository it can push to.
The App is installed on the owner, but this repository is not shared with it. Public repositories can still be read. Yes. The person adds the repository on the page the card opens.
The App is not installed on the owner’s account. Public repositories can still be read; private ones and every write cannot. Yes, when the account is the person’s own or an organization they administer. For anyone else’s account, work in a fork or a repository the person owns.
The App’s installation is suspended on GitHub. Yes. The card’s page is where the suspension is lifted.
The organization enforces SAML single sign-on and the Team’s GitHub sign-in has not completed it. Yes. The card signs the person in to GitHub again, where single sign-on is asked for.
GitHub has no user or organization by that name. No. Check the spelling, for example with git remote -v.
The owner has no repository by that name that the account can see. No. Check the name; it may have been renamed, moved or deleted.
GitHub is not connected for this Team. Yes. The card walks the person through connecting GitHub.
The GitHub connection can no longer be refreshed. Yes. The card walks the person through connecting GitHub again.

If AirBuild cannot answer, gh access stops with Error: could not check GitHub access for OWNER/REPO. Name it as OWNER/REPO (or a bare OWNER), or retry shortly. and exit code 2. Without an argument outside a GitHub checkout it says Error: gh access needs OWNER/REPO: this directory has no github.com origin remote.

gh access works even where gh itself is missing.

The hint lines

When a command fails, AirBuild adds lines starting with hint: on stderr after GitHub’s own error:

  • gh: after any command that exits with an error.
  • git: only after commands that talk to a remote: clone, fetch, pull, push, ls-remote, remote and submodule. A local command that exits non-zero (such as git grep with no match) gets no hint.

The hint is the gh access answer for the repository the command was talking to:

hint: GitHub access to `example-org/example-app` for this Team: the AirBuild GitHub App is installed on `example-org`, but this repository is not among the ones shared with it. Reading it still works if it is public; pushing, opening pull requests and every other write do not.

A second hint: line says whether a request_github_repo card repairs it, and what the person does on the page the card opens.

How the repository is found:

Command Repository
git A github.com address on the command line. Otherwise, for fetch, pull, push and ls-remote only: the remote the command named, or the one it uses by default (for push, the push remote), else origin.
gh -R / --repo, the GH_REPO variable, a repos/OWNER/REPO/… path given to gh api, or the argument of gh repo <verb>. Otherwise the current folder’s origin, with one more hint saying so: hint: (that is the repository of this directory; if the command addressed another one, run gh access OWNER/REPO for it.)

When no repository can be told, or AirBuild has no answer, the hint is a general one pointing to gh access OWNER/REPO and the request_github_repo card.

gh auth

gh auth <command> [flags]

gh auth is GitHub’s own group of sign-in commands. In a Team, gh is already signed in as the Team owner through the AirBuild GitHub App, so only the commands that read that sign-in are useful:

Command In a Team
gh auth status Works. Shows the signed-in account, then AirBuild’s note. See Sign-in commands that are refused.
gh auth token Works. Prints the token gh uses. See gh auth token.
gh auth switch Runs, but there is no other account to switch to, so it fails. See gh auth switch.
gh auth login, gh auth logout, gh auth refresh, gh auth setup-git Refused by AirBuild. See Sign-in commands that are refused.

gh auth --help lists them; gh auth <command> --help shows one. In a Team these help pages are not exempt the way gh --help is: gh auth --help, gh auth status --help, gh auth switch --help and gh auth token --help need GitHub to be ready for the Team, and stop with the messages under Sign-in commands that are refused when it is not. gh auth login --help, gh auth logout --help, gh auth refresh --help and gh auth setup-git --help are refused like the commands themselves.

gh auth token

gh auth token [--hostname HOST] [--user USER]

Prints the GitHub token gh is using for a host and account, on one line on stdout, and exits 0. In a Team that is the Team owner’s sign-in through the AirBuild GitHub App, the same one git and gh use, with the same access (gh access shows what it can do). It is for a tool that needs a GitHub token passed to it directly.

Flag What it does Default
-h, --hostname The GitHub host to print the token for. The default host, github.com
-u, --user The account to print the token for. In a Team there is only the Team owner’s account. The host’s active account
Message What to do
no oauth token found for github.com account USER --user named an account gh is not signed in as. Leave --user out.
Error: GitHub is not configured for this Team. and the other messages under Sign-in commands that are refused GitHub is not ready for the Team; do what that table says.
Terminal window
GITHUB_TOKEN="$(gh auth token)" ./scripts/release.sh

gh auth switch

gh auth switch [--hostname HOST] [--user USER]

In GitHub’s CLI, gh auth switch changes which signed-in account gh uses on a host. A Team has one sign-in, the Team owner’s, so there is no other account to switch to: the command fails (exit code 1), followed by AirBuild’s hint lines.

Flag What it does Default
-h, --hostname The GitHub host to switch the account for. Asked for, or the only host
-u, --user The account to switch to. Needed when a host has more than two accounts. Asked for, or the only other account

GitHub’s CLI asks for a missing host or account in a prompt; in a Team gh does not prompt.

The account is always the one the Team owner connected in Settings › GitHub. To reach a repository the current sign-in cannot, run gh access OWNER/REPO to see what is missing.

Terminal window
# Shows the one account the Team signs in as
gh auth status

Sign-in commands that are refused

Signing in and out belongs to AirBuild, so these gh auth commands stop with exit code 2:

Command Result
gh auth login, gh auth logout, gh auth refresh, gh auth setup-git Error: gh auth <verb> is not used here. and a line saying that GitHub credentials are provided automatically, and that missing or broken access is fixed with a request_github_repo card.
gh auth status Works, then adds: note: this is the Team owner's sign-in through the AirBuild GitHub App. Being signed in is not access to a repository: gh access OWNER/REPO shows what this token can do there.

gh --help and gh --version work even before GitHub is connected. Other gh commands stop with exit code 2 when GitHub is not ready:

Message What to do
Error: GitHub is not configured for this Team. Send a request_github_repo card and retry once the person has connected GitHub.
Error: the GitHub connection for this Team can no longer be refreshed. Send a request_github_repo card so the person connects GitHub again, then retry.
Error: Airbuild could not provide a GitHub token (HTTP …). Retry shortly. Try again in a moment.
Error: could not reach Airbuild to fetch GitHub credentials. Try again in a moment.

If gh is missing on a host, it prints Error: the GitHub CLI is not available in this environment. and suggests using git, which signs in the same way.

The co-author line on commits

Every git commit an Agent runs adds this trailer to the commit message:

Co-authored-by: AirBuild <315705251+airbuild[bot]@users.noreply.github.com>

On GitHub the commit then shows AirBuild as a co-author.

  • It is added to every kind of git commit, including --amend, --fixup, -m, -F and messages written in the editor.
  • It is not added twice: a message that already has this exact trailer is left as it is.
  • git merge, git cherry-pick and git revert do not add it.
  • It is added through git’s own --trailer option, not a hook, so the repository’s hooks and configuration are not touched.

To leave it off:

How Scope
Turn off Sign Commits with AirBuild in Settings › GitHub (“Commits your agents make show AirBuild as a co-author on GitHub.”). Only the Team’s owner can change it; it is on by default. Every Agent of the Team.
Run git with AIRBUILD_GIT_COAUTHOR=0 (also false, off or no). That one command.

When AirBuild cannot read the Team’s setting (for example, GitHub is not connected), the trailer is added.

Examples

Check access before pushing to a repository:

Terminal window
gh access example-org/example-app

Check whether the AirBuild GitHub App is installed on an organization:

Terminal window
gh access example-org

Commit once without the co-author line:

Terminal window
AIRBUILD_GIT_COAUTHOR=0 git commit -m "Update README"

Open a pull request as usual:

Terminal window
git push -u origin feature/login
gh pr create --fill