# Automate code review on pull requests

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/air/llms.txt).

An AI code review automation reads every new pull request the way a reviewer would – the linked issue, the description, the diff, and the code around it – and posts only the findings the author has to act on before the merge. Each finding is an inline comment with the problem, the scenario where it fails, and a fix. The review ends with a verdict: Request changes if any finding blocks the merge, otherwise Approve.

You build it from the Code Review [template](https://www.jetbrains.com/help/air/automation-templates.html.md). The [quickstart](https://www.jetbrains.com/help/air/automations-quickstart.html.md) sets up the basic version; this topic covers the choices that make it fit a team: which pull requests get reviewed, how often, and against which rules.

<a id="code_review_setup"></a>

## Set up the review

<a id="code_review_setup_procedure"></a>

Procedure: Create a code review automation

1. On the Automations page, click New Automation. In Instructions, click Use Template and select Code Review under By Air.

2. Select the repository. To review pull requests for the whole team, select the team's [project](https://www.jetbrains.com/help/air/create-automation.html.md#automation_sharing) in the scope selector.

3. In Triggers, add the pull request event that matches when your team wants a review – see [Choose which pull requests get reviewed](#code_review_which_prs) – and set its change handling to No code changes. The review is posted on the pull request, so the run has nothing to commit.

![A PR labeled trigger with the label ai-review and No code changes](images/automation-example-code-review-trigger.png)

4. Add your team's rules to the end of the instructions – see [Add your team's rules](#code_review_team_rules).

5. Click Create. To check the result before the next pull request arrives, click Run Now and enter a link to an open pull request in Context – see [Run an automation manually](https://www.jetbrains.com/help/air/run-automations.html.md#run_automation_manually_procedure).

<a id="code_review_which_prs"></a>

## Choose which pull requests get reviewed

Every review is a run, and every run spends AI credits. Pick the trigger for how your team works:

| Review | Trigger and filters |
| --- | --- |
| Every pull request, once | `GitHub \| Pull request \| Opened` with Ignore drafts, and `Pull request \| Moved out of draft` for pull requests that start as drafts |
| Every pull request, after every push | Add `Pull request \| New changes` with Ignore drafts. A pull request that gets ten pushes gets ten reviews. |
| Only when someone asks for it | `Pull request \| Labeled` with a label such as `ai-review`. The author adds the label when the pull request is ready. For another pass, they remove the label and add it again. |
| Only for some authors | Any of the above with the PR author filter – for example, to review the pull requests that other automations open. |

For every event and filter, see [GitHub events](https://www.jetbrains.com/help/air/automation-triggers.html.md#automation_trigger_github_events).

<a id="code_review_team_rules"></a>

## Add your team's rules

The template judges a change by the code around it, and it already skips style remarks and anything the author doesn't have to fix. Add what only your team knows, as plain sentences at the end of the instructions. For example:

```TEXT
Don't comment on files under generated/ or on lockfiles.
Every new public API endpoint needs an entry in docs/api.md; flag one that doesn't have it as Blocking.
Database migrations must be backward-compatible with the previous release.
```

If you review after every push, tell the agent not to repeat itself, so the second review doesn't post the same findings again:

```TEXT
If you reviewed this pull request before, read your earlier comments first. Review only what changed since
then, and don't post a finding again that an earlier comment already covers.
```

Conventions that apply to every agent – build commands, code style, architecture rules – belong in the repository's [project instructions](https://www.jetbrains.com/help/air/project-instructions.html.md), where cloud tasks follow them too.

<a id="code_review_go_further"></a>

## Go further

* GitLab – the same setup works with `GitLab | Merge request | Opened` and the matching merge request events. Air Teams adds the project webhook when you save the automation – see [GitLab events](https://www.jetbrains.com/help/air/automation-triggers.html.md#automation_trigger_gitlab_events).

* Comment only, no verdict – if your team doesn't want an automation to approve pull requests, replace the verdict part of the instructions with "Post comments only. Never approve or request changes."

* Add tests where the change needs them – a second automation adds the missing tests to the pull request itself, and can start the review once they're in – see [Add missing tests to pull requests](https://www.jetbrains.com/help/air/add-tests-to-pull-requests.html.md).

* Check the docs too – the Documentation Maintenance template comments on documentation that the change made wrong.

