---
title: "Pull request checks"
description: "Scan a pull request's head and base, post a pass or fail check from your policy, and annotate only the findings it introduces, on GitHub or GitLab."
---

A pull request check answers one question: **does this change make the
repository less secure?** TRUSTIVAN scans the pull request's head commit and
its base commit, compares the two by finding fingerprint, and reports only what
the change introduces. A vulnerability, secret or code finding that is already
on the base branch is not repeated on every pull request.

| | GitHub | GitLab (gitlab.com or self-hosted) |
| --- | --- | --- |
| Triggered by | GitHub App webhook: `pull_request` opened, synchronize, reopened, ready for review | Project webhook: merge request events (open, reopen, update) |
| Result | A check run named **TRUSTIVAN** with a conclusion | A commit status named **TRUSTIVAN** |
| Line comments | Check-run annotations on the introduced findings | A merge request note listing them, when there are any |
| Authenticates as | The GitHub App installation | Your organization's stored git credential for the host |

## What the check reports

- **Passed**: your organization's enabled policy passes over the findings the
  change introduces.
- **Failed**: the policy fails over them, a scan of the head or base commit did
  not complete, or a scan reported more findings than TRUSTIVAN stores for a
  comparison. A check that could not look is never a pass.
- **No verdict** (GitHub `neutral`, GitLab `success`): the organization has no
  enabled policy. The introduced findings are still listed.

The policy is the same one the [CLI gate](/integrations/ci-pipelines) uses, but
evaluated over the **introduced** findings only. A suppression you already
recorded on the repository's finding still applies, as your policy's
suppression mode says. No verdict record is stored for a pull request check;
its result is on the check itself and in the repository's page in TRUSTIVAN.

Annotations go on findings that name a file: at most 200 per check, worst
first, sent 50 per request as GitHub requires. A finding without a file path
(for example, a vulnerability reported from a lockfile with no line) is listed
in the summary table instead.

## How comparison works

Each finding has a fingerprint built from what it **is** (the advisory and
package, the secret rule, file and credential digest, the code rule and file),
never from its line number. So a finding that moved because lines were added
above it is neither new nor fixed. A finding without a fingerprint is treated
as new.

The two scans are **check-only**. They do not change the repository's findings
in TRUSTIVAN: a pull request is code that is not merged, and reconciling it
would mark main-branch findings as resolved because a branch happens to fix
them. Two pull requests on the same base commit share one scan of it.

## Set it up

PR checks are **off** for every repository until you switch them on.

1. Link the code host to your organization (below).
2. Add the repository as an asset by scanning it once. A private repository
   clones with the same credential every scan of it uses: a stored
   [git credential](/how-to/scan-a-private-repository) for the host if you have
   one, otherwise, on github.com, a read-only token from the linked App
   installation on the account that owns the repository. On GitLab a stored
   credential is the only way.
3. On the repository's page in TRUSTIVAN, turn on **PR checks** in the
   **Pull requests** card, or call
   `PATCH /api/v1/assets/{id}/code-settings` with `{"pr_checks_enabled": true}`.

### Link the GitHub App

Install the deployment's GitHub App on the account that owns the repository,
with **Checks: read and write**, **Contents: read** (read and write for
[fix pull requests](/integrations/fix-pull-requests)), **Pull requests: read
and write** and **Metadata: read**, subscribed to **Pull request** events.

Then link it from the repository's page, in the **Pull requests** card:

1. Choose **Install the GitHub App** if it is not installed yet. TRUSTIVAN reads
   the address of the App's install page from GitHub.
2. The card lists the installations GitHub says you can access. Choose
   **Link** beside the account. There is no id to type.

GitHub lists installations only for a token from the App's own sign-in. A token
from a separate OAuth App gets `403` and an expired one gets `401`, so when
TRUSTIVAN has neither, the card offers **Authorize on GitHub**. That stores a
token for you and comes back to the same page. It does not sign you in, and does
not make that GitHub account a way to sign in to TRUSTIVAN.

| The card says | Why | What to do |
| --- | --- | --- |
| No GitHub App configured | `GITHUB_APP_ID` and `GITHUB_PRIVATE_KEY` are unset | An administrator [configures the App](/configuration/sign-up-and-sign-in#the-github-app) |
| Authorize on GitHub | GitHub refused the stored token, or there is none | Choose it |
| An administrator must set `GITHUB_APP_CLIENT_ID` | The App has no OAuth client, so nobody can get a token GitHub accepts, and nothing can be linked | An administrator sets both client variables |
| GitHub did not answer | GitHub failed | Try again. A field for the installation id appears, but GitHub still has to confirm access, so it works only once GitHub answers |

TRUSTIVAN links an installation only if GitHub lists it among the ones your
GitHub account can access (`GET /user/installations`, with your own token). An
API key cannot link one, and an installation linked to another organization is
refused. Linking needs `credentials:manage`.

The same through the API, from a session:

```bash
curl https://app.trustivan.com/api/v1/code-integrations/github/installations \
  -H "Authorization: Bearer $SESSION"

curl -X POST https://app.trustivan.com/api/v1/code-integrations/github/installations \
  -H "Authorization: Bearer $SESSION" -H "Content-Type: application/json" \
  -d '{"installation_id": 12345678}'
```

Deliveries for an installation no organization has linked, for a repository
that is not an asset, or with PR checks off, are acknowledged and ignored.
Pull requests **from forks** and **drafts** are not checked.

### Create a GitLab webhook

```bash
curl -X POST https://app.trustivan.com/api/v1/code-integrations/gitlab \
  -H "Authorization: Bearer $SESSION" -H "Content-Type: application/json" \
  -d '{"host": "gitlab.com"}'
```

The response carries `webhook_url` and `secret_token`, **shown once**. In the
GitLab project, add a webhook with that URL and secret token and tick **Merge
request events**. TRUSTIVAN stores only a SHA-256 of the token. The results are
posted with your organization's stored git credential for that host, which
needs the `api` scope. Merge requests from forks and drafts are not checked.

## When the host is unavailable

The webhook only records the pull request; a background task talks to GitHub
or GitLab and queues the scans. A failed call is retried with backoff (30
seconds, doubling, up to 30 minutes) and the check is marked errored after 8
attempts, with the reason shown on the repository's page.

## Limits

- github.com and GitLab only. GitHub Enterprise Server and Bitbucket are not
  supported yet.
- Check scans run your organization's scanner selection for repositories
  (**Settings → Data and evidence → Repository scanners**). With no selection that is vulnerabilities, secrets
  and the SBOM, so **misconfiguration and static analysis run on a pull request
  only once you select them**, and static analysis also needs the deployment's
  [analyser image](/configuration/static-analysis). A selected scanner the
  deployment cannot run is left out of the check rather than failing it.
- Verification: the GitHub and GitLab API calls are tested against **recorded
  API responses** shaped from GitHub's and GitLab's published examples, through
  the same outbound network guard production uses, and a clone with an
  installation token is tested against a local git server. None of it has been
  run against a live GitHub or GitLab account.

## API

| Route | Permission |
| --- | --- |
| `POST /api/v1/github/webhook` | GitHub signature |
| `POST /api/v1/gitlab/webhook/{id}` | GitLab secret token |
| `GET /api/v1/code-integrations/installations` | `credentials:read` |
| `GET /api/v1/code-integrations/github/installations` | `credentials:manage`, a person |
| `POST /api/v1/code-integrations/github/installations` | `credentials:manage`, a person |
| `POST /api/v1/code-integrations/github/authorize` | `credentials:manage`, a person |
| `POST /api/v1/code-integrations/gitlab` | `credentials:manage` |
| `DELETE /api/v1/code-integrations/installations/{id}` | `credentials:manage` |
| `GET /api/v1/assets/{id}/code-settings` | `assets:read` |
| `PATCH /api/v1/assets/{id}/code-settings` | `assets:write` |
