# GitLab and GitLab Self-Managed

> Connect GitLab.com or a self-managed GitLab instance to MergeHarbor with OAuth or an access token, then choose the projects and merge requests to review.

## Connect with GitLab (recommended)

1. In the console, choose **GitLab** (or **GitLab Self-Managed** and enter your instance URL).
2. Authorize MergeHarbor on GitLab.
3. Choose the projects to review.

MergeHarbor stores the tokens encrypted, refreshes them automatically, and registers a webhook on each project you enable.

For self-managed instances, your administrator can register an OAuth application for MergeHarbor (scope `api`, redirect URL shown in the console) or enter an existing application's ID and secret when connecting.

## Connect with an access token

Use a **group** or **project access token** with the **Developer** role or higher and the `api` scope. Group tokens cover every project in the group. Choose **Connect with a token** and paste it; MergeHarbor verifies the token and stores it encrypted.

## How reviews appear

Reviews are posted as merge-request discussions positioned on the diff, with a summary note and a commit status. Comments that GitLab cannot position on the diff are listed in the summary.

Webhook events used: merge request, comments, and push. Registering a project again, for example after you reconnect, replaces the webhooks MergeHarbor added before.

Comment `@mergeharbor review` or another [command](https://mergeharbor.com/docs/configuration#commands-in-pull-requests) on a merge request; a comment that starts with `mergeharbor review` (no `@`) works too. See [Code host permissions](https://mergeharbor.com/docs/permissions) for why MergeHarbor needs the `api` scope and how to revoke access.

## Private networks

Instances that are not reachable from the internet need a [self-hosted](https://mergeharbor.com/docs/self-hosting) MergeHarbor deployment inside your network.

## Reconnect, switch accounts or disconnect

- **Reconnect** (Integrations → Code hosts) replaces the token of the account the connection belongs to, for example after a token expired or was revoked. Signing in as a different GitLab account is refused and nothing changes. After a reconnect, MergeHarbor registers the webhooks of the enabled repositories again with the new credentials; a repository the account can no longer access stops being reviewed and shows a webhook error on the Repositories page.
- **Switch accounts** by disconnecting and connecting the other account.
- **Disconnect** stops reviews at once and removes MergeHarbor's webhooks from GitLab. The repositories' reviews, index and settings are kept for 7 days, then permanently deleted. Connecting GitLab again within those 7 days brings the repositories back with their history; the ones that were enabled are reviewed again if the connected account can see them, and the others stay disabled.
- A repository belongs to one MergeHarbor organization at a time. Enabling a repository that another organization has connected is refused until it is disconnected there.
