# GitHub

This page says what the GitHub App does once a repository is connected to
an app, what deploys when, what it writes back on the commit, how to
disconnect, and how it stands against a workflow of your own
(`durable-sdk ci init`, the [CI/CD page](https://durablesdk.com/docs/hosting/ci-cd.md)).

## Connect

1. Open the app's **Settings** page and press **Connect a repository**.
   You land on GitHub's install page for the App; install it on your
   account or organization, choose the repositories it may read and
   authorize the App when GitHub asks (that authorization is how the
   platform knows the installation is yours; nothing of your account is
   kept).
2. GitHub sends you back to the Settings page. Pick the repository (a
   searchable list, fifty at a time) and the branch that deploys
   production: the select opens on the repository's default branch.
   Press **Connect**.

An installation stays with your organization: a second app's card lists
it as **Installed on <login> · Pick a repository**, so connecting it needs
no second install. An admin of the organization connects, changes the
branch and disconnects; a member may press **Deploy now**; a reader reads
the connection. The App reads the repository's contents and metadata and
writes checks and pull-request comments; nothing else.

The same connection over the API:

```http
GET    /apps/{slug}/repositories?installation={id}   the repositories an installation offers
POST   /apps/{slug}/repository  { installationId, repoId, defaultBranch? }
GET    /apps/{slug}/repository
PATCH  /apps/{slug}/repository  { defaultBranch }        the production branch, in place
POST   /apps/{slug}/repository/deploy                    the production branch at its head, now
DELETE /apps/{slug}/repository
```

The install itself needs a browser: the install page is GitHub's, and the
state that binds the flow to your app is minted when you press Connect
(it rides the install URL and a ten-minute cookie, so the return holds
whichever GitHub kept).

## What the build expects

A connected repository is built exactly as `durable-sdk deploy` builds an
upload: `pnpm install --frozen-lockfile` (falling back to a plain install
when the lockfile is stale), then `pnpm run build`. The tree needs a
`pnpm-lock.yaml` and a `build` script in its `package.json`; a tree
scaffolded by `durable-sdk init` has both. No variable is needed for the
App path; the app's own secrets come from **Secrets** as for any deploy.

## The card

Connected, the Repository card says `<owner/repo> · <branch> · installed
on <login>` and the newest deployment from the repository: its commit,
message, moment and state, with links to the deployment and to the check
run on GitHub; a failed one shows the platform's sentence and remedy.
Three doors beside it:

- **Deploy now** deploys the production branch at its head to production,
  as a push would; a push of the same commit lands on the same deployment.
- **Change branch** moves the production branch without disconnecting;
  the installation and the repository stay.
- **Disconnect** asks once ("Pushes deploy no more") and then clears the
  connection.

## What deploys when

| On the connected repository                    | What the platform does                                                                                                      |
| ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| a push to the production branch                | a production deployment: built, aliased, checked, promoted under the app's promotion rule (auto, or a person's press)       |
| a push to any other branch                     | a preview at `<app>-git-<branch>.durablesdk.com`, the branch's environment                                                  |
| a pull request opened, pushed to, reopened     | the same preview of its head commit, and one comment on the pull request with the preview's hostname, updated on every push |
| a pull request closed                          | the preview environment removed                                                                                             |
| a tag, a fork's pull request, a deleted branch | nothing; a deleted branch's preview is swept after the tier's preview days                                                  |

One commit on one branch is one deployment: a push and the pull request's
event for the same commit land on the same run. The tree is fetched by
the platform as the commit's archive, bounded as an upload is (100 MB
unpacked, 10 000 entries, a file at most 10 MB), and built exactly as
`durable-sdk deploy` builds an upload: the same states, the same
`deployments list|get|events`, the same `Deployment` with `source: "git"`
and `git: { sha, ref, repo, sender, prNumber }`.

The deployer on the row is `system:github`; the message names the pusher
or the pull request.

## The check and the comment

Every deployment from a push writes a check run named `durablesdk/deploy`
on the commit: `in_progress` while the build runs, then `success` with the
hostname or `failure` with the platform's own sentence (never a provider's
word), its **Details** link the deployment's page on the dashboard. Branch
protection may require it.

A pull request carries one comment, found by its marker and updated in
place on every push: the preview's hostname, or the failure sentence.

A check or a comment the platform could not write (the repository
unreachable, the installation suspended) does not fail the deployment:
the deployment stands as the dashboard shows it, and the run's ledger
names the step.

## Disconnect

**Disconnect** on the Settings page (behind its confirm), or
`DELETE /apps/{slug}/repository`: pushes deploy no more; the installation
stays, so the next app's card offers it under **Pick a repository** with
no second install. Uninstalling the App on GitHub disconnects every app
on that installation at once.

## Two shapes

| You want                                                        | Pick                                                                                                                                                                      |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| every push deployed, no workflow file, no key in the repository | the App: connect the repository and leave the workflow out                                                                                                                |
| your tests to gate production                                   | your own workflow: `durable-sdk ci init --deploy` with a `deploy` key, the production job behind `prove` ([CI/CD](https://durablesdk.com/docs/hosting/ci-cd.md)); leave the repository unconnected |
| both                                                            | connect the repository and keep the tests' jobs: the App deploys on the push, the check run reports beside your own                                                       |

A repository both connected and deploying from its own workflow deploys
twice; pick one.

## Errors

| Code                                | When                                                                  |
| ----------------------------------- | --------------------------------------------------------------------- |
| `plane.github.not_registered`       | the platform's owner has not registered the App yet                   |
| `plane.github.installation_unknown` | the installation is another organization's, or was uninstalled        |
| `plane.github.repo_unknown`         | the repository is not one the installation offers                     |
| `plane.github.not_connected`        | a read or a disconnect of an app with no repository                   |
| `plane.github.state`                | the connect flow's state is missing, forged or older than ten minutes |
| `plane.github.signature`            | a webhook whose signature does not verify                             |
| `plane.github.tarball_too_large`    | the commit's archive is over 100 MB                                   |
| `plane.github.check_failed`         | the check run or the comment could not be written                     |

Every code has its row in the [errors reference](https://durablesdk.com/docs/reference/api/errors.md).

---

Prompt for an agent:

```text
Read https://durablesdk.com/docs/hosting/github.md, then connect a GitHub repository to an app so every push deploys without a workflow of your own; run durable-sdk doctor --host before and after; a refused line is a refusal id: durable-sdk explain <id>
```
