Connecting the GitHub App
Install the CodeHerder Cloud GitHub App on your organization, or create your own App when you self-host.
The hosted App is named CodeHerder Cloud (slug codeherder-cloud). The name “CodeHerder” is taken on GitHub. A self-hosted App can have any free name that you choose. Use its slug in URLs.
The GitHub App links a GitHub organization or account to a workspace. GitHub then sends pull request, review, comment, check and push events to CodeHerder. CodeHerder also mints short-lived installation tokens on the server. This is separate from the token-based GitHub integration.
Connect GitHub on CodeHerder
- Open Admin → Integrations, then GitHub. Find the GitHub App panel.
- Select Install GitHub App. CodeHerder sends you to GitHub.
- Pick the organization or account. Choose all repositories or only some.
- Approve the install. GitHub asks you to authorize the App too. Approve that as well.
- GitHub returns you to CodeHerder. CodeHerder finishes the link and lists the repositories.
Only a workspace admin or owner can start the install. That person must also be an owner (admin) of the GitHub organization, or the owner of the personal account, that holds the installation. Being able to see the installation, or to read one of its repositories, is not enough. A repository admin who is not an organization owner is refused. CodeHerder checks this with your GitHub authorization. A refused user sees not_account_admin. Pasting an installation id does not work. Another tenant’s installation is refused.
Connecting with Install GitHub App or Connect also marks your GitHub login as verified for you in this workspace. CodeHerder uses it to attribute comments and events to you. It never grants access. If another member already holds that login, the connect still works and the other link stays.
One installation belongs to one workspace. A second claim of the same installation fails with already_exists. A group’s installation is usable in every workspace beneath it. The panel marks it inherited.
Disconnect removes the link in CodeHerder. It does not uninstall the App on GitHub. To stop the App’s events, uninstall it on GitHub too. Only a workspace admin or owner sees Disconnect, and only on the workspace or group that holds the installation. An inherited installation has no button.
Share one installation across workspaces
GitHub allows one installation of the App for each account. If you select Install GitHub App in a second workspace, GitHub only opens the configure page. It never returns to CodeHerder, so nothing connects.
To share one installation, connect it on the common group. Every workspace beneath the group then inherits it.
- Open Admin → Integrations, then GitHub, in the workspace that holds the installation. Select Disconnect on the installation.
- Open Admin → Integrations, then GitHub, on the common group. The group sidebar has this item.
- If the panel lists no installation, select Sign in with GitHub. GitHub proves your login for the group. A proof on a workspace does not count for its parent group.
- Select Connect next to the installation.
- Open any workspace below the group. The panel shows the installation as inherited.
If another workspace holds the installation, the panel says so before you select Install GitHub App. It names the holder when you can see that workspace. It never names a workspace you cannot see. In that case, ask an admin of that workspace to disconnect it.
A workspace that inherits an installation sees only the repositories that it registered, or that sit beneath it. It never sees the other repositories of the installation. An admin of the holding workspace or group sees the full count. They select Browse all to search and page the full list.
You can do the same from the CLI. Run ch githost app show to see the installations and their ids. Run ch githost app connect to print a URL that proves your login. Run ch githost app unclaimed to list the installations that you administer, and who holds each. Run ch githost app connect <installationId> to print the URL that connects one installation. Open each URL in a browser. Run ch githost app release <installationRowId> to disconnect an installation, the same as Disconnect. Run ch githost app repos <installationRowId> to page the full repository list, for the holder’s admins. ch githost app install prints the install URL.
Installed from GitHub first
Start from CodeHerder when you can. You can also install the App from GitHub: from the App’s public page, from the GitHub Marketplace, or from a link an organization owner shared. GitHub then returns you to CodeHerder with no workspace attached. CodeHerder checks your GitHub authorization, as it does for a normal install. It then shows a page that asks you to choose a workspace.
- Sign in to CodeHerder if you are signed out. You return to the same page.
- Pick a workspace. The list holds only the workspaces where you are an admin or owner.
- CodeHerder connects the installation to that workspace and lists the repositories.
This path does not verify your GitHub login. The page link proves only that someone installed the App. It does not prove that you are that person. To verify your login, use Connect or Install GitHub App later.
The page link works once and expires after 15 minutes. This is the longest wait of any path. If it fails, install again, or use Connect as described below.
If a workspace already holds the installation, the page says so and links to that workspace. CodeHerder does not move the installation. An admin of that workspace must Disconnect it first.
If you see no workspace to pick, you are not an admin of any workspace. Ask a workspace admin to connect it, or to make you an admin.
Connect an installation that no workspace holds
GitHub does not send the authorization step again when you only change the App’s settings. In that case you return to the GitHub page with nothing connected. The GitHub App panel then lists each installation that no workspace holds and that your GitHub login owns or administers. Select Connect next to it. CodeHerder sends you to GitHub to authorize, then connects the installation to this workspace.
The list needs a GitHub login that GitHub proved to CodeHerder for this workspace, or for a group above it. Connecting once with Install GitHub App or Connect proves it. When the panel lists nothing, select Sign in with GitHub to prove it without an installation. A login that a workspace admin verified by hand does not count. An install that started on GitHub does not. For an organization, the installation also needs the Members: Read permission. Without it, the organization is not listed. Use Install GitHub App instead.
Keeping the repository list current
Add or remove a repository on the installation in GitHub. CodeHerder updates its list within seconds. The panel lists the repositories that you also registered in CodeHerder in this workspace or beneath it. The holder’s admins can browse every repository of the installation. Registering a repository stays a separate step: see Connecting repositories.
Self-host: create your own App
A self-hosted server uses your App, not the hosted one. You create the App once on GitHub. Then you set six server knobs. Replace <base> with your server’s public HTTPS URL.
Create the App
Open Settings → Developer settings → GitHub Apps → New GitHub App. You can instead register it from this manifest. Choose a free App name. “CodeHerder” is taken on GitHub.
{
"name": "<your App name>",
"url": "<base>",
"hook_attributes": { "url": "<base>/v1/githost-deliveries/github", "active": true },
"redirect_url": "<base>/v1/github-app/callback",
"callback_urls": ["<base>/v1/github-app/callback"],
"setup_url": "<base>/v1/github-app/callback",
"request_oauth_on_install": true,
"public": false,
"default_permissions": {
"metadata": "read",
"members": "read",
"contents": "write",
"pull_requests": "write",
"issues": "write",
"checks": "read",
"actions": "read",
"statuses": "read"
},
"default_events": [
"pull_request", "pull_request_review", "pull_request_review_comment",
"issue_comment", "check_suite", "check_run", "workflow_run",
"push", "create", "delete"
]
}
Register the manifest and convert the code
GitHub reads a manifest from a form post. Build an HTML page with a form that posts the manifest to https://github.com/settings/apps/new, or to https://github.com/organizations/<org>/settings/apps/new for an organization. Put the manifest JSON in a field named manifest. Open the page, then select Create GitHub App on GitHub.
GitHub then redirects your browser to <base>/v1/github-app/callback?code=<code>. CodeHerder shows a page with the next command. GitHub has not created the App yet. The code works once and expires after 1 hour. Convert it:
curl -X POST -H "Accept: application/vnd.github+json" https://api.github.com/app-manifests/<code>/conversions
The reply holds the App secrets. Keep it private. It maps to the knobs in Set the knobs:
| Reply field | Knob |
|---|---|
id |
CH_SERVER_GITHUB_APP_ID |
pem |
Save to a file. Set CH_SERVER_GITHUB_APP_PRIVATE_KEY_FILE to its path. |
slug |
CH_GITHUB_APP_SLUG |
webhook_secret |
CH_GITHUB_APP_WEBHOOK_SECRET |
client_id |
CH_GITHUB_APP_CLIENT_ID |
client_secret |
CH_GITHUB_APP_CLIENT_SECRET |
If the code expires, register the manifest again.
Check these settings on the App page:
- Webhook URL:
<base>/v1/githost-deliveries/github - Callback URL:
<base>/v1/github-app/callback - Request user authorization (OAuth) during installation: on. Without it, CodeHerder cannot prove who installed the App.
- Webhook secret: a long random string. Keep a copy.
- Repository permissions: Pull requests: Read and write and Issues: Read and write. Grant Checks, Commit statuses and Actions as Read-only. Stages and devices read all three, so a stage can read CI results. CodeHerder’s server no longer posts a
CodeHerderstatus check (see Task status on pull requests). CodeHerder needs Pull requests and Issues write to post a task comment to a pull request (see Posting a task comment to the pull or merge request). The manifest sets them. To resolve a review thread for an agent, the App also needs Contents: Read and write (see Posting a task comment to the pull or merge request). An App made by hand needs them too, and an owner of each organization must accept the new permissions on each installation. - Optional: Actions write. Grant Actions: Read and write if a repo lets a stage after the merge dispatch workflows. The manifest keeps Actions at Read-only. A repo opts in with its Release actions setting (see Release actions). Without the permission, the server refuses the release token and says which permission is missing.
- Optional: Workflows. Grant Workflows: Read and write only if a repo needs to let agents change files under
.github/workflows/. The manifest leaves it out. A repo opts in with its Workflow edits setting (see Letting agents change CI workflow files).
GitHub sends installation events without a subscription. Generate a private key and a client secret on the App page.
Set the knobs
| Knob | Value |
|---|---|
CH_SERVER_GITHUB_APP_ID |
The numeric App id. |
CH_SERVER_GITHUB_APP_PRIVATE_KEY_FILE |
Path to the PEM private key. CodeHerder reads it at each mint. |
CH_GITHUB_APP_SLUG |
The App’s URL name, from github.com/apps/<slug>. |
CH_GITHUB_APP_WEBHOOK_SECRET |
The webhook secret. |
CH_GITHUB_APP_CLIENT_ID |
The App’s OAuth client id. |
CH_GITHUB_APP_CLIENT_SECRET |
The App’s OAuth client secret. |
Set all six, then restart the server. If you set only some, CodeHerder logs a warning at boot and treats the App as not configured.
Devices need no App key. The server mints the token that a stage uses, for the workspace the stage runs in. See Server-minted tokens. The device knobs CH_GITHUB_APP_ID and CH_GITHUB_APP_PRIVATE_KEY_FILE are optional. They apply to a self-hosted device that has no server App.
What the App reads
With the App installed on a repo, CodeHerder reads that repo with a short-lived installation token. This covers merge state, mergeability and repo health. The token covers one repo and has read access only. CodeHerder revokes it after the read. A task can enter a waiting-for-merge stage on such a repo with no GitHub token.
You need a GitHub personal access token only for repos the App does not cover, and for GitHub Enterprise Server. If an installation is suspended or removed, CodeHerder uses the token for that repo. If there is no token, the repo’s health shows not_connected. The repo’s integration health names the credential in its Read by row.
Server-minted tokens
A stage gets its GitHub token from the server. The device asks the server for a token for one sandbox, one repo and one access class. The server finds the installation that the sandbox’s workspace holds for the repo. It looks in the workspace first, then in the nearest group above it. A suspended installation does not count. The server mints a short-lived installation token with its own App key and returns it. The device needs no App ID and no private key. The App key stays on the server. The request names a sandbox, not a workspace. The server picks the installation from that sandbox’s own workspace. So a device that serves several workspaces gets each sandbox’s token from that sandbox’s workspace. If that workspace has no installation for the repo, the server mints nothing for it.
A device picks the source of a git credential in this order:
- The server. The workspace has an installation that covers the repo.
- The device’s own key. The device has
CH_GITHUB_APP_IDandCH_GITHUB_APP_PRIVATE_KEY_FILE. This is a second choice, for self-hosted devices. - The git-token pool. Neither of the above covers the repo. The pool can hold a person’s token, so the pull request then shows that person.
If the server could mint a token and failed, the device serves no credential. It does not use the pool in that case, because the pool could show a person where the workspace’s App belongs. The device asks again on the next git call.
- What the server mints. A writable stage on a
read_writerepo gets Contents, Pull requests and Issues, all read and write. It also gets Checks, Commit statuses and Actions, all read, so the stage can read CI results. A read-only stage gets Contents read, Pull requests write and Issues write, plus the three CI reads, so it can post comments and reviews (see Read-only stage posts). A fetch gets Contents read, Pull requests read and the three CI reads. Metadata read is always implied. A stage after the merge, on a repo with Release actions allowed, can also get a token with Contents write and Actions write, and no Pull requests or Issues write. See Release actions. A writable stage on a repo with Workflow edits allowed also gets Workflows write. See Letting agents change CI workflow files. - Scope. The server mints two kinds of token. Each lasts about 1 hour, and the device caches it until shortly before it expires.
- Git fetch and push use a token for one repo. Sandbox teardown revokes it.
- GitHub API relay calls use one installation-wide token for each sandbox, installation and class. It reaches every repo the workspace may use on that installation. No two sandboxes share it. Sandbox teardown revokes it, as it does a per-repo token.
- A GraphQL read through the relay must name a listed repo and select only
repository. The relay refusesviewer,node,searchand similar fields. - No token enters the sandbox. The relay adds the token to each call.
- Refusals. The server mints only for the device that hosts the sandbox, for a sandbox that has not ended, and for a repo attached to that sandbox. A write token needs the repo at
read_writefor the workspace. A refusal says nothing about the installation or the key, and no log line holds a token. - Fallback. Your installation may not grant every requested permission. GitHub then refuses the request with a 422. The server drops only the missing permissions and mints the rest. It logs one warning for each installation each hour. For example, an installation without Checks still gets Contents, Pull requests and Issues write, but the stage cannot read CI results. A read-only stage that posts comments is refused when Pull requests or Issues write is missing, and the error names it. Accept the permission update on GitHub. The server asks for the full set again within one hour. No restart is needed. A repo that allows workflow edits works the same way. If the installation lacks Workflows, the server drops only that permission, and GitHub then refuses a push that changes a workflow file. A 422 for a repo the installation cannot access does not cause the fallback.
- What shows as the App. Commits keep the agent’s git author. The push, the pull requests, the pull request comments and the issue comments show as
<slug>[bot]. - Which source served. The device page and
ch device showname the source for each host: “GitHub mint: server”, “device key” or the pool. When the server did not cover a repo, the check says why, for exampleno_installation. The pool entry then shows as the fallback only.
Troubleshooting
- The panel has no Install GitHub App button. The server is not configured. Check that all six knobs are set and the server restarted.
- GitHub says the callback URL is wrong. The URL must match
<base>/v1/github-app/callbackexactly. - A repo reads Gap or Failing. Open the repo page and read Integration health, or run
ch repo health <repo>. A gap means GitHub shows pull request activity that no delivery announced. In GitHub, open the App’s Advanced tab, find the missed delivery under Recent deliveries, and redeliver it. While the status is not healthy, CodeHerder reads the repo from GitHub on a short timer, so task state stays correct. - No events arrive. Check the webhook URL and the webhook secret. GitHub’s Advanced tab shows each delivery and its answer. A
401means the secret differs. - The installation shows as suspended. Someone suspended the App on GitHub. Unsuspend it there. CodeHerder clears the mark when GitHub says so.
- A thread resolve fails with “the GitHub App lacks Pull requests: Read and write and Contents: Read and write”. The App lacks one of the two permissions on that installation. GitHub refuses
resolveReviewThreadto an App without Contents write, although its documentation does not say so. The default manifest grants both. Grant Contents: Read and write on the App, accept the update on the installation, then runch task comments resolveagain. - A comment fails with “the host refused the credential”. The App lacks Pull requests or Issues write permission on that installation. Accept the permission update on GitHub, then retry the comment.
- Pull request creation fails with 403 on a minted token. The installation lacks Pull requests or Issues write. The server log shows the warning “lacks requested permissions”. Accept the permission update on GitHub.
gh pr checksfails with 403 on a minted token. The installation lacks Checks, Commit statuses or Actions read. The server log shows the warning “lacks requested permissions” with the missing names. Grant the three read permissions on the App, then accept the update on the installation.- A push that changes a file under
.github/workflows/is refused. Either the repo’s Workflow edits setting is off, or the installation lacks Workflows: Read and write. Fix both: allow workflow edits on the repo, and grant the permission on the App, then accept the update on the installation. The change applies from the next stage start. See Letting agents change CI workflow files. - Pull requests still show a person, not the App. Open the device page and read the git mint check. A reason of
no_installationmeans no installation of the workspace covers that repo. Add the repo to the installation, or connect the installation to the workspace. A reason ofapp_not_configuredmeans the server has no App. A device that predates the server mint (an olderch) serves its pool until it updates. - A repository is missing. The installation may not include it. Add it in GitHub under the App’s Configure page.
- The claim fails after you return. You have 10 minutes to finish the install on GitHub. After GitHub returns you, you have 5 minutes to finish in CodeHerder. A link works once. If either time runs out, start the install again from the same signed-in account. An install that began on GitHub gets 15 minutes.
- You installed from GitHub and the workspace still shows no installation. Finish on the page CodeHerder showed after the install. If you closed it, select Connect in the GitHub App panel, or install again from CodeHerder.
Related guides
- Integrations — connect a token for GitHub or GitLab.
- Connecting repositories — register the repositories agents work in.
Last updated