# GitLab

> Authorize LevelFour on GitLab over OAuth so it can comment cost impact on merge requests and open merge requests with savings changes.

Source: https://docs.levelfour.ai/integrations/gitlab


LevelFour connects to GitLab over OAuth. You name the projects it should read, authorize once, and LevelFour registers a webhook on each one. It works with GitLab SaaS and with a self-managed instance.

## Prerequisites

* **Maintainer** or **Owner** on every project you connect. LevelFour registers a webhook, and lower roles cannot.
* A GitLab tier that allows project webhooks. LevelFour reports the ones that do not, project by project.
* The full path of each project, in the form `group/subgroup/project`.

## Connect

### Open Settings, then Integrations

In the dashboard sidebar, click **Settings**, then **Integrations**, then the **GitLab** tile.

If the tile reads **Contact sales**, GitLab is not enabled for your organization yet. Click it to ask.

### List your projects

Add the full path of each project where LevelFour should look for Infrastructure-as-Code. Add as many as you want. One authorization covers all of them.

Leave the instance URL as `https://gitlab.com` for GitLab SaaS. For a self-managed instance, enter its URL, such as `https://gitlab.example.com`.

### Authorize in GitLab

Click **Connect GitLab**. GitLab opens in a new tab and asks you to authorize LevelFour. Approve it, then return to the dashboard tab.

The status pill moves through `Waiting for authorization` and `Verifying connection`. Authorization finishes in under a minute. If you closed the GitLab tab before approving, click **Cancel** and start again.

### Read the connection results

> **Success**
>
> The pill lands on `Connected`, and the results panel says how many of your projects connected.

A project that did not connect says why. The three you are most likely to see:

| Result                                     | What to do                                                       |
| ------------------------------------------ | ---------------------------------------------------------------- |
| LevelFour needs maintainer or owner access | Raise your role on that project in GitLab, then connect it again |
| The tier does not allow the webhook        | Upgrade the tier, or connect a different project                 |
| We could not find this project             | Check the path, including every subgroup                         |

## Removing access

Open the connection under **Settings > Integrations > GitLab** and click **Disconnect**. LevelFour stops analyzing merge requests for that path and deletes its webhook from GitLab. If GitLab refuses the deletion, the dashboard says so, and you remove the webhook yourself under the project's **Settings > Webhooks**.

You can reconnect a project at any time.

## Troubleshooting

| Symptom                                      | What to do                                                                                           |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| The pill sits on `Waiting for authorization` | The GitLab tab was closed or blocked. Click **Reopen GitLab authorization**                          |
| The pill reads `Expired`                     | The request timed out. Start a new one for a fresh link                                              |
| The pill reads `Failed`                      | Someone closed the tab before authorizing, or permissions changed inside GitLab. Click **Try again** |
| A self-managed instance never answers        | Check that the URL is `https` and that the instance is reachable from the public internet            |

## Next

* [Pull request bot](/integrations/pull-request-bot) is what the bot posts on merge requests and the commands it answers
* [Integrations](/integrations) lists the other tools you can connect
* [GitLab billing](/connectors/gitlab-billing) is separate, and it reads your GitLab spend
