---
title: "What is CIHub"
description: "CIHub is a self-hosted merge queue for GitHub. It tests each pull request on top of the ones ahead of it and merges it only if the result passes."
canonical_url: "https://cihub.io/docs"
markdown_url: "https://cihub.io/docs.md"
---

# What is CIHub

CIHub is an open-source, self-hosted merge queue for GitHub. It keeps the target branch green with the CI you
already have, installs with one image and one Postgres, and explains each of its decisions.

## The problem a merge queue solves

Two pull requests pass CI on their own. You merge both. `main` is red, and nobody knows why: each one was
tested without the other.

CIHub makes that impossible. Approve a pull request, type `/cihub merge`, and go back to work. CIHub lines it up
behind the others, tests it together with everything that lands before it, and merges it only if the result
still passes.

## How the merge queue works

1. **Approve.** A pull request is approved and its checks are green.
2. **Queue.** Comment `/cihub merge`. CIHub tests it on top of everything ahead of it, alone or in a batch.
3. **Merge.** If that exact combination passes, CIHub merges it. If not, the pull request leaves the queue,
   with the reason on it.

## What CIHub does and does not do

- CIHub never runs your CI. It pushes a test branch and waits for the required statuses and check runs:
  GitHub Actions, Buildkite, CircleCI and Jenkins work without changes.
- The required checks are read on the target branch, never from the pull request, so that a pull request
  cannot weaken its own gate.
- One instance serves several GitHub organizations. Postgres is its only dependency.
- GitLab and Bitbucket are not supported.

## Status

CIHub is in active development (v0.x). The queue, its batches and its dashboard work; metrics, parallel queues
for monorepos and flaky test detection come next. Do not use it in production yet: its behavior, its
configuration and its data can change without notice from one version to the next.

## Next steps

<Cards>
  <Card title="Install CIHub" href="/docs/install" />
  <Card title="Use CIHub with a coding agent" href="/docs/agents" />
</Cards>


---
title: "Install CIHub"
description: "What a CIHub instance is made of, the two ways to run it (Docker on one machine, or Kubernetes with the Helm chart), and the steps to a first merged pull request in about 30 minutes."
canonical_url: "https://cihub.io/docs/install"
markdown_url: "https://cihub.io/docs/install.md"
---

# Install CIHub

CIHub is one container and a Postgres. It runs on any machine that runs containers: Kubernetes is one way, not a
requirement.

<ArchitectureDiagram />

## What you need

- A machine or a cluster that runs containers, `linux/amd64` or `linux/arm64`.
- A Postgres 17. The installation with Docker brings one.
- An HTTPS address that GitHub can reach, for example `https://cihub.example.com`: GitHub sends the events of your
  repositories there.
- The owner rights on a GitHub organization, to create the App of your CIHub.

## Choose how to run CIHub

<Cards>
  <Card title="Docker" href="/docs/install/docker">
    One machine, a VM or a server with Docker Compose: CIHub, Postgres and an HTTPS proxy in one file. The
    simplest way.
  </Card>
  <Card title="Kubernetes" href="/docs/install/kubernetes">
    The Helm chart: the migrations in a Job, as many replicas as you need, your Ingress or your Gateway.
  </Card>
</Cards>

Both run the same image, `ghcr.io/getcihub/server`, and take the same settings. You can start with Docker and move
to Kubernetes later: the data is in Postgres.

## The steps

<Steps>
<Step>

### Create the GitHub App

Register the App that receives the events of your repositories and acts on them: [Create the GitHub
App](/docs/install/github-app).

</Step>
<Step>

### Run CIHub

Start the server with its keys: with [Docker](/docs/install/docker) or on [Kubernetes](/docs/install/kubernetes).

</Step>
<Step>

### Install the App on your repositories

CIHub creates your organization by itself: [Install the App on your
repositories](/docs/install/github-app#install-the-app-on-your-repositories).

</Step>
<Step>

### Merge your first pull request

Protect the target branch, check your CI, then comment `/cihub merge`: [Merge your first pull
request](/docs/install/first-pull-request).

</Step>
</Steps>


---
title: "Create the GitHub App"
description: "Create the GitHub App of your CIHub instance, give its keys to CIHub, install it on your repositories, and check that GitHub reaches the instance."
canonical_url: "https://cihub.io/docs/install/github-app"
markdown_url: "https://cihub.io/docs/install/github-app.md"
---

# Create the GitHub App

Your CIHub instance talks to GitHub through a GitHub App that you own. The App receives the webhooks of your
repositories, gives CIHub the rights to test and merge pull requests, and signs people in to the dashboard. You
create it once, on GitHub.

## Before you start

- The HTTPS address of your instance, reachable from GitHub, for example `https://cihub.example.com`. The examples
  below write it `https://<your CIHub host>`.
- Owner rights on the GitHub organization that will own the App.

## Create the App

The App has three addresses on your instance. Most mistakes come from mixing them up:

<GithubAppUrlsDiagram />

Generate the webhook secret first:

```sh
openssl rand -hex 32
```

### Open the form

- For an organization: your profile picture → _Your organizations_ → _Settings_ next to the organization →
  _Developer settings_ → _GitHub Apps_ → **New GitHub App**.
- For a personal account: your profile picture → _Settings_ → _Developer settings_ → _GitHub Apps_ → **New GitHub
  App**.

On a GitHub Enterprise Server, the path is the same on your server.

### Fill in the identity and the sign-in

| Field                                                      | Value                                             | Why                                                                                        |
| ---------------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| **GitHub App name**                                        | Any free name, for example `Acme CIHub`           | Its bot writes the comments and the statuses: `acme-cihub[bot]`                            |
| **Homepage URL**                                           | `https://<your CIHub host>`                       | Shown on the page of the App                                                               |
| **Callback URL**                                           | `https://<your CIHub host>/auth/github/callback`  | Where GitHub sends a person back after the sign-in to the dashboard                        |
| **Expire user authorization tokens**                       | Checked (the default)                             | CIHub refreshes the token of each person                                                   |
| **Request user authorization (OAuth) during installation** | **Unchecked**                                     | Checked, GitHub would skip the Setup URL after an installation                             |
| **Enable Device Flow**                                     | Unchecked                                         | The command line `cihub` signs in through the dashboard, not through GitHub                |
| **Setup URL**                                              | `https://<your CIHub host>/auth/github/installed` | After an installation, GitHub sends the person to the repositories of the new organization |
| **Redirect on update**                                     | Checked                                           | The same after a change of the repositories of the installation                            |

### Fill in the webhook

| Field                | Value                                       |
| -------------------- | ------------------------------------------- |
| **Active**           | Checked                                     |
| **Webhook URL**      | `https://<your CIHub host>/webhooks/github` |
| **Webhook secret**   | The secret that you generated               |
| **SSL verification** | Enabled                                     |

### Set the permissions

Under _Repository permissions_:

| Permission          | Access         | What CIHub does with it                                                                                                      |
| ------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| **Actions**         | Read-only      | Show a check of GitHub Actions as running when a runner takes its job                                                        |
| **Administration**  | Read-only      | Read the rules of the branches, for their required checks and to [check your setup](/docs/branch-protection#check-the-setup) |
| **Checks**          | Read-only      | Read the checks of your CI on the test commits                                                                               |
| **Commit statuses** | Read and write | Write the statuses `CIHub Merge Queue (<branch>)` and `CIHub Conditions (<branch>)`                                          |
| **Contents**        | Read and write | Write the test branches, merge, read `.cihub.yaml`                                                                           |
| **Issues**          | Read and write | Labels and reactions on the pull requests                                                                                    |
| **Metadata**        | Read-only      | List the repositories (GitHub sets it)                                                                                       |
| **Pull requests**   | Read and write | Read the pull requests, open and close the draft pull requests of the tests, merge, comment                                  |

Under _Organization permissions_: **Members**, Read-only, to give each person the role that they have on GitHub.

Leave every other permission at _No access_.

### Subscribe to the events

Under _Subscribe to events_, check:

- **Branch protection rule**
- **Check run**
- **Check suite**
- **Issue comment**
- **Pull request**
- **Pull request review**
- **Push**
- **Repository**
- **Status**
- **Workflow job**

GitHub sends the events of the installation itself without a subscription.

### Keep the App private

Under _Where can this GitHub App be installed?_, choose **Only on this account**, then **Create GitHub App**.

Any account that installs your App gets an organization in your CIHub: a public App would let anyone use your
instance.

### Collect the keys of the App

On the page of the new App (_General_):

1. Note the **App ID** and the **Client ID**.
2. Under _Client secrets_, **Generate a new client secret**, and copy it: GitHub shows it once.
3. Under _Private keys_, **Generate a private key**: your browser downloads a `.pem` file.

Keep the private key, the client secret and the webhook secret in your secret store. The private key and the client
secret act as the App: whoever has them can act on every repository where the App is installed.

## Give the keys to CIHub

You now have five values: the App ID, the private key, the webhook secret, the Client ID and the client secret. Give
them to CIHub as [Run CIHub with Docker](/docs/install/docker) or [Run CIHub on
Kubernetes](/docs/install/kubernetes) shows, then come back here to install the App.

<GithubAppKeysDiagram />

| Value                    | Variable of the server                                                            |
| ------------------------ | --------------------------------------------------------------------------------- |
| App ID                   | `CIHUB_GITHUB_APP_ID`                                                             |
| Private key              | `CIHUB_GITHUB_PRIVATE_KEY_FILE` (a path), or `CIHUB_GITHUB_PRIVATE_KEY` (the PEM) |
| Webhook secret           | `CIHUB_GITHUB_WEBHOOK_SECRET`                                                     |
| Client ID                | `CIHUB_GITHUB_CLIENT_ID`                                                          |
| Client secret            | `CIHUB_GITHUB_CLIENT_SECRET`                                                      |
| GitHub Enterprise Server | `CIHUB_GITHUB_URL`                                                                |

The Client ID and the client secret turn on the sign-in to the dashboard, with the public address
(`CIHUB_HTTP_PUBLIC_URL`) and a sealing key (`CIHUB_DATABASE_SECRET`, at least 32 bytes, which seals the GitHub tokens
of the people who sign in). Without them, only the API tokens work. `cihub-server start` stops at startup and names
the value that is missing.

## Install the App on your repositories

On the page of the App: **Install App** → your organization → **Only select repositories** (or _All repositories_) →
**Install**.

GitHub then sends you to the Setup URL: sign in to the dashboard, and it opens the repositories of the new
organization. You create nothing else: CIHub creates the organization, named after the login of the account, and the
first `/cihub merge` on a branch creates its queue. To add or remove repositories later, change the installation on
GitHub (_Settings → GitHub Apps → Configure_ in the organization); CIHub reads the change.

## Check that GitHub reaches CIHub

1. On the page of the App: _Advanced_ → _Recent Deliveries_. The `installation` delivery has a green mark: CIHub
   answered it.
2. The dashboard lists the repositories that you selected.
3. A comment `/cihub merge` on an approved, green pull request gets a 👍 reaction, then the comment of CIHub.

| Symptom                                                    | Cause                                                    | Fix                                                                                                     |
| ---------------------------------------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| The deliveries fail with a timeout or a connection error   | GitHub cannot reach the instance                         | Check the DNS, the TLS certificate and the route to `/webhooks/github` from outside your network        |
| The deliveries fail with an error status from CIHub        | The webhook secret differs between the App and CIHub     | Set the same secret in both, then **Redeliver** the failed deliveries                                   |
| The sign-in comes back to the sign-in page with an error   | Callback URL, client ID, client secret or public address | Compare the Callback URL with `<public address>/auth/github/callback`, and the client keys with the App |
| After the installation, GitHub does not open the dashboard | The Setup URL is empty, or the OAuth box is checked      | Set the Setup URL, uncheck _Request user authorization (OAuth) during installation_                     |
| Nothing happens on the pull requests of a repository       | The repository is not in the installation                | Add it to the installation of the App                                                                   |

## Change the permissions later

When a new version of CIHub needs a new permission or event, change it on the page of the App. GitHub then asks an
owner of each organization to accept the new permissions (_Settings → GitHub Apps_ in the organization): until they
do, the installation keeps the old ones.

From the release after 0.3.0, the App needs **Actions**, Read-only, and the **Workflow job** event: without them, a
check of GitHub Actions shows _queued_ until it ends, never _running_. On an older App, add them on the page of the App, then accept them in each organization.


---
title: "Run CIHub with Docker"
description: "Run CIHub, its Postgres and an HTTPS proxy on one machine with Docker Compose, then update it."
canonical_url: "https://cihub.io/docs/install/docker"
markdown_url: "https://cihub.io/docs/install/docker.md"
---

# Run CIHub with Docker

One machine with Docker runs the whole instance: Postgres, a one-shot service that applies the migrations, CIHub,
and Caddy, which gets a TLS certificate for your address.

You need:

- A machine with Docker and Docker Compose, which GitHub can reach on the ports 80 and 443.
- A DNS name that points to it, for example `cihub.example.com`.
- The App of your CIHub and its keys: [Create the GitHub App](/docs/install/github-app).

## Write the files

In a new directory, write four files.

`compose.yaml`:

```yaml title="compose.yaml"
services:
  postgres:
    image: postgres:17
    restart: unless-stopped
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      CIHUB_DATABASE_PASSWORD: ${CIHUB_DATABASE_PASSWORD}
    volumes:
      - postgres:/var/lib/postgresql/data
      - ./create-cihub-database.sh:/docker-entrypoint-initdb.d/create-cihub-database.sh:ro
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 5s

  migrate:
    image: ghcr.io/getcihub/server:0.2
    command: ["migrate", "up"]
    environment:
      CIHUB_DATABASE_URL: postgres://cihub:${CIHUB_DATABASE_PASSWORD}@postgres:5432/cihub
    depends_on:
      postgres:
        condition: service_healthy

  cihub:
    image: ghcr.io/getcihub/server:0.2
    restart: unless-stopped
    environment:
      CIHUB_DATABASE_URL: postgres://cihub:${CIHUB_DATABASE_PASSWORD}@postgres:5432/cihub
      CIHUB_DATABASE_SECRET: ${CIHUB_DATABASE_SECRET}
      CIHUB_HTTP_PUBLIC_URL: https://${CIHUB_HOST}
      CIHUB_GITHUB_APP_ID: ${CIHUB_GITHUB_APP_ID}
      CIHUB_GITHUB_PRIVATE_KEY_FILE: /run/secrets/github-app
      CIHUB_GITHUB_WEBHOOK_SECRET: ${CIHUB_GITHUB_WEBHOOK_SECRET}
      CIHUB_GITHUB_CLIENT_ID: ${CIHUB_GITHUB_CLIENT_ID}
      CIHUB_GITHUB_CLIENT_SECRET: ${CIHUB_GITHUB_CLIENT_SECRET}
    secrets:
      - github-app
    depends_on:
      migrate:
        condition: service_completed_successfully

  caddy:
    image: caddy:2
    restart: unless-stopped
    command: caddy reverse-proxy --from ${CIHUB_HOST} --to cihub:8080
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - caddy:/data
    depends_on:
      - cihub

secrets:
  github-app:
    file: ./github-app.private-key.pem

volumes:
  postgres:
  caddy:
```

`create-cihub-database.sh`, which Postgres runs once, at its first start. CIHub refuses to connect as a
superuser: it gets its own role, which owns its database.

```sh title="create-cihub-database.sh"
#!/bin/sh
set -e
psql -v ON_ERROR_STOP=1 --username postgres <<SQL
CREATE ROLE cihub LOGIN PASSWORD '${CIHUB_DATABASE_PASSWORD}';
CREATE DATABASE cihub OWNER cihub;
SQL
```

`.env`, with your address, the passwords and the sealing key, generated once, then the keys of the
[GitHub App](/docs/install/github-app#give-the-keys-to-cihub):

```sh
cat > .env <<EOF
CIHUB_HOST=cihub.example.com
POSTGRES_PASSWORD=$(openssl rand -hex 16)
CIHUB_DATABASE_PASSWORD=$(openssl rand -hex 16)
CIHUB_DATABASE_SECRET=$(openssl rand -hex 32)
CIHUB_GITHUB_APP_ID=<App ID>
CIHUB_GITHUB_WEBHOOK_SECRET=<webhook secret>
CIHUB_GITHUB_CLIENT_ID=<Client ID>
CIHUB_GITHUB_CLIENT_SECRET=<client secret>
EOF
chmod 600 .env
```

`github-app.private-key.pem`: the private key of the App, which GitHub downloaded, under this name. The container
reads it as the user 65532:

```sh
chmod +x create-cihub-database.sh
chmod 644 github-app.private-key.pem
```

## Start CIHub

```sh
docker compose up -d
docker compose ps
```

`migrate` ends with the exit code 0, then `cihub` starts. Open `https://cihub.example.com`: the dashboard asks you to
sign in with GitHub.

The `.env` file and the private key are secrets: keep them out of a repository, and back them up with the volume
`postgres`. A lost `CIHUB_DATABASE_SECRET` signs every person out; the queues keep their data.

## Create an API token

Once the App is installed on your organization, a script or a CI that calls the API needs a token of the
organization. The command prints it once:

```sh
docker compose run --rm cihub token create --org <login of the organization>
```

## Update CIHub

Change the tag of the two `image:` lines (`0.2` follows the fixes of the version 0.2), then:

```sh
docker compose pull
docker compose up -d
```

`migrate` applies the migrations of the new version before `cihub` starts again.

## Go back to an older version

When the older version has fewer migrations, the running version reverts its own first. `--to` takes the newest
migration of the older version: the last file of `migrations/` in its tag.

```sh
docker compose run --rm cihub migrate down --to <version>
```

Then put the older tag back on the two `image:` lines and run `docker compose up -d`. The data of the reverted
migrations is lost.

## Without Caddy

If the machine already has a proxy or a load balancer that terminates TLS, remove the service `caddy`, publish the
port of CIHub to that proxy, and route your address to it:

```yaml
cihub:
  ports:
    - "127.0.0.1:8080:8080"
```

The proxy sends every path to CIHub: the dashboard, `/api`, `/auth` and `/webhooks/github`.

## Next

[Install the App on your repositories](/docs/install/github-app#install-the-app-on-your-repositories), then [merge
your first pull request](/docs/install/first-pull-request).


---
title: "Run CIHub on Kubernetes"
description: "Install CIHub on a Kubernetes cluster with its Helm chart, get a Postgres for it (CloudNativePG, a managed service or your own server), expose it, and update it."
canonical_url: "https://cihub.io/docs/install/kubernetes"
markdown_url: "https://cihub.io/docs/install/kubernetes.md"
---

# Run CIHub on Kubernetes

The Helm chart installs a Job that applies the migrations at each install and upgrade, a Deployment of identical
replicas, a Service, and, if you want, an Ingress or a Gateway API HTTPRoute.

You need:

- A Kubernetes cluster (1.25 or later) and Helm.
- A Postgres 17: [the next section](#get-a-postgres) gives three ways.
- The App of your CIHub and its keys: [Create the GitHub App](/docs/install/github-app).

## Get a Postgres

CIHub needs a database that it owns, through a role that is neither a superuser nor `BYPASSRLS`. CIHub isolates the
organizations with the row level security of Postgres, which such a role ignores: CIHub refuses to start with one.
You give CIHub the URL of the database in a Secret, under the key `uri`.

<Tabs items={["CloudNativePG", "A managed Postgres", "Your own server"]}>
<Tab value="CloudNativePG">

With the [CloudNativePG](https://cloudnative-pg.io) operator in the cluster, one resource creates the database, its
owner, which is not a superuser, and the Secret `cihub-db-app`, whose key `uri` holds the URL:

```yaml title="cihub-db.yaml"
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cihub-db
spec:
  instances: 2
  imageName: ghcr.io/cloudnative-pg/postgresql:17
  bootstrap:
    initdb:
      database: cihub
      owner: cihub
  storage:
    size: 10Gi
```

```sh
kubectl apply -f cihub-db.yaml
```

The Secret of the database is `cihub-db-app`: you create none.

</Tab>
<Tab value="A managed Postgres">

On Amazon RDS, Cloud SQL, Azure Database for PostgreSQL or another service, create a Postgres 17 with a database
`cihub` and a user `cihub` that owns it, from the console of the service or your infrastructure code. Do not give
CIHub the administrator of the instance.

```sh
kubectl create secret generic cihub-db-app \
  --from-literal=uri='postgres://cihub:<password>@<host>:5432/cihub'
```

</Tab>
<Tab value="Your own server">

On a Postgres 17 that the cluster reaches, as a superuser:

```sql
CREATE ROLE cihub LOGIN PASSWORD '<password>';
CREATE DATABASE cihub OWNER cihub;
```

```sh
kubectl create secret generic cihub-db-app \
  --from-literal=uri='postgres://cihub:<password>@<host>:5432/cihub'
```

</Tab>
</Tabs>

## Create the Secrets

One Secret holds the keys of the App, and one the sealing key, at least 32 bytes, which seals the GitHub tokens of
the people who sign in. With the [keys of the App](/docs/install/github-app#give-the-keys-to-cihub):

```sh
kubectl create secret generic cihub-github \
  --from-file=private-key.pem=<path to the private key> \
  --from-literal=webhook-secret='<webhook secret>' \
  --from-literal=client-secret='<client secret>'
kubectl create secret generic cihub-sealing \
  --from-literal=secret="$(openssl rand -hex 32)"
```

Keep the sealing key: a new one signs every person out.

## Install the chart

```sh
helm install cihub oci://ghcr.io/getcihub/charts/cihub \
  --set database.existingSecret=cihub-db-app \
  --set database.secretExistingSecret=cihub-sealing \
  --set github.existingSecret=cihub-github \
  --set github.appId='<App ID>' \
  --set github.clientId='<Client ID>' \
  --set publicUrl=https://cihub.example.com \
  --set replicas=2
```

- `publicUrl`, `github.clientId` and the client secret turn on the sign-in to the dashboard. Without them, only the
  API tokens work.
- Two replicas keep one that receives the webhooks while a pod or a node is lost. The replicas share the work through
  Postgres; each one opens up to `database.poolSize` connections (10).
- For a GitHub Enterprise Server, add `--set github.url=https://<your GitHub server>`.

The migration Job runs first, then the pods start. Check them:

```sh
kubectl get pods -l app.kubernetes.io/instance=cihub
helm test cihub
```

`helm test` posts an unsigned delivery to the Service: CIHub must refuse it.

## Expose CIHub

GitHub and the people reach CIHub on one address, with every path: the dashboard, `/api`, `/auth` and
`/webhooks/github`. With an Ingress:

```yaml title="values.yaml"
ingress:
  enabled: true
  className: nginx
  hosts:
    - host: cihub.example.com
      paths:
        - path: /
          pathType: Prefix
  tls:
    - hosts:
        - cihub.example.com
      secretName: cihub-tls
```

Or with a Gateway: `httpRoute.enabled: true`, with `httpRoute.hostnames` and `httpRoute.parentRefs`.

The dashboard keeps a stream open on `/api/v1/orgs/<org>/stream`: the proxy must not buffer it, and must keep it open
past 15 seconds without data. Serve HTTP/2 to the browsers.

Every value of the chart is in [`helm/cihub/README.md`](https://github.com/getcihub/cihub/blob/main/helm/cihub/README.md).

## Create an API token

Once the App is installed on your organization, a script or a CI that calls the API needs a token of the
organization. The command prints it once:

```sh
kubectl exec deploy/cihub -- cihub-server token create --config /etc/cihub/server.yaml --org <login of the organization>
```

## Update CIHub

```sh
helm upgrade cihub oci://ghcr.io/getcihub/charts/cihub --reuse-values
```

The migration Job applies the migrations of the new version before the pods roll.

## Go back to an older version

When the older version has fewer migrations, the running version reverts its own first, then Helm rolls back.
`--to` takes the newest migration of the older version: the last file of `migrations/` in its tag.

```sh
kubectl exec deploy/cihub -- cihub-server migrate down --config /etc/cihub/server.yaml --to <version>
helm rollback cihub
```

The data of the reverted migrations is lost, and the pods of the newer version fail until the rollback ends.

## Next

[Install the App on your repositories](/docs/install/github-app#install-the-app-on-your-repositories), then [merge
your first pull request](/docs/install/first-pull-request).


---
title: "Merge your first pull request"
description: "The last steps of the installation, protect the target branch, check that your CI runs on the tests of the queue, then submit a first pull request and follow it to the merge."
canonical_url: "https://cihub.io/docs/install/first-pull-request"
markdown_url: "https://cihub.io/docs/install/first-pull-request.md"
---

# Merge your first pull request

CIHub runs and the App is installed on your repositories. You do not create a queue: the first `/cihub merge` on a
pull request of the default branch creates it, with the default settings.

<Steps>
<Step>

### Protect the target branch

Two rulesets on the target branch make every merge go through the queue: one that restricts the updates, with the
App in its bypass list in the mode **Exempt**, and one that holds the rules of a pull request. Turn off "Require
branches to be up to date before merging". [Protect the target branch](/docs/branch-protection) gives each click.

<RulesetsDiagram />

</Step>
<Step>

### Check that your CI runs on the tests

By default, each test of the queue opens a draft pull request: a workflow on `pull_request` runs on it without a
change, if it does not skip draft pull requests. The test waits for the required checks of the rules of the branch.
[Run your CI on the tests of the queue](/docs/ci) covers GitHub Actions and the other CIs.

</Step>
<Step>

### Submit a pull request

Choose a pull request of the default branch that is approved and whose checks pass, and comment:

```text
/cihub merge
```

CIHub adds a 👍 reaction, then a comment that it keeps up to date, and the status `CIHub Merge Queue (main)`:

<PrCommentPreview />

The pull request merges when its test passes. If it waits, the comment says why: [The life of a pull request in the
queue](/docs/pull-requests).

</Step>
<Step>

### Follow the queue

The link _Open in CIHub_ of the comment opens the pull request in the dashboard, with its queue. From a terminal, the
command line shows the same:

```sh
cihub auth login --hostname cihub.example.com   # approve the code in the dashboard
cihub queue status
```

[Install the command line](/docs/install/cli) first.

In a CI, set `CIHUB_HOST` and `CIHUB_TOKEN`, with an [API token](/docs/install/docker#create-an-api-token) of the
organization.

</Step>
</Steps>

## Next

<Cards>
  <Card title="Write your .cihub.yaml" href="/docs/configuration">
    Queue conditions, priorities, several branches: a queue works without a file, and the file changes its
    behavior.
  </Card>
  <Card title="Choose a strategy" href="/docs/strategies">
    Test several pull requests at the same time, or in batches, when the queue gets busy.
  </Card>
</Cards>


---
title: "Install the command line"
description: "Install cihub, the command line of CIHub, on Linux or macOS, to drive the queues of an instance from a terminal or a CI."
canonical_url: "https://cihub.io/docs/install/cli"
markdown_url: "https://cihub.io/docs/install/cli.md"
---

# Install the command line

`cihub` is one binary. It signs in to an instance (`cihub auth login`) and drives its queues (`cihub queue …`).

<Callout title="From the release after 0.2.1">
  Each release attaches the binaries below from the next release of CIHub. Until then, build `cihub` with
  Cargo, as in the last tab.
</Callout>

<Tabs items={["Linux x86_64", "Linux arm64", "macOS (Apple silicon)", "From the sources"]}>
<Tab value="Linux x86_64">

```sh
curl -fsSL https://github.com/getcihub/cihub/releases/latest/download/cihub-x86_64-unknown-linux-musl.tar.gz | tar -xz
sudo install cihub /usr/local/bin/
```

</Tab>
<Tab value="Linux arm64">

```sh
curl -fsSL https://github.com/getcihub/cihub/releases/latest/download/cihub-aarch64-unknown-linux-musl.tar.gz | tar -xz
sudo install cihub /usr/local/bin/
```

</Tab>
<Tab value="macOS (Apple silicon)">

```sh
curl -fsSL https://github.com/getcihub/cihub/releases/latest/download/cihub-aarch64-apple-darwin.tar.gz | tar -xz
sudo install cihub /usr/local/bin/
```

</Tab>
<Tab value="From the sources">

With Rust installed, on any platform:

```sh
cargo install --locked --git https://github.com/getcihub/cihub cihub-cli
```

</Tab>
</Tabs>

Check it:

```sh
cihub --version
```

The Linux binaries are static: they run on any distribution. Each archive has its SHA-256 checksum next to it on the
page of the release, `cihub-<target>.tar.gz.sha256`.

## Next

- [Sign in to an instance](/docs/install/first-pull-request#follow-the-queue) with `cihub auth login`.


---
title: "The life of a pull request in the queue"
description: "The states of a pull request in a CIHub queue, what moves it from one state to the next, and what CIHub shows on GitHub at each step."
canonical_url: "https://cihub.io/docs/pull-requests"
markdown_url: "https://cihub.io/docs/pull-requests.md"
---

# The life of a pull request in the queue

A pull request enters the queue of its base branch when someone submits it ([Submit, cancel and restart a pull
request](/docs/commands)). From there, CIHub tells it where it stands on the pull request itself: you never need to
open the dashboard to know why a pull request waits.

## What CIHub writes on a pull request

<PrCommentPreview />

| Where                                            | What it says                                                                                                                                                                                                                                                                                |
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| One comment, edited in place                     | The state and its reason, what blocks the pull request, the failing checks, the pull requests it is tested with, a link to its test (the draft pull request of the run, or the test commit), a link to its page in the dashboard, its history in the queue, and the commands that apply now |
| The commit status `CIHub Merge Queue (<branch>)` | `pending` while the pull request waits or is tested, `success` once its tests passed, `failure` when it failed, `error` when it was cancelled. Its link opens the page of the pull request in the dashboard                                                                                 |
| The commit status `CIHub Conditions (<branch>)`  | On every open pull request of a branch with a queue, submitted or not: whether it would enter the queue now. `success` reads "Ready for the queue"; `pending` means that a required check still runs; `failure` gives the first reason                                                      |
| Labels, if you turn them on                      | `cihub:queued`, `cihub:testing` and `cihub:failed`, with `state_labels_enabled: true` in `.cihub.yaml`                                                                                                                                                                                      |

When a pull request is opened out of draft on a branch with a queue, the comment welcomes it with a checkbox that
submits it. Do not make `CIHub Conditions (<branch>)` a required check: a pull request whose conditions pass would
then merge outside the queue.

## The states of a pull request

The comment shows a state line; the API, the command line and the webhooks use the code of the state.

<StatesDiagram />

| State             | The comment shows                                               | What happens                                                                                            |
| ----------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `not_ready`       | ⏳ **Waiting** · not in the queue for `main` yet                | Submitted, but it cannot enter the line yet: a review, a check or a condition is missing                |
| `pending`         | 🕓 **Queued** · position 3 in the queue for `main`              | In the line, it waits for room among the tests that run                                                 |
| `testing`         | 🧪 **Testing** · position 2 in the queue for `main`             | Its test runs, alone or in a batch, on top of the target branch and of every pull request ahead of it   |
| `pending_failure` | ⚠️ **Tests failed** · waiting for the PRs ahead before it fails | Its test failed; the queue waits for the pull requests ahead of it to know whether the cause is its own |
| `tests_passed`    | 🚀 **Tests passed** · merging into `main`                       | Its test passed; it merges as soon as the pull requests ahead of it merged                              |
| `merged`          | ✅ **Merged** into `main` by the queue                          | The queue merged it, as its own commit, with the `merge_method` of the queue                            |
| `failed`          | ❌ **Failed** · _the reason_                                    | It left the queue; submit it again after a fix                                                          |
| `cancelled`       | ⚪ **Cancelled** · _the reason_                                 | It left the queue without a fault of its tests                                                          |

The status `CIHub Merge Queue (<branch>)` says the same in short: "Testing, position 2", "Failed: a required check
failed".

`merged`, `failed` and `cancelled` are final: a pull request that left the queue enters it again only with a new
submission.

## Why a pull request waits to enter the line

A submitted pull request stays `not_ready` while GitHub would refuse to merge it, or while it does not meet the
`queue_conditions` of the queue. The comment says what is missing:

| The comment says                                    | What to do                                                                                                   |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| 1 of 2 required approvals                           | Get the reviews that the rules of the branch require                                                         |
| a review asks for changes                           | Address the review, then ask for a new one                                                                   |
| the required check `build` failed                   | Fix the pull request; the check runs again on its new commit                                                 |
| the required check `build` has not reported         | The check never ran on this commit: see [Run your CI on the tests of the queue](/docs/ci)                    |
| the required check `build` is queued, or is running | Nothing: the pull request enters the line when the check passes                                              |
| the branch is behind its base                       | The rules of the branch ask that a pull request be up to date: [turn that rule off](/docs/branch-protection) |
| the branch conflicts with its base                  | Merge or rebase the base branch into the pull request                                                        |
| the queue conditions `labels: ready` are not met    | Meet the `queue_conditions` of `.cihub.yaml`                                                                 |
| the SCM does not say yet why the PR is blocked      | Nothing: GitHub computes the mergeability later, and CIHub reads it again                                    |

The conditions count only before the pull request enters the line: a condition that becomes false later does not
take it out. A pull request that stays `not_ready` for 7 days (`not_ready_timeout_hours: 168`) is cancelled.

## How the test of a pull request decides

CIHub never merges what it did not test. For each test, it builds a commit that holds the head of the target branch,
every pull request ahead in the line, and the pull requests of the test, on a branch named
`cihub-merge/pr-<number>/<run id>`. Your CI tests that commit ([Run your CI on the tests of the
queue](/docs/ci)).

<TestCommitDiagram />

- The test **passes** when every required check concludes with `success`, `neutral` or `skipped`.
- The test **fails** at the first required check that concludes otherwise.
- The test **times out** after `testing_timeout_minutes` (300 by default), for example when a required check never
  reports.

When a test fails, the pull request moves to `pending_failure` and the queue waits for the pull requests ahead of
it. If one of them fails, the cause was there: the pull request is tested again without it. If they all merge, the
fault is the pull request's own: the queue first runs its test again, once by default (`failure_budget.retries`),
because one failure can be a flaky test. A failed batch is split in two to find the pull request that broke it
([Choose a strategy](/docs/strategies)).

## What tests a pull request again

A test is valid only while the commit that it tested is still the one that would land. The queue starts the test
of a pull request again, and the comment gives the reason, when:

- a push outside the queue changed the target branch;
- a PR ahead in the queue failed, was cancelled, or was merged outside the queue;
- a PR of the same batch left the queue;
- an urgent PR went to the front of the queue;
- a user restarted the tests (`/cihub restart`).

## What takes a pull request out of the queue

| The status says                                                          | Cause                                                                                                        |
| ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
| Cancelled: the PR received a new commit after its submission             | A push on the pull request. With `resubmit_on_push: true`, the queue submits it again at the end of the line |
| Cancelled: the base branch of the PR changed                             | The pull request now targets another branch, which has its own queue                                         |
| Cancelled: the PR became a draft                                         | Mark it ready for review, then submit it again                                                               |
| Cancelled: the PR was closed                                             | Reopen it, then submit it again                                                                              |
| Cancelled: the label that submitted the PR was removed                   | The submission label was removed                                                                             |
| Cancelled: a user asked for it                                           | `/cihub cancel`, the command line or the dashboard                                                           |
| Failed: a required check failed                                          | The test failed after its retries, and the pull requests ahead of it merged                                  |
| Failed: the PR conflicts with the target branch or with a PR ahead of it | Update the pull request once the other one merged                                                            |
| Failed: the tests took longer than the time limit                        | See [Troubleshooting](/docs/troubleshooting)                                                                 |
| Failed: branch protection refused the merge                              | See [Troubleshooting](/docs/troubleshooting)                                                                 |
| Failed: the PR changed between its tests and its merge                   | A push between the test and the merge; submit it again                                                       |

The full list of reasons, with their codes, is the `Reason` schema of the [API](/openapi/v1.json).


---
title: "Submit, cancel and restart a pull request"
description: "Submit a pull request to the queue from a comment, a label, the checkbox of CIHub, the command line or the dashboard; give it a priority; cancel it or restart its tests; pause a queue."
canonical_url: "https://cihub.io/docs/commands"
markdown_url: "https://cihub.io/docs/commands.md"
---

# Submit, cancel and restart a pull request

A pull request enters the queue of its base branch. You do not create a queue: the first submission on the default
branch of the repository, or on a branch that `.cihub.yaml` serves, creates it.

## Who can run a command

A command needs the `write` permission on the repository. The queue answers each command on the pull request:

- a 👍 reaction on the comment when it accepts the command;
- a comment that quotes the command and gives the cause when it refuses it:
  `@octocat, the queue refused this command: <cause>`.

The queue accepts a submission only for an open pull request that is not a draft.

## Submit a pull request

Any of these submits the pull request, with the same effect:

| From                          | How                                                                                                                            |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| A comment on the pull request | `/cihub merge`                                                                                                                 |
| The comment of CIHub          | Check the box of the welcome comment                                                                                           |
| A label                       | Add the label `cihub-merge-queue-submit` (`label_commands.enqueue_label` in `.cihub.yaml`). Removing it cancels the submission |
| The command line              | `cihub queue merge 123`, in a clone of the repository                                                                          |
| The dashboard                 | **Submit a pull request** on the page of the queue                                                                             |
| The API                       | `POST /api/v1/orgs/{org}/repos/{repo}/prs/{number}/submit`, with a token of the organization                                   |

A submitted pull request first waits until it meets the rules of its branch and the `queue_conditions` of the queue
([The life of a pull request in the queue](/docs/pull-requests)): you can submit it before its review or its checks
end.

## Give a pull request a priority

```text
/cihub merge --priority=urgent
/cihub merge --priority=high --no-batch
/cihub merge --profile=dependencies
```

| Option              | Effect                                                                                                                                |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `--priority=urgent` | Goes to the front of the queue, ahead of the tests that run, which start again behind it. For a fix that cannot wait                  |
| `--priority=high`   | Goes behind the tests that run, ahead of every `medium` and `low` pull request                                                        |
| `--priority=medium` | The default                                                                                                                           |
| `--priority=low`    | Behind every other pull request                                                                                                       |
| `--priority=0-255`  | A number: the smallest goes first. `urgent` is 0, `high` 10, `medium` 100, `low` 200. Only 0 interrupts the tests that run            |
| `--no-batch`        | The pull request is tested alone, never in a batch                                                                                    |
| `--profile=<name>`  | Takes the settings of a profile of the queue in `.cihub.yaml`, instead of the first profile whose `conditions` the pull request meets |

Without `--priority`, the first rule of `priority_rules` in `.cihub.yaml` that the pull request meets gives its
priority. The command line takes the same options: `cihub queue merge 123 -p urgent --no-batch`.

## Cancel a submission

```text
/cihub cancel
```

Or `cihub queue cancel 123`, the dashboard, or the removal of the submission label. The pull request leaves the queue;
the pull requests behind it are tested again without it.

## Restart the tests of a pull request

```text
/cihub restart
```

Or `cihub queue restart 123`. It applies to a pull request whose test runs or failed and waits
(`testing`, `pending_failure`): the queue runs its test again, for example after a fix of the CI. A pull request that
left the queue needs a new submission instead.

## Pause, drain and resume a queue

| Command              | Effect                                                                                                                  |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `cihub queue pause`  | No new test and no merge. The queue keeps its order, and a submission waits for the resume. For an incident of the CI   |
| `cihub queue drain`  | The pull requests in the queue finish; a new submission is cancelled with "the queue is draining and accepts no new PR" |
| `cihub queue resume` | The queue tests and merges again                                                                                        |

The dashboard has the same actions on the page of the queue, and shows who paused it. These commands act on the
queue of the default branch; add `--branch release/2.0` for another one.

## Follow the queue from the command line

```sh
cihub queue status        # the queue of the default branch
cihub queue status 123    # one pull request: its state, its reason, its position
cihub queue watch 123     # follows the pull request until it merges or fails
cihub queue watch         # follows the queue, until Ctrl-C
cihub queue graph         # the pull requests in the queue, and what each one is tested on top of
```

In a terminal, the commands write a table with colors; in a pipe, the rows alone, separated by tabs, for a script.
`--json` writes what the API gives. `NO_COLOR=1` turns the colors off. `cihub queue watch 123` ends with the pull
request: exit code 0 when it merges, 1 when it fails or is cancelled, so that a CI job can wait for the merge:

```sh
cihub queue merge 123 && cihub queue watch 123
```

Every `cihub queue` command finds the repository from the `origin` remote of git; `--repo acme/web` names another
one. [Install the command line](/docs/install/cli), then sign in with `cihub auth login`.

## Turn off a way to submit

In `.cihub.yaml`, on a queue or in `defaults`:

```yaml
commands_enabled: false # the comment commands and the checkbox
label_commands:
  enabled: false # the submission label
```


---
title: "Write your .cihub.yaml"
description: "Change the behavior of a queue or add queues with the .cihub.yaml file of the repository; write it by hand with the JSON Schema, or with an assistant."
canonical_url: "https://cihub.io/docs/configuration"
markdown_url: "https://cihub.io/docs/configuration.md"
---

# Write your .cihub.yaml

A queue works without a file: the first `/cihub merge` on the default branch creates its queue with the default
settings. `.cihub.yaml`, at the root of the repository, changes the behavior of a queue, adds queues on other
branches, and sets who goes first.

CIHub reads the file on the head of the target branch, never on a pull request: a pull request cannot loosen its own
gate. A change of the file applies once it merges. The file can also be `.cihub.yml`, `.cihub/config.yaml` or
`.cihub/config.yml`, but only one of them: with two, the configuration is in error.

## Start the file

The first line declares the [JSON Schema](/schema/config/v1.json): your editor then completes each key and shows an
error before you commit.

```yaml title=".cihub.yaml"
# yaml-language-server: $schema=https://cihub.io/schema/config/v1.json
version: 1
```

Editors with a YAML language server, such as VS Code with its YAML extension, read this line.

## A complete example

```yaml title=".cihub.yaml"
# yaml-language-server: $schema=https://cihub.io/schema/config/v1.json
version: 1

# Settings and conditions of every queue, unless a queue sets its own.
defaults:
  queue_conditions:
    draft: false
    labels:
      none:
        - do-not-merge

queues:
  - branch: main
    strategy: batched
    batching:
      size: 3
      max_wait_minutes: 1
    # The checks that the test of the queue must pass, in addition to those of the rules of the branch.
    merge_conditions:
      checks:
        success:
          - Build Success
    # A kind of pull request with its own settings, in the same queue.
    profiles:
      - name: dependencies
        conditions:
          author: renovate[bot]
        batching:
          size: 10

  # Each release branch gets its own queue.
  - branch: release/*
    strategy: sequential

# The first rule that a pull request meets gives its priority; /cihub merge --priority wins.
priority_rules:
  - name: hotfixes
    conditions:
      labels:
        - hotfix
    priority: urgent
  - name: dependencies
    conditions:
      author: renovate[bot]
    priority: low
```

| Key                | What it does                                                                                               |
| ------------------ | ---------------------------------------------------------------------------------------------------------- |
| `queues`           | One entry per branch, or per glob of branches (`release/*`): each branch that it matches has its own queue |
| `strategy`         | How the queue tests the pull requests: [Choose a strategy](/docs/strategies)                               |
| `queue_conditions` | What a pull request must meet to enter the line, in addition to the rules of the branch                    |
| `merge_conditions` | The checks that the test commit must pass, in addition to the required checks                              |
| `profiles`         | The settings of a kind of pull request in the same queue, such as the updates of dependencies              |
| `priority_rules`   | Who goes first: `urgent`, `high`, `medium`, `low`, or 0 to 255                                             |
| `defaults`         | The settings and the conditions of every queue that does not set its own                                   |

## Write conditions

A condition is a YAML map: the key is an attribute of the pull request, and every key must hold.

```yaml
queue_conditions:
  draft: false # a boolean
  base: main # a value, or a list of values (one of them)
  labels:
    none: # a list: all, any, none, or count
      - do-not-merge
  files:
    none_match: # globs
      - "migrations/**"
  approved_reviews_by:
    count:
      min: 2
  checks:
    success:
      - build
```

`any:`, `all:` and `none:` take a list of maps. The attributes cover the state of the pull request (`draft`,
`conflict`, `from_fork`, `behind_base`), its reviews, its checks, its labels, its author, its files and its size, its
base and its head, and its position and age in the queue. The [JSON schema](https://cihub.io/schema/config/v1.json)
describes every attribute, and
[`specs/CONFIGURATION.md`](https://github.com/getcihub/cihub/blob/main/specs/CONFIGURATION.md#conditions) gives their
rules.

When a submitted pull request does not meet a condition, its comment names it: "the queue conditions `labels: ready`
are not met".

## Check the file

- The schema line makes your editor check each key and each value.
- An unknown key, a value out of range or two queues on one branch is an error, with its line.
- The page of the queue in the dashboard shows the error of the file on the target branch. Until you fix it, the
  queue keeps the last valid file; a test that needs the file fails with "the configuration file is not valid".

## Write it with an assistant

An assistant writes a valid file if it knows the rules of the file. Copy this prompt into it: it asks you the right
questions first, then writes the file and explains each choice.

<Accordions>
<Accordion title="The prompt for an assistant">

```text title="Prompt"
Help me write the .cihub.yaml file of CIHub, a merge queue for GitHub. Ask me
questions first, one at a time: which branches need a queue, how long my CI
takes and how often it fails, which checks are required, which labels or
reviews must block a merge, and which pull requests must go first.

Then write the file, with only the keys below, and explain each choice.

Rules of the file (version 1):
- Its first line declares the schema, for the editor:
  `# yaml-language-server: $schema=https://cihub.io/schema/config/v1.json`.
- It starts with `version: 1`. Top-level keys: `queues` (a list),
  `priority_rules` (a list) and `defaults` (any queue setting and the
  conditions, without `branch` or `profiles`). An unknown key is an error.
- Each queue has a `branch`, unique in the file: a branch has one queue, and
  a pull request goes to the queue of its base branch. A `branch` can be a
  glob (`release/*`): each branch that it matches gets its own queue, and an
  entry that names a branch wins over a glob. For an urgent pull request,
  use `priority_rules`, not a second queue.
- If the file has no queue for the default branch, that branch still has
  one. Other branches have a queue only with an entry.
- YAML anchors (`&name`, `*name`) and merge keys (`<<: *name`) work, to
  write a map of conditions or a set of settings once.
- `strategy`: `sequential` (one test at a time), `pipelined` (default: tests
  in parallel, each on top of the ones ahead) or `batched` (`pipelined` with
  several pull requests per test; a failed batch is split to find the
  cause). Do not use `parallel`: it is not ready yet.
- `batching: { enabled, size: 2-20, max_wait_minutes: 1-60 }`: on with
  `batched` (size 4, wait 5 by default), off otherwise.
- `merge_method`: `squash` (default), `merge_commit`, `rebase`, or
  `fast_forward` (only with `strategy: sequential`).
- `trigger`: `draft_pr` (default: a draft pull request runs the CI of each
  test) or `push` (the push of the test branch runs it).
- `window: { floor: 1-100, ceiling: 1-100 }`, floor <= ceiling (default 2 /
  20, 1 / 1 with `sequential`), or `testing_concurrency: 1-100` instead.
- `failure_budget: { retries: 0-10 }` (default 1): retries before a pull
  request fails.
- `testing_timeout_minutes` (10-1440, default 300), `not_ready_timeout_hours`
  (1-720, default 168), `keep_test_branches_minutes` (0-1440, default 0).
- `merge_commit_title`: `pr_title` (default) or `pr_title_and_number`.
- Booleans: `comments_enabled`, `commands_enabled`, `status_check_enabled`
  (default true), `state_labels_enabled`, `resubmit_on_push` (default false).
- `label_commands: { enabled: true, enqueue_label: <label> }`: a label that
  submits the pull request (default `cihub-merge-queue-submit`).
- `direct_merge_mode`: `always` (default: when no test runs, merge the first
  pull request without a test branch if it contains the head of the target
  branch and its checks are green) or `off`.
- `branch_protection_injection`: `both` (default), `merge` or `none`: whether
  the checks required by the branch rules also count before admission and on
  the test commit.
- `required_statuses`: a list of check names for the test commit; without
  the key, they come from the branch rules. With no required check at all,
  every test fails.
- `queue_conditions`: what a pull request must meet to enter the queue.
  `merge_conditions`: only `checks`, then `success`, then a list of check
  names, which adds required checks on the test commit. Those of `defaults` come first, and
  each queue adds its own.
- `profiles` (in a queue): a list of `{ name, conditions, merge_method,
  merge_commit_title, batching, failure_budget }` for a kind of pull request
  in the same queue, such as dependency updates. The first profile whose
  `conditions` match, read once at the submission, gives these settings;
  `/cihub merge --profile=<name>` names one. A batch holds one profile.
  A profile cannot set `fast_forward`, nor the settings of the whole queue.
- `priority_rules`: a list of `{ name, conditions, priority }`, where priority
  is `urgent` (0), `high` (10), `medium` (100, default), `low` (200) or 0-255;
  a lower number goes first; the first rule that matches wins.

Conditions are a YAML map, in the block style: the key is an attribute, the
value is typed, and every key must hold. A boolean takes `true` or `false`
(`draft: false`). A string takes a value or a list (one of them), or `not`
(none of them), `matches` (globs) or `regex`. A list takes a list of values
(all of them), or `all`, `any`, `none`, `any_match`, `all_match`,
`none_match` (globs) or `count` (a number, or `min` and `max`). A number or
a duration takes a value (equal), or `min` and `max` (inclusive). The checks
are under one `checks` map: `success`, `neutral`, `skipped`, `failure`,
`pending`. `all:`, `any:` and `none:` take a list of maps. Attributes:
draft, conflict, from_fork, behind_base, number, title, body,
review_decision (approved, changes_requested, review_required, none),
approved_reviews_by, changes_requested_reviews_by, review_requested,
review_threads_unresolved, checks, labels, author, sender, sender_permission
(none < read < write < admin; takes `min`, `max`), files, additions,
deletions, base, head, queue_position, queue_age, pr_age. Durations are
`<n>m`, `<n>h` or `<n>d`. Only `true` and `false` are booleans. Quote a value
that starts with `*`. For example:

    queue_conditions:
      draft: false
      labels:
        none:
          - do-not-merge
      checks:
        success:
          - build
```

</Accordion>
</Accordions>

A coding agent reads the same rules from the schema and from this site in Markdown: [Use CIHub with a coding
agent](/docs/agents).


---
title: "Choose a strategy"
description: "Sequential, pipelined or batched, how the queue tests the pull requests, and which strategy fits the length of your CI and the number of pull requests a day."
canonical_url: "https://cihub.io/docs/strategies"
markdown_url: "https://cihub.io/docs/strategies.md"
---

# Choose a strategy

The strategy is the first setting of a queue: it sets the others to values that go together. Without
`.cihub.yaml`, a queue is `pipelined`.

```yaml
# yaml-language-server: $schema=https://cihub.io/schema/config/v1.json
version: 1
queues:
  - branch: main
    strategy: batched
```

## What every strategy shares

- A pull request is tested on top of the target branch and of every pull request ahead of it, and merges only if
  that test passes.
- A failed test runs once more before the pull request fails (`failure_budget.retries: 1`).
- The first pull request merges without a test branch when no test runs, it already contains the head of the target
  branch, and its required checks passed on its own head (`direct_merge_mode: always`). Its CI already tested what
  lands. `direct_merge_mode: off` tests every pull request in the queue.

## Compare the strategies

<StrategiesDiagram />

| `strategy`            | Tests at the same time       | Pull requests per test | For                                             |
| --------------------- | ---------------------------- | ---------------------- | ----------------------------------------------- |
| `sequential`          | 1                            | 1                      | Few pull requests, a short CI                   |
| `pipelined` (default) | 2, up to 20 while tests pass | 1                      | Most repositories                               |
| `batched`             | 2, up to 20 while tests pass | up to 4                | A long or costly CI, many pull requests an hour |

The `parallel` strategy, independent lines for the parts of a monorepo, is not ready yet.

## sequential: one test at a time

The queue tests one pull request, merges it, then tests the next one. It is the easiest to follow, and the slowest:
with a CI of 20 minutes, the queue merges about 3 pull requests an hour.

Only this strategy allows `merge_method: fast_forward`: the target branch moves to the commit that the CI tested,
without a new merge commit, so that what lands is exactly what passed.

## pipelined: test ahead of the merges

The queue tests several pull requests at the same time, each one on top of the ones ahead of it:

| Test | Holds                 |
| ---- | --------------------- |
| #1   | `main` + #1           |
| #2   | `main` + #1 + #2      |
| #3   | `main` + #1 + #2 + #3 |

When the three tests pass, the three pull requests merge one after the other, with no new test. If #1 fails, the
tests of #2 and #3 start again without it.

The number of tests at the same time, the window, adapts to the health of the queue. It starts at 2
(`window.floor`), grows by one at each test that passes, up to 20 (`window.ceiling`), and halves at each failure
that the failure budget confirms: a queue hit by flaky tests stops spending CI on tests that will run again.
`testing_concurrency: 4` sets a fixed window.

## batched: several pull requests per test

The queue tests up to 4 pull requests in one test, on top of the batches ahead of it. A batch starts when it is full,
or when its oldest pull request waited 5 minutes. Each pull request of a batch still merges as its own commit.

<BisectionDiagram />

When a batch fails, the queue splits it in two halves and tests them at the same time, then splits the half that
fails, until it finds the cause: 8 pull requests with one culprit take 3 rounds of tests. A pull request is never
removed from the queue by a failure that the queue inferred: it is removed only after a test of its own.

This strategy also merges a pull request whose test failed when a test behind it, which includes it, passes: one
flaky failure does not remove a pull request.

| Setting                     | Default with `batched` | Range |
| --------------------------- | ---------------------- | ----- |
| `batching.size`             | 4                      | 2–20  |
| `batching.max_wait_minutes` | 5                      | 1–60  |

A pull request submitted with `--no-batch` is tested alone ([Submit, cancel and restart a pull
request](/docs/commands)).

## Adjust a strategy

A setting of `.cihub.yaml` wins over the value of the strategy.

```yaml
queues:
  - branch: main
    strategy: pipelined
    window:
      floor: 2
      ceiling: 8 # no more than 8 tests at the same time, to spare the runners
    failure_budget:
      retries: 2 # a CI with flaky tests
    testing_timeout_minutes: 60
```

A kind of pull request can have its own settings in the same queue, with a profile: for example, larger batches for
the updates of dependencies.

```yaml
queues:
  - branch: main
    strategy: batched
    profiles:
      - name: dependencies
        conditions:
          author: renovate[bot]
        batching:
          size: 10
```

The [JSON schema](https://cihub.io/schema/config/v1.json) describes every setting, and
[`specs/CONFIGURATION.md`](https://github.com/getcihub/cihub/blob/main/specs/CONFIGURATION.md) gives their rules.


---
title: "Protect the target branch"
description: "The two GitHub rulesets that make every merge to the target branch go through the queue, the settings that slow a queue down, and how CIHub checks them for you."
canonical_url: "https://cihub.io/docs/branch-protection"
markdown_url: "https://cihub.io/docs/branch-protection.md"
---

# Protect the target branch

Without protection, anyone can merge a pull request around the queue, and nothing tested the result. With these
rules, only CIHub can update the target branch, and it does so only after a test of exactly what lands.

You need the `admin` permission on the repository, or rulesets of the organization, and the App of your CIHub
installed on the repository ([Install CIHub](/docs/install)).

<RulesetsDiagram />

## Restrict the updates of the target branch

In the repository: _Settings → Rules → Rulesets → New ruleset → New branch ruleset_.

1. **Target branches**: the branch of the queue, for example `main` (or _Include default branch_).
2. **Rules**: turn on _Restrict updates_.
3. **Bypass list**: add the GitHub App of your CIHub, in the mode **Exempt**.

The mode _Always allow_ does not let a GitHub App update a branch: the queue could not merge. Only _Exempt_ does.

## Require what a pull request must meet

A second ruleset on the same branch, **without any bypass**, holds the rules of a pull request: _Require a pull
request before merging_, its approvals, and _Require status checks to pass_ with the checks of your CI.

CIHub reads these rules: a submitted pull request waits until it meets them, and their required checks are the ones
that the test of the queue must pass, unless `required_statuses` in `.cihub.yaml` names others ([Run your CI on the
tests of the queue](/docs/ci)). Keep the rules of the pull requests in this ruleset, apart from the restriction:
the App bypasses the first one only.

## Exclude the test branches from your other rules

The queue writes its tests on branches named `cihub-temp/…` and `cihub-merge/…`. Every other ruleset whose target
could match them, such as a ruleset on `**` or on all branches, must exclude:

```text
cihub-temp/**/*
cihub-merge/**/*
```

Otherwise, GitHub refuses the test branch, and the test fails with "branch protection refused the test branch".
With `branch_prefix: ci` in `.cihub.yaml`, the branches are `ci-temp/…` and `ci-merge/…`.

## Turn off "Require branches to be up to date before merging"

This rule, in a ruleset or in the classic branch protection, asks that each pull request contain the last commit of
its base. Each merge of the queue then puts every other pull request behind its base, and they wait with "the branch
is behind its base". The queue makes the rule useless: it tests each pull request on top of the target branch and of
every pull request ahead of it.

## The statuses of CIHub in your rules

- `CIHub Merge Queue (<branch>)` can be a required check, so that nothing merges without a test of the queue. The
  restriction of the updates above is what prevents a merge around the queue.
- `CIHub Conditions (<branch>)` must **not** be a required check: a pull request whose conditions pass would then
  merge outside the queue as soon as its other checks pass.

## Check the setup

CIHub reads the rules of the target branch and of the test branches every hour. The page of the queue in the
dashboard shows what is wrong, and so does the API, in `setup.findings`:

```sh
curl https://<your CIHub host>/api/v1/orgs/<owner>/repos/<repo>/queues/<queue> -H "Authorization: Bearer <token>"
```

| Finding                      | What is wrong                                                                        | Fix                                                                             |
| ---------------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
| `update_restriction_missing` | No rule restricts the updates of the target branch: a merge can skip the queue       | [Restrict the updates](#restrict-the-updates-of-the-target-branch)              |
| `app_not_exempt`             | A rule restricts the updates, but does not let CIHub through: the queue cannot merge | Add the App to its bypass list, in the mode _Exempt_                            |
| `test_branches_not_excluded` | A rule covers the test branches too: the queue cannot write them                     | [Exclude the test branches](#exclude-the-test-branches-from-your-other-rules)   |
| `up_to_date_required`        | The rules ask that a pull request be up to date: each merge makes the next ones wait | [Turn the rule off](#turn-off-require-branches-to-be-up-to-date-before-merging) |
| `conditions_status_required` | A rule requires `CIHub Conditions (<branch>)`                                        | Remove it from the required checks                                              |
| `target_branch_missing`      | The target branch no longer exists                                                   | Create the branch again, or stop using its queue                                |

An empty list means sound rules. After a change of the rules, **Check again** on the page of the repository in the
dashboard reads them at once.


---
title: "Run your CI on the tests of the queue"
description: "How CIHub starts your CI on each test of the queue, which checks the test waits for, and how to set up GitHub Actions or another CI."
canonical_url: "https://cihub.io/docs/ci"
markdown_url: "https://cihub.io/docs/ci.md"
---

# Run your CI on the tests of the queue

CIHub never runs your CI. For each test, it pushes a commit, your CI tests it as it tests any commit, and the queue
reads the checks that your CI reports on it. GitHub Actions, Buildkite, CircleCI, Jenkins: any CI that reports a check
run or a commit status works.

## What your CI receives

<TestCommitDiagram />

The test commit holds the head of the target branch, every pull request ahead in the line, and the pull requests of
the test. It is on a branch named `cihub-merge/pr-<number>/<run id>`, which the queue deletes when the test ends.
How your CI hears of it depends on `trigger` in `.cihub.yaml`:

| `trigger`            | What CIHub does                                                                                                                 | What your CI must do                           |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- |
| `draft_pr` (default) | Opens a draft pull request from the test branch to the target branch, named `CIHub: test #12 on main`, and closes it at the end | Run on pull requests, drafts included          |
| `push`               | Pushes the test branch, without a pull request                                                                                  | Run on pushes of the branches `cihub-merge/**` |

Use `push` when a pull request starts things that a test does not need: preview deployments, bots that comment.
To keep the test branches after the test, to look at them, set `keep_test_branches_minutes` (0 by default).

## Which checks the test waits for

The required checks of a test come, in this order:

1. `required_statuses` in `.cihub.yaml`, read on the target branch, never on the pull request;
2. else the required status checks of the rules of the target branch ([Protect the target
   branch](/docs/branch-protection));
3. plus the names of `merge_conditions.checks.success`, if any.

```yaml
# yaml-language-server: $schema=https://cihub.io/schema/config/v1.json
version: 1
defaults:
  required_statuses:
    - build
    - test (ubuntu-latest)
```

- A name matches **exactly** the name that your CI reports: for GitHub Actions, the `name` of the job, or its id,
  followed by the values of its matrix (`test (ubuntu-latest)`).
- The test passes when every required check concludes `success`, `neutral` or `skipped`, and fails at the first other
  conclusion.
- A required check that never reports does not fail the test: the test times out after `testing_timeout_minutes`
  (300 by default). A renamed job is the most common cause: the page of the pull request in the dashboard lists the
  checks of its test, required or not, to compare their names.
- With no required check at all, every test fails with "no required check is configured".

## Set up GitHub Actions

With `trigger: draft_pr`, a workflow that runs on `pull_request` runs on the tests of the queue without a change:

```yaml
on:
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: make test
```

Check that no condition skips draft pull requests, such as `if: github.event.pull_request.draft == false` or
`types: [ready_for_review]` alone. To skip a step on the tests of the queue, test the head branch:

```yaml
- name: Deploy a preview
  if: ${{ !startsWith(github.head_ref, 'cihub-merge/') }}
  run: make preview
```

With `trigger: push` in `.cihub.yaml`, add the test branches to the `push` event:

```yaml
on:
  pull_request:
  push:
    branches:
      - "cihub-merge/**"
```

## Set up another CI

Buildkite, CircleCI, Jenkins and the others need only two things:

- they build the test commit: with `trigger: draft_pr`, they build pull requests, drafts included; with
  `trigger: push`, they build the pushed branches, and a filter of branches lets `cihub-merge/**` through;
- they report their result on GitHub, as a check run or a commit status, under the names that the test requires.

## Know which pull requests a job tests

The name of the test branch ends with the identifier of its run: in GitHub Actions, `${GITHUB_HEAD_REF##*/}` with
`trigger: draft_pr`, `${GITHUB_REF##*/}` with `trigger: push`. A job that needs the list of the tested pull
requests reads the run from the API, with a token of the organization:

```sh
curl https://<your CIHub host>/api/v1/orgs/<owner>/repos/<repo>/runs/<run id> -H "Authorization: Bearer <token>"
```

The body of the draft pull request gives them too: the target and its commit, the pull requests tested, and the ones
that they are tested on top of.


---
title: "Use CIHub with a coding agent"
description: "The files and URLs that let a coding agent read the CIHub documentation, write a valid .cihub.yaml and call the API of an instance."
canonical_url: "https://cihub.io/docs/agents"
markdown_url: "https://cihub.io/docs/agents.md"
---

# Use CIHub with a coding agent

Every page of this site is written for people and for agents. An agent finds here the same information as a
person, in Markdown.

## Read the documentation as Markdown

| URL                                         | Content                                          |
| ------------------------------------------- | ------------------------------------------------ |
| `https://cihub.io/llms.txt`                 | The index of the site, with a link to every page |
| `https://cihub.io/llms-full.txt`            | Every page of the documentation in one file      |
| `https://cihub.io/docs/install.md`          | One page as Markdown: its URL with `.md`         |
| `https://cihub.io/docs/install` with header | The same Markdown, with `Accept: text/markdown`  |

```sh
curl https://cihub.io/docs/install.md
curl -H 'Accept: text/markdown' https://cihub.io/docs/install
```

## Write a valid `.cihub.yaml`

The JSON Schema of the file is at `https://cihub.io/schema/config/v1.json`. Declare it on the first line of the
file, so that an editor completes and checks each key:

```yaml
# yaml-language-server: $schema=https://cihub.io/schema/config/v1.json
version: 1
```

An agent that writes the file validates it against the schema before it proposes the change. [Write your .cihub.yaml](/docs/configuration#write-it-with-an-assistant) has a prompt that asks the right
questions first.

## Call the API of an instance

The OpenAPI document of the API v1 is at `https://cihub.io/openapi/v1.json`. Each instance serves the same
document at `https://<your CIHub host>/api/v1/openapi.json`: cihub.io hosts no API. A request sends a token of
the organization in `Authorization: Bearer <token>`.


---
title: "API errors"
description: "The error codes of the API of a CIHub instance, with the HTTP status of each and what it means."
canonical_url: "https://cihub.io/docs/api/errors"
markdown_url: "https://cihub.io/docs/api/errors.md"
---

# API errors

An error of the API is an `application/problem+json` document (RFC 9457):

```json
{
  "type": "https://cihub.io/docs/api/errors#queue_not_found",
  "title": "Not Found",
  "status": 404,
  "detail": "no queue of `main`",
  "code": "queue_not_found"
}
```

| Field    | Meaning                                                              |
| -------- | -------------------------------------------------------------------- |
| `type`   | The section of this page that explains `code`                        |
| `title`  | The reason phrase of the HTTP status                                 |
| `status` | The HTTP status of the answer                                        |
| `detail` | What went wrong with this request, for a person; its text can change |
| `code`   | The cause of the error, from the closed list below: decide on it     |

Each code has one HTTP status. A `429` also carries the header `Retry-After`: the seconds to wait before the next
request. The [OpenAPI document](/openapi/v1.json) lists, for each route, the codes that it can answer.

## 400 Bad Request

### `invalid_request`

The body, the path or the query of the request is not valid.

### `limit_out_of_range`

`limit` is from 1 to 100.

### `invalid_cursor`

`from` is not a `cursor` that this list gave.

### `unknown_priority`

The name of the priority is not `urgent`, `high`, `medium` or `low`.

### `device_code_pending`

The person has not approved or denied the code yet: ask again after `interval` seconds.

### `device_code_expired`

The device code is unknown, already used, or older than 15 minutes: start again.

## 401 Unauthorized

### `unauthorized`

No API token or session, or one that is unknown or expired.

## 403 Forbidden

### `scope_missing`

The token, or the role of the user of the session or their permission on the repository, lacks the scope of the route.

### `csrf_refused`

A request of a session that can change a state lacks the header `X-CSRF-Token`, or carries another token than the cookie `__Host-cihub_csrf`.

### `device_code_denied`

The person denied the code: the command line is not signed in.

## 404 Not Found

### `route_not_found`

No route has this path.

### `org_not_found`

No organization has this slug, or the token or the user does not belong to it.

### `repo_not_found`

The organization has no repository with this name.

### `queue_not_found`

The repository has no queue of this branch.

### `pr_not_found`

The PR was never submitted to a queue of the repository.

### `run_not_found`

The organization has no run with this identifier.

### `device_code_not_found`

No sign-in of the command line waits for this code: it is wrong, used, or older than 15 minutes.

## 409 Conflict

### `pr_already_queued`

The PR is already in a queue of the repository, and its item has not ended.

### `item_ended`

The item of the PR ended: `merged`, `failed` or `cancelled`.

### `item_not_in_test`

Only an item in `testing` or `pending_failure` can restart its tests.

## 429 Too Many Requests

### `rate_limited`

The token, the session or the client address made too many requests in the minute (600 for a token or a session, 120 for the sign-in of the command line): retry after `Retry-After` seconds.

### `too_many_streams`

The token or the person already keeps 8 streams open.

### `polling_too_fast`

The command line asked again sooner than `interval`: wait 5 seconds more each time.

## 500 Internal Server Error

### `internal`

The server failed; the logs of the instance say why.

## 503 Service Unavailable

### `sign_in_unavailable`

The instance has no public address or no sign-in client: nobody signs in to it.

### `scm_unavailable`

The SCM did not answer the check of the access of the person of the session: try again in a moment.


---
title: "Troubleshooting"
description: "What to check when a command gets no answer, when a pull request does not enter the queue, when its test does not start or never ends, or when the queue cannot merge it."
canonical_url: "https://cihub.io/docs/troubleshooting"
markdown_url: "https://cihub.io/docs/troubleshooting.md"
---

# Troubleshooting

Start with the comment of CIHub on the pull request: its state line gives the reason, and its _History_ block lists
every decision of the queue on the pull request. `cihub queue status <number>` and the page of the pull request in the
dashboard give the same information.

## A command gets no answer

A command that the queue reads gets a 👍 reaction, or a comment that gives the cause of a refusal.

| Symptom                          | Cause                                                                             | Fix                                                                                                                        |
| -------------------------------- | --------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| No reaction, no comment          | GitHub does not send the events of the repository to CIHub                        | Check that the App is installed on the repository, and the _Recent Deliveries_ of the App (_Advanced_ tab of its settings) |
| No reaction, no comment          | `commands_enabled: false` in `.cihub.yaml`                                        | Turn the commands on, or submit through the command line or the dashboard                                                  |
| "the queue refused this command" | The author lacks the `write` permission, or the pull request is closed or a draft | Read the cause in the comment                                                                                              |
| `/cihub restart` is refused      | Only a pull request whose test runs or failed and waits can restart               | Submit the pull request again with `/cihub merge`                                                                          |

## A pull request stays "Waiting"

The comment gives the first thing that blocks it; [The life of a pull request in the
queue](/docs/pull-requests#why-a-pull-request-waits-to-enter-the-line) lists them all.

| The comment says                               | Cause                                                                                 | Fix                                                                                                    |
| ---------------------------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| the required check `build` has not reported    | The CI does not run this check on the pull request, or under another name             | Compare the name of the required check with the name of the job                                        |
| the branch is behind its base                  | The rules require that a pull request be up to date                                   | [Turn the rule off](/docs/branch-protection#turn-off-require-branches-to-be-up-to-date-before-merging) |
| the queue conditions `…` are not met           | The `queue_conditions` of `.cihub.yaml`                                               | Meet them; the status `CIHub Conditions (<branch>)` says the same on every pull request                |
| the SCM does not say yet why the PR is blocked | GitHub has not computed the mergeability yet, or a rule blocks that CIHub cannot name | Wait for the next read; if it stays, open the merge box of the pull request on GitHub                  |

A pull request that waits 7 days is cancelled with "the PR waited too long to become ready"
(`not_ready_timeout_hours`).

## A test does not start

| Symptom                                                                  | Cause                                                             | Fix                                                                                                                           |
| ------------------------------------------------------------------------ | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| The pull request stays "Queued"                                          | The tests at the same time fill the window                        | Nothing: it starts when a test ends. See [Choose a strategy](/docs/strategies)                                                |
| Nothing moves in the queue                                               | The queue is paused, or CIHub lost its access to the repository   | The page of the queue says why; `cihub queue resume`, or install the App again                                                |
| Failed: branch protection refused the test branch                        | A ruleset covers `cihub-temp/…` or `cihub-merge/…`                | [Exclude the test branches](/docs/branch-protection#exclude-the-test-branches-from-your-other-rules)                          |
| Failed: the repository does not allow draft PRs                          | The repository cannot have draft pull requests                    | `trigger: push`, and a CI that builds `cihub-merge/**` ([Run your CI](/docs/ci))                                              |
| Failed: no required check is configured                                  | Neither the rules of the branch nor `.cihub.yaml` require a check | Add required checks to the rules of the branch, or `required_statuses` to `.cihub.yaml`                                       |
| Failed: the configuration file is not valid                              | `.cihub.yaml` on the target branch has an error                   | The page of the queue shows the error; declare the [schema](/schema/config/v1.json) in the file so that your editor checks it |
| Failed: the PR conflicts with the target branch or with a PR ahead of it | The pull request does not merge with what is ahead of it          | Merge the target branch into the pull request once the other one merged, then submit it again                                 |

## A test never ends

| Symptom                                               | Cause                                                              | Fix                                                                                                                |
| ----------------------------------------------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| No CI runs on the draft pull request `CIHub: test #…` | A workflow skips draft pull requests                               | Remove the condition on `draft`; see [Set up GitHub Actions](/docs/ci#set-up-github-actions)                       |
| No CI runs on the test branch with `trigger: push`    | The CI does not build `cihub-merge/**`                             | Add the branches to its triggers or to its filter of branches                                                      |
| The CI passes, but the test waits                     | A required check reports under another name, or never reports      | Compare the names; the test fails with "the tests took longer than the time limit" after `testing_timeout_minutes` |
| Failed: the tests took longer than the time limit     | A required check did not conclude in time (300 minutes by default) | Fix the name of the check, or raise `testing_timeout_minutes`                                                      |

## Tests that fail only in the queue

| Symptom                                                                       | Cause                                                                                       | Fix                                                                                                     |
| ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| The test fails, the CI of the pull request passed                             | The pull request breaks with a pull request ahead of it, or with a new commit of the target | This is what the queue is for: update the pull request on top of the target branch and fix it           |
| A test fails, then passes when it runs again                                  | A flaky test                                                                                | The failure budget runs a failed test again once; raise `failure_budget.retries` while you fix the test |
| Every test starts again: "a push outside the queue changed the target branch" | Someone pushed to the target branch                                                         | [Restrict the updates](/docs/branch-protection#restrict-the-updates-of-the-target-branch) of the branch |

## The queue cannot merge

| The comment says                                               | Cause                                                                                              | Fix                                                                                         |
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| Failed: branch protection refused the merge                    | The rules of the branch require something that the pull request lacks, or do not let CIHub through | Check the rules; `app_not_exempt` in the [setup](/docs/branch-protection#check-the-setup)   |
| Failed: the merge of the PR was refused                        | GitHub refused the merge, for example a merge method that the repository does not allow            | Allow the `merge_method` of the queue in _Settings → General → Pull Requests_, or change it |
| Failed: the PR changed between its tests and its merge         | A push on the pull request after its test                                                          | Submit it again                                                                             |
| Failed: the API rate limit did not reset in time for the merge | The installation of the App used its GitHub API budget                                             | Submit it again; check what else uses the App                                               |

## Ask for help

Open an issue on [GitHub](https://github.com/getcihub/cihub/issues) with the state line and the _History_ block of
the comment of CIHub, and `cihub queue status <number>`.
