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

# GitLab

<Warning>
  **Git Integration (formerly Qodo Merge)** – AI code review agents for pull requests. This documentation describes the Qodo v1 experience. For the Qodo v2 documentation, click [here.](/code-review)
</Warning>

Learn more on how to setup Qodo on GitLab.

## Before you start

Installing Qodo on GitLab allows you to enhance your merge requests with automated insights and improvements.

You can configure it for a single repository or roll it out to multiple projects or groups.

Setup time is usually a few minutes, depending on whether you're using a webhook or CI pipeline approach.

After setup, Qodo will monitor merge requests, process their content, and publish outputs like descriptions, reviews, or improvement suggestions directly to your MRs.

## 1. Log in to Qodo portal

Before setting up Qodo, make sure to [create a Qodo account and sign in](https://app.qodo.ai/signin).

Once you've signed in to the Qodo portal, you can follow the [Qodo Git plugin installation guide](https://app.qodo.ai/qodo-merge/installation) straight from the portal, or continue reading here.

## 2. Set up Qodo

Once you've signed in to your [Qodo account](https://app.qodo.ai/signin), follow the instructions in the [Qodo portal](https://app.qodo.ai/qodo-merge/installation) or below to setup Qodo on GitLab.

### GitLab Repository

<Note>
  This installation method is available to subscribed users only.

  Visit [Qodo's Plans page](/v1/getting-started/setup-and-installation/gitlab/qodo-single-tenant-gitlab) to learn more.
</Note>

<Steps>
  <Step>
    **Generate a GitLab access token:** Generate either a personal, project or group level access token, and store the token in a safe place.

    * **Make sure to enable the "api" scope** in order to allow Qodo to read pull requests, comment and respond to requests.

    <Frame>
      <img src="https://mintcdn.com/qodo/uIkZ6kAWHm6WXqrW/images/v1/image-136.png?fit=max&auto=format&n=uIkZ6kAWHm6WXqrW&q=85&s=897b04328d3bdf65bc0b7686447a91e0" alt="" width="1844" height="518" data-path="images/v1/image-136.png" />
    </Frame>
  </Step>

  <Step>
    **Generate a shared secret through Qodo registration page:**<br />
      a. Go to [https://register.gitlab.pr-agent.codium.ai](https://register.gitlab.pr-agent.codium.ai)<br />
      b. Fill in your generated GitLab token and your company or personal name in the appropriate fields and click **Submit**.<br />
      c. A shared secret will be generated. Store it in a safe place.

    <Frame>
      <img src="https://mintcdn.com/qodo/uIkZ6kAWHm6WXqrW/images/v1/image-137.png?fit=max&auto=format&n=uIkZ6kAWHm6WXqrW&q=85&s=24cb643c49f1f9042e9486608c04dd8f" alt="" width="630" height="546" data-path="images/v1/image-137.png" />
    </Frame>
  </Step>

  <Step>
    **Install a GitLab webhook:**<br />
      a. Go to the settings menu in your repository or groups, and click **Webhooks.**<br />
      b. Click **Add new webhook**.<br />
      c. In the webhook definition form, fill in the following fields:<br />
        i. **URL:** [https://pro.gitlab.pr-agent.codium.ai/webhook](https://pro.gitlab.pr-agent.codium.ai/webhook)<br />
        ii. **Secret token:** Your Qodo key<br />
        iii. **Trigger:** Check the **Comments** and **Merge request events** boxes.<br />
        iv. **SSL Verification:** Check the **Enable SSL verification** box.<br />

    <Frame>
      <img src="https://mintcdn.com/qodo/uIkZ6kAWHm6WXqrW/images/v1/image-138.jpeg?fit=max&auto=format&n=uIkZ6kAWHm6WXqrW&q=85&s=2e6ad377925f06579b9264fcf8eb8ad2" alt="" width="854" height="1203" data-path="images/v1/image-138.jpeg" />
    </Frame>
  </Step>
</Steps>

**You’re all set!** Start using Qodo

<Note>
  [Visit our usage guide](/v1/getting-started/usage-guide) for next steps.
</Note>

### GitLab Pipeline

<Steps>
  <Step>
    **Create a CI file:** Create a new file named `.gitlab-ci.yml` with the content below:

    ```yaml theme={null}
    stages:
      - pr_agent

    pr_agent_job:
      stage: pr_agent
      image:
        name: codiumai/pr-agent:latest
        entrypoint: [""]
      script:
        - cd /app
        - echo "Running PR Agent action step"
        - export MR_URL="$CI_MERGE_REQUEST_PROJECT_URL/merge_requests/$CI_MERGE_REQUEST_IID"
        - echo "MR_URL=$MR_URL"
        - export gitlab__url=$CI_SERVER_PROTOCOL://$CI_SERVER_FQDN
        - export gitlab__PERSONAL_ACCESS_TOKEN=$GITLAB_PERSONAL_ACCESS_TOKEN
        - export config__git_provider="gitlab"
        - export openai__key=$OPENAI_KEY
        - python -m pr_agent.cli --pr_url="$MR_URL" describe
        - python -m pr_agent.cli --pr_url="$MR_URL" review
        - python -m pr_agent.cli --pr_url="$MR_URL" improve
      rules:
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    ```

    * This script will run Qodo Merge on every new merge request.
    * You can modify the `rules` section to run Qodo Merge on different events.
    * You can also modify the `script` section to run different Qodo Merge commands, or with different parameters by exporting different environment variables.

    <Note>
      **Note**:

      The `$CI_SERVER_FQDN` variable is available only from GitLab version 16.10.

      If you're using an earlier version, you can combine the variables `$CI_SERVER_HOST` and `$CI_SERVER_PORT` to achieve the same result.
    </Note>
  </Step>

  <Step>
    **Add masked variables:** Go to **CI/CD**, then select **Variables**. In the masked variables section, add the following masked variables to your GitLab repository:

    * `GITLAB_PERSONAL_ACCESS_TOKEN`: Your GitLab personal access token.
    * `OPENAI_KEY`: Your OpenAI key.

    Don't set the variables as `protected`, or the pipeline will not have access to them.
  </Step>
</Steps>

**You’re all set!** Start using Qodo

<Note>
  [Visit our usage guide](/v1/getting-started/usage-guide) for next steps.
</Note>

### GitLab webhook server

<Steps>
  <Step>
    **Create a new GitLab user:** In the group or project where you'd like to add Qodo Merge, create a new user and give it the **Reporter** role.
  </Step>

  <Step>
    **Generate token:** Generate a `personal_access_token` with `api` access.
  </Step>

  <Step>
    **Obtain secret:** Generate a random secret for your app, and save it for later (`shared_secret`). For example, you can use:

    ```bash theme={null}
    SHARED_SECRET=$(python -c "import secrets; print(secrets.token_hex(10))")
    ```
  </Step>

  <Step>
    **Clone this repository:**

    ```bash theme={null}
    git clone https://github.com/qodo-ai/pr-agent.git
    ```
  </Step>

  <Step>
    **Prepare variables and secrets:**<br />
    a. In the [Qodo Merge configuration file](/v1/configuration/configuration-file/):<br />

    * Set `config.git_provider` to "gitlab"<br />

    b. In the secrets file/variables:<br />

    * Set your AI model key in the respective section<br />
    * In the `[gitlab]` section:<br />
      * Set `personal_access_token` with the token from step 2.<br />
      * Set `shared_secret` with the random secret from step 3.<br />
  </Step>

  <Step>
    **Build Docker image:** Build a Docker image for the app.

    For example using Dockerhub:

    ```bash theme={null}
    docker build . -t gitlab_pr_agent --target gitlab_webhook -f docker/Dockerfile
    docker push codiumai/pr-agent:gitlab_webhook  # Push to your Docker repository
    ```
  </Step>

  <Step>
    **Set the environment variables in the Docker image:**

    ```bash theme={null}
    CONFIG__GIT_PROVIDER=gitlab
    GITLAB__PERSONAL_ACCESS_TOKEN=<personal_access_token>
    GITLAB__SHARED_SECRET=<shared_secret>
    GITLAB__URL=https://gitlab.com
    OPENAI__KEY=<your_openai_api_key>
    ```
  </Step>

  <Step>
    **Create webhook:** Create a webhook in your GitLab project. Make sure to:

    * Set the URL to `http[s]://<PR_AGENT_HOSTNAME>/webhook`
    * Set the secret token to the generated secret from step 3.
    * Enable the triggers `push`, `comments` and `merge request events`.
  </Step>
</Steps>

**You’re all set!** Start using Qodo

<Note>
  [Visit our usage guide](/v1/getting-started/usage-guide) for next steps.
</Note>
