# GitHub App

> Connect GitHub to Alphorn once and get pull request, issue, push, release, workflow, deployment, and security alert notifications (secret scanning, Dependabot, code scanning) from every selected repository - no per-repo webhooks. Includes the self-hosted GitHub App setup.

Source: https://docs.alphorn.dev/github-app/

With the GitHub App you connect a GitHub account or organization once and pick its repositories on GitHub. Events from all selected repositories arrive in one Alphorn webhook. You don't set up a webhook per repository, and repositories you add later (or all of them, if you choose **All repositories**) are covered automatically.

## Connect GitHub

1. Open **Webhooks**, click the arrow next to **Create webhook** and choose **GitHub repositories**. Only project owners and admins can create webhooks.
2. GitHub asks where to install the app. Pick your account or an organization, then **All repositories** or a selection.
3. GitHub asks you to authorize Alphorn. Alphorn uses this once to confirm that you own the installation, and doesn't store the token: an installation on a personal account must be yours, an installation on an organization needs an owner of that organization. Read access to some of its repositories isn't enough, because the connection receives events from all of them.
4. You land on the new webhook, named after the GitHub account (for example **GitHub (octocat)**). Link output channels there, as with any other webhook.

On the webhook page, choose which events become messages. Pull requests, reviews, review comments, issues, comments, secret scanning alerts, and security advisories are selected by default. Events you don't select are dropped before they are stored, so they don't count against your message quota.

| Group | Event | What triggers it |
|---|---|---|
| Code | Pushes | Commits pushed to a branch, tags pushed |
| | Branch or tag created | A branch or tag is created |
| | Branch or tag deleted | A branch or tag is deleted |
| | Releases | Published, edited, or deleted releases |
| | Commit comments | Comments on a commit |
| Pull requests | Pull requests | Opened, closed, merged, reopened, and other pull request actions |
| | Pull request reviews | A review is submitted, edited, or dismissed |
| | Pull request review comments | Comments on the diff of a pull request |
| Issues and discussions | Issues | Opened, closed, edited, labeled, and other issue actions |
| | Issue and pull request comments | Comments in the conversation of an issue or pull request |
| | Discussions | Discussions created, answered, closed, and other discussion actions |
| | Discussion comments | Comments on a discussion |
| CI/CD | Workflow runs | GitHub Actions workflow runs |
| | Deployments | Deployment status changes (success, failure, error, ...) |
| | Deployment approvals | A deployment waits for review, or a reviewer approves or rejects it |
| Security | Secret scanning alerts | A secret is detected, publicly leaked, reopened, or resolved |
| | Dependabot alerts | A vulnerable dependency is found, fixed, dismissed, or reintroduced |
| | Code scanning alerts | A code scanning alert is created, appears in a branch, is fixed, or dismissed |
| | Security advisories | A repository security advisory is reported or published |
| Community | Stars | Someone stars or unstars a repository |
| | Forks | Someone forks a repository |

### Priorities

Alphorn sets a priority (1-5) where the event calls for attention. All other events, including resolved, fixed, and dismissed alerts, carry no priority.

| Event | Priority |
|---|---|
| Secret scanning alert created, publicly leaked, or reopened | 5 |
| Dependabot alert created, reopened, or reintroduced | From the advisory severity: critical 5, high 4, medium 3, low 2 |
| Code scanning alert created, reopened, or appeared in a branch | From the security severity: critical 5, high 4, medium 3, low 2. Without one: error 4, warning 3, note 2 |
| Security advisory reported | 4 |
| Security advisory published | 3 |
| Deployment status failure or error | 4 |
| Deployment approval requested | 3 |
| Failed workflow run | 4 |

Code scanning and secret scanning alerts need GitHub Advanced Security on private repositories (they are free on public repositories). Dependabot alerts are free on all repositories. Secret values are never part of the notification.

Messages are formatted like any other GitHub webhook (see [Sources → GitHub](/sources#github)) and tagged with `github`, the event name, and the repository name. Use these tags to route per repository or event type, for example Tags **has any of** `my-repo` for one channel and `push` for another. See [Filtering](/filtering).

### Change repositories, disconnect

- **Repositories**: click **Manage repositories** on the webhook page, or change the installation on GitHub under **Settings → Applications → Installed GitHub Apps** (for organizations: the organization's settings). No change in Alphorn is needed.
- **Disconnect**: deleting the webhook in Alphorn removes the connection. The app stays installed on GitHub until you uninstall it there.
- **Uninstall on GitHub**: Alphorn removes the webhook automatically. Its message history is kept.

An installation can be connected to one project at a time.

## Self-hosted setup

On a self-hosted instance, you register your own GitHub App once. After that, every user of your instance can connect GitHub.

<Callout type="warn" title="GitHub must reach your instance">
GitHub delivers events over the internet to `BETTER_AUTH_URL`. An instance that is only reachable in your local network (for example a home lab behind NAT) needs a reverse proxy with a public hostname or a tunnel such as Cloudflare Tunnel. Use HTTPS.
</Callout>

### 1. Register the app

On GitHub, open **Settings → Developer settings → GitHub Apps → New GitHub App**. To let members of an organization manage it together, create it under the organization's settings instead.

Replace `https://alphorn.example.com` with your `BETTER_AUTH_URL`:

| Field | Value |
|---|---|
| GitHub App name | Any unique name, e.g. `Alphorn Example` |
| Homepage URL | `https://alphorn.example.com` |
| Callback URL | `https://alphorn.example.com/api/github/callback` |
| Request user authorization (OAuth) during installation | **Off** (Alphorn asks for authorization itself) |
| Setup URL | `https://alphorn.example.com/api/github/callback` |
| Redirect on update | On |
| Webhook: Active | On |
| Webhook URL | `https://alphorn.example.com/api/github/webhook` |
| Webhook secret | A random string, e.g. from `openssl rand -hex 32` |

**Repository permissions** (all **Read-only**): Actions, Code scanning alerts, Contents, Dependabot alerts, Deployments, Discussions, Issues, Metadata, Pull requests, Repository security advisories, Secret scanning alerts.

**Organization permissions**: Members **Read-only**. Alphorn uses it to check that the person connecting an organization's installation is an owner of that organization.

Leave everything else at **No access**.

**Subscribe to events**: Code scanning alert, Commit comment, Create, Delete, Dependabot alert, Deployment review, Deployment status, Discussion, Discussion comment, Fork, Issue comment, Issues, Pull request, Pull request review, Pull request review comment, Push, Release, Repository advisory, Secret scanning alert, Star, Workflow run.

If you add permissions to an existing GitHub App, every account that installed it must accept the new permissions on GitHub before those events arrive.

**Where can this GitHub App be installed?** Choose **Only on this account** if you only connect your own repositories, or **Any account** if other GitHub users or organizations on your instance should connect theirs.

Click **Create GitHub App**.

### 2. Collect the credentials

On the app's settings page:

- The **app slug** is the last part of the public link, e.g. `alphorn-example` in `https://github.com/apps/alphorn-example`.
- Copy the **Client ID**.
- Under **Client secrets**, click **Generate a new client secret** and copy it.

You don't need a private key.

### 3. Configure Alphorn

Add the values to your environment and restart Alphorn:

```bash title=".env"
GITHUB_APP_SLUG=alphorn-example
GITHUB_APP_CLIENT_ID=Iv23liExample
GITHUB_APP_CLIENT_SECRET=your-client-secret
GITHUB_APP_WEBHOOK_SECRET=the-webhook-secret-from-step-1
```

**GitHub repositories** appears in the menu next to **Create webhook** on the **Webhooks** page once all four are set.

If you route outgoing traffic through an egress proxy (`EGRESS_PROXY_URL`), allow `github.com` and `api.github.com`: Alphorn calls them while connecting.

These variables are separate from `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET`, which enable [sign-in with GitHub](/self-hosting#sso--oauth) and belong to a different app.

| Variable | Description |
|---|---|
| `GITHUB_APP_SLUG` | Slug of the GitHub App, from its public link |
| `GITHUB_APP_CLIENT_ID` | Client ID of the GitHub App |
| `GITHUB_APP_CLIENT_SECRET` | A client secret of the GitHub App |
| `GITHUB_APP_WEBHOOK_SECRET` | The webhook secret set on the GitHub App. Alphorn rejects deliveries without a valid `X-Hub-Signature-256` signature |

## Troubleshooting

| Message or symptom | Cause |
|---|---|
| **GitHub repositories** is missing from the menu | One of the four variables is unset, or you aren't an owner or admin of the project |
| "The GitHub connection expired or was started from another project" | More than 10 minutes passed between installing and authorizing, or you switched projects during the flow. Choose **GitHub repositories** again |
| "Your GitHub account doesn't own that installation" | The GitHub account you authorized isn't the account the app is installed on. Sign in on GitHub with that account |
| "Only owners of the GitHub organization can connect its installation" | Ask an owner of the organization to connect it. Self-hosted: also check that the app has the **Members** organization permission and that the organization accepted it |
| "This GitHub installation is already connected to another project" | Delete the webhook in the other project first |
| No messages arrive | Check **Recent Deliveries** on the app's **Advanced** settings page on GitHub. `401` means the webhook secret doesn't match `GITHUB_APP_WEBHOOK_SECRET`. `202` with `event not selected` means the event isn't selected on the webhook page |
