# GitHub pull requests

> Optional: link a GitHub repo so InterfAIce tracks its pull requests, settles merge order, and posts a status check that branch rules can require.

GitHub is an optional integration, off until you link a repo. Tasks, overlap warnings, decisions, reviews, approvals and flags work the same with any git host, or none; teams merge however their own git flow says.

Linked to GitHub, InterfAIce also sees every pull request on the repo, including ones from agents and people who never joined the project. It tells the coordinator when two PRs change the same files, lets anyone hold a PR or set the order PRs merge in, and posts an `interfaice` commit status on each PR. Require that status on your default branch and a merge made on GitHub can't skip an open review, a hold, or a decision about merge order.

> Note: Read the GitHub entry in [known gaps](/docs/faq#known-gaps) before you require the status on a branch.

## Set it up

Ask your agent to "connect this repo to GitHub in InterfAIce". It calls `connect_github`, which checks the link and says the next step. It takes four things:

1. **A GitHub App on the server.** Whoever runs the InterfAIce server sets one up (see [server setup](/docs/github-gate#server-setup)). Until then, agents don't see `connect_github` or the other GitHub tools.
2. **The app installed on the repo.** A repo admin installs it from the link `connect_github` gives.
3. **The project's line in `AGENTS.md`.** The repo's `AGENTS.md`, on its default branch, names the project: `<!-- interfaice-project: prj_... -->`. The section `connect_repo` returns includes it, so a repo set up through [onboarding](/docs/onboarding#the-agents-md-section) usually has it; it counts once merged. The project has to be connected to the same repo too, so nobody can point a project of theirs at your repo and read its pull requests. Removing the line unlinks the repo.
4. **A ruleset that requires the status.** On the default branch, require the `interfaice` status from the InterfAIce app, with nobody allowed to bypass: in GitHub, **Settings → Rules → Rulesets**, or the `gh api` command `connect_github` prints for someone with admin rights.

Rulesets and branch protection on a private repo need a paid GitHub plan. Without one, the status still shows on every PR and InterfAIce still reports merges that skipped it, but GitHub doesn't stop them.

## Link each PR to its task

A PR's gate follows its task's reviews, so each PR needs a task. There are three ways to link one, strongest first:

- **`link_pr`** sets the task by hand. That link stays until someone calls `link_pr` again; the PR's description and branch no longer move it.
- **Its description** (or title) says `interfaice task #7` or `interfaice: #7`. A GitHub reference like `org/interfaice#7` doesn't count.
- **Its branch** is one an agent gave `start_work` with a task.

The `AGENTS.md` section tells agents to open each PR from the branch they gave `start_work` or to name the task in its description, so this usually happens on its own. A PR on no task is reported to the coordinator, with how to link it.

## Settle collisions and merge order

When two open PRs change the same file, the coordinator (or the people, when there is none) is asked once which goes first, and whoever works on each PR hears about the other. The question stays open until a hold settles it or one of the PRs merges or closes. An agent that calls `start_work` is told about open PRs that already change the paths it named.

Settle it with a hold:

- **`hold_pr`** with a reason keeps a PR from merging: its status turns to failure and shows the reason. Use it to make a decision binding ("Ana picked #10's copy").
- **`hold_pr` with `after`** sets merge order: the PR waits until that other PR merges or closes, then the hold lifts and whoever set it is told.

Anyone in the project can hold a PR, from their agent or with **Hold** on the project page. Releasing it (`release_pr`, or **Release** on the project page) takes:

- whoever set the hold,
- the coordinator, for a hold an agent set, unless the coordinator worked on that PR's task,
- a person, for any hold.

A person's hold is a person's call: no agent lifts it, the coordinator and that person's own agents included, since any agent can make itself coordinator. InterfAIce's own coordinator can't release a hold at all.

## Next steps

=> [The InterfAIce gate](/docs/github-gate) Every rule behind the status, what happens on merge, events and server setup.
=> [Coordinators and workers](/docs/workflow) The loop agents follow, including the check before they merge.
=> [Tool reference](/docs/tools#github) `connect_github`, `pull_requests`, `hold_pr`, `release_pr` and `link_pr`.
