> ## Documentation Index
> Fetch the complete documentation index at: https://docs.augmentcode.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate GitLab Cloud

## Introduction

In this page we’ll configure the native Gitlab integration and learn how to:

1. Get Gitlab to push events to Cosmos via webhooks
2. Configure a Cosmos environment that git clones/fetches from Gitlab repo(s)
3. Get Cosmos to automatically post onto a MR when the MR is created
4. Deploy the MR author and MR reviewer experts via the Cosmos Advisor

For 4, below is the flow that will be followed by the Cosmos MR reviewer expert:

```mermaid theme={null}
sequenceDiagram
	autonumber
	participant GL as GitLab
	participant A as Augment Cosmos
	GL->>A: Webhook: Merge Request created (MR payload)
	A->>A: Start Expert (spawn/run expert agent)
	A->>A: Expert analyzes MR (diff + context)
	A->>GL: POST MR comment
	GL-->>A: 201 Created (comment posted)
```

## Prerequisites

To configure the one-time connectivity between Cosmos and Gitlab:

* you must be a Augment admin
* you must have Gitlab permissions to create a Gitlab group service access token with the `api` scope (required) and either \[the **Owner** role] or \[a custom role with at least the **Developer** role and the `admin_web_hook` permission].

## Step 1 - Configure the native Gitlab integration

As a Augment admin, go to [cosmos.augmentcode.com](http://cosmos.augmentcode.com) > Settings > Integrations ([https://cosmos.augmentcode.com/integrations](https://cosmos.augmentcode.com/integrations)) and next to Gitlab click on Connect:

<img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-01.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=34d36818038febdb9448adedbda671e8" alt="" width="1784" height="646" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-01.png" />

You’ll be redirected to this view:

<img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-02.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=b1f57de708b8a4b36d58be9bb767d91e" alt="" width="1778" height="702" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-02.png" />

Let’s switch to Gitlab to create that group service account:

* Navigate to your Gitlab group, then Settings > Service Accounts in the left sidebar
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-03.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=20463d82d98e675580a06c244471edf7" alt="" width="512" height="764" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-03.png" />
* Click on Add service account
  * Name: Cosmos
  * Username: ex: augment-code-cosmos
    <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-04.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=6dc5cb638ef0039a779329478bc1cb2b" alt="" width="1000" height="436" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-04.png" />
* Next to your service account > click on the 3 dots > Manage access tokens
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-05.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=c00e1c995a33fadb4eb122b0eb172632" alt="" width="1330" height="562" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-05.png" />
* Add new token
  * Name: Cosmos01
  * Expiration date - set the maximum
  * Select `api` scope
  * Click on Generate token
    <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-06.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=f90c01140a08412d208c4e74cbf36045" alt="" width="1338" height="1664" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-06.png" />
* Copy the access token, we’ll need it shortly
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-07.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=9bb09d91686a56850358d7c13f1f9c75" alt="" width="1332" height="1006" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-07.png" />
  Now you’ll make this service account a member of the projects you want to surface in Cosmos.
  2 options:
* (1) make it an Owner on those projects
* or (2) create a [custom role](https://docs.gitlab.com/user/custom_roles/) with `admin_web_hook` permission and a base of at least the Developer role

Here we’ll make the service account an Owner on a given project:

* Go to your project > left sidebar > Manage > Members > Invite members > select your service account > role ‘Owner’ or the Custom role > select your project (or all projects in the group) > Invite
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-08.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=4cfd5ce71eac0fb87d9fd30930cade87" alt="" width="664" height="642" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-08.png" />
  You should see this:
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-09.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=d4514c797b388c531c36467e732b93c9" alt="" width="1704" height="444" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-09.png" />
  Now go back to Cosmos.
* Paste the group service account’s access token into Cosmos and click on ‘Connect bot’:
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-10.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=39ae6cb3c1f5a64b01d2361748de1e44" alt="" width="1562" height="608" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-10.png" />
  Cosmos will automatically:
* Discover the repos
* Register webhooks to react to events across those repos

You should see this:

<img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-11.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=c46465befd69d7acae385c7916efe125" alt="" width="1594" height="868" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-11.png" />

If you don’t see your repos, double check the scopes of your service account and that it’s added as a member of your projects with the proper role.

## Step 2 - Create a cloud environment

Let’s create a cloud environment with those Gitlab repos:

* Go to Cosmos settings > Environments ([https://cosmos.augmentcode.com/environments](https://cosmos.augmentcode.com/environments)) > top right Create an environment > Cloud machine
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-12.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=eb186f4705a5306613faa5f429b9830d" alt="" width="1600" height="294" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-12.png" />
* Configure your environment
  * Name: ex: ecomm-stack
  * Image: ex: keep the Cosmos default base image
  * Repositories: select your Gitlab repos
  * Refresh: toggle on
  * Spaces: keep the default space
  * Click on Create Environment
    <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-13.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=f6ea35094910a97d98e57a4b5effa70b" alt="" width="1594" height="1818" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-13.png" />
    Cosmos will create the cloud environment, git clone your repos and keep them up to date
    <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-14.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=a51ba924cff8eec8f627327983b02191" alt="" width="568" height="278" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-14.png" />
    <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-15.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=4a3208af765d48c8a9879ebacc18c622" alt="" width="574" height="206" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-15.png" />
* Click on Done

You’ll see your new environment in your “Mine” tab:

<img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-16.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=c80f517cc0641cdcdcd9fd5f87fb8992" alt="" width="1598" height="468" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-16.png" />

Now let’s do a quick test and create a session with that env:

* Click on ‘Back to app’ top left > New session ([https://cosmos.augmentcode.com/home](https://cosmos.augmentcode.com/home)) > bottom left of the prompt select your env, then click on Integrations and verify that Gitlab is selected, then send this prompt “What’s this repo about?”
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-17.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=cfb907d5b7b87d70b3af3f5fc9eee21c" alt="" width="1054" height="1058" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-17.png" />
  That’ll start a session. Notice on the right sidebar Expert = Not set, Integrations include Gitlab, your selected env:
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-18.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=7990774fd89f1067ef8983faa248e4f5" alt="" width="1606" height="1818" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-18.png" />
  Your Gitlab integration and your cloud env are ready. It’s time to create your first Cosmos expert.

## Step 3 - Create a MR deep reviewer expert

Cosmos has a large knowledge base and greatly assists with creating new experts.
A common expert you’d create for your Gitlab repos is the “MR reviewer”, whose job will be to auto react to MRs being created and auto review them. Whenever you need to create new experts go ask the Cosmos Advisor:

* Go to New session ([https://cosmos.augmentcode.com/home](https://cosmos.augmentcode.com/home)) > select the ‘Cosmos Advisor’ expert, make sure the Gitlab integration is selected and prompt with “Create a MR author, a MR risk analyzer, a MR deep reviewer. The MR review should start whenever a MR gets created. Those experts should reuse the ecomm-stack env of this session”
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-19.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=44584cdad6c1760d62454731bb3b4a7f" alt="" width="1036" height="1054" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-19.png" />
  The Cosmos Advisor may ask you to clarify what experts to deploy, it may recommend to include other experts (ex: helper experts), and if an integration is missing it’ll guide you to add it. Ultimately you should see this at the end of your session:
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-20.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=ad7afc770e6bbe6b513bb0f1de704244" alt="" width="796" height="610" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-20.png" />
  Go check where your experts are created:
* Go to Cosmos settings > Experts ([https://cosmos.augmentcode.com/experts](https://cosmos.augmentcode.com/experts)) > filter on expert name containing ‘gitlab’:
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-21.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=060f160368747cd9b5470c36b3066f77" alt="" width="1596" height="778" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-21.png" />
  Cosmos Advisor configured some experts to react to Gitlab events, you can see those configured in Cosmos settings > Automations ([https://cosmos.augmentcode.com/automations](https://cosmos.augmentcode.com/automations))
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-22.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=328d05431ec367b31b59304d11ee9ccc" alt="" width="1588" height="580" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-22.png" />
  If you expand the Deep Code Reviewer (Gitlab Cloud) you’ll see its triggers:
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-23.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=d8cf191fb4a11bd4027b988a187316f1" alt="" width="1288" height="358" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-23.png" />

## Step 4 - Create a new MR and observe your experts at work

* Create a new session ([https://cosmos.augmentcode.com/home](https://cosmos.augmentcode.com/home)), implement a simple change ex: prompt with “add a hello world banner on top of the web app, then create a MR in ready to review state”
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-24.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=23eed419eb3d516bbabade55c660dfcf" alt="" width="1600" height="1166" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-24.png" />
  Then open your MR, you’ll see the MR Risk analyzer expert commenting on the MR, followed by the Deep Code Review expert:
  <img src="https://mintcdn.com/augment-mtje7p526w/-GW3XrvrHYMzepvG/images/cosmos-integrations/gitlab-cloud/gitlab-cloud-25.png?fit=max&auto=format&n=-GW3XrvrHYMzepvG&q=85&s=5d58444e6efe52b45d96a5be3e1979c1" alt="" width="1724" height="1392" data-path="images/cosmos-integrations/gitlab-cloud/gitlab-cloud-25.png" />
  Congratulations, you’ve configured the native Gitlab integration and your first MR experts!
