GitLab

Learn more on how to setup Qodo Merge on GitLab.

Before you start

Installing Qodo Merge 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 Merge 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 Merge, make sure to create a Qodo account and sign in.

Once you've signed in to the Qodo Portal, you can follow the Qodo Merge installation guide straight from the portal, or continue reading here.

2. Setup Qodo Merge

Once you've signed in to your Qodo account, follow the instructions in the Qodo Portal or below to setup Qodo Merge on GitLab.

GitLab Repository

  1. 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 Merge to read pull requests, comment and respond to requests.

  1. Generate a shared secret through Qodo Merge registration page:

    1. Fill in your generated GitLab token and your company or personal name in the appropriate fields and click Submit.

    2. A shared secret will be generated. Store it in a safe place.

  1. Install a GitLab webhook:

    1. Go to the settings menu in your repository or groups, and click Webhooks.

    2. Click Add new webhook.

    3. In the webhook definition form, fill in the following fields:

      1. URL: https://pro.gitlab.pr-agent.codium.ai/webhook

      2. Secret token: Your Qodo key

      3. Trigger: Check the Comments and Merge request events boxes.

      4. SSL Verification: Check the Enable SSL verification box.

You’re all set! Start using Qodo Merge.

Visit our usage guide for next steps.

GitLab Pipeline

  1. Create a CI file: Create a new file named .gitlab-ci.yml with the content below:

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: 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.

  1. Add masked vairables: Go to CI/CD, then choose 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.

You’re all set! Start using Qodo Merge.

Visit our usage guide for next steps.

GitLab Webhook Server

  1. 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.

  2. Generate token: Generate a personal_access_token with api access.

  3. Obtain secret: Generate a random secret for your app, and save it for later (shared_secret). For example, you can use:

SHARED_SECRET=$(python -c "import secrets; print(secrets.token_hex(10))")
  1. Clone this repository:

git clone https://github.com/qodo-ai/pr-agent.git
  1. Prepare variables and secrets:

    1. In the Qodo Merge configuration file:

      • Set config.git_provider to "gitlab"

    2. In the secrets file/variables:

      • Set your AI model key in the respective section

      • In the [gitlab] section:

        • Set personal_access_token with the token from step 2.

        • Set shared_secret with the random secret from step 3.

  2. Build Docker image: Build a Docker image for the app. For example using Dockerhub:

    docker build . -t gitlab_pr_agent --target gitlab_webhook -f docker/Dockerfile
    docker push codiumai/pr-agent:gitlab_webhook  # Push to your Docker repository
  3. Set the environmente variables in the Docker image:

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>
  1. 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.

You’re all set! Start using Qodo Merge.

Visit our usage guide for next steps.

Last updated

Was this helpful?