GitLab Integration¶
Run as a GitLab CI Pipeline¶
The simplest route — MergeMate runs inside your existing GitLab CI without any extra infrastructure.
-
Add this to your repo's
.gitlab-ci.yml:stages: - mergemate mergemate_job: stage: mergemate image: name: imtiyaazsalie/mergemate-review:latest entrypoint: [""] script: - cd /app - echo "Running MergeMate" - 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 - mergemate-review --pr_url="$MR_URL" describe - mergemate-review --pr_url="$MR_URL" review - mergemate-review --pr_url="$MR_URL" improve rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'This fires on every new merge request. Tweak the
rulesblock to target different events, and adjust thescriptsection to run a different set of commands or pass custom env vars. -
In your GitLab repo, go to Settings > CI/CD > Variables and add these masked variables:
GITLAB_PERSONAL_ACCESS_TOKEN— a token with API accessOPENAI_KEY— your model provider key
If your base branches aren't protected, don't mark the variables as protected — otherwise the pipeline won't be able to read them.
$CI_SERVER_FQDNavailabilityThe
$CI_SERVER_FQDNvariable was introduced in GitLab 16.10. On older versions, combine$CI_SERVER_HOSTand$CI_SERVER_PORTto build the equivalent URL.SSL verification
Use
gitlab__SSL_VERIFYto point at a custom CA bundle. GitLab exposes$CI_SERVER_TLS_CA_FILEfor this purpose. You can also disable verification entirely withgitlab__SSL_VERIFY=false, though that's not recommended in production.
Run as a Webhook Server¶
For a self-hosted setup that responds to webhook events:
-
In GitLab, create a dedicated user and assign it the Reporter role on the target group or project.
-
Generate a
personal_access_tokenwithapiscope for that user. -
Create a random shared secret:
-
Clone the repo:
-
Wire up your config. If you're not setting these as environment variables at runtime:
- In your configuration: set
config.git_provider = "gitlab" - In your secrets: set your model provider key, then under
[gitlab]fill inpersonal_access_token(from step 2) andshared_secret(from step 3) - Authentication type: set
auth_type = "oauth_token"for gitlab.com or modern instances. Use"private_token"for older versions (e.g. GitLab 11.x) or private deployments.
- In your configuration: set
-
Build and push the Docker image:
-
Provide the environment variables (exact method depends on your container runtime):
CONFIG__GIT_PROVIDER=gitlab GITLAB__PERSONAL_ACCESS_TOKEN=<personal_access_token> GITLAB__SHARED_SECRET=<shared_secret> GITLAB__URL=https://gitlab.com GITLAB__AUTH_TYPE=oauth_token # or "private_token" for older instances OPENAI__KEY=<your_openai_api_key> PORT=3000 # optional — override the webhook server port -
Create a webhook in your GitLab project. Point the URL at
http[s]://<YOUR_HOST>/webhook, set the secret token to the value from step 3, and enable Push events, Comments, and Merge request events. -
Test by opening a merge request or dropping a MergeMate command into a PR comment.
Deploy as a Lambda Function¶
AWS Lambda env vars can't contain dots — replace each . with __. For example, GITLAB.PERSONAL_ACCESS_TOKEN becomes GITLAB__PERSONAL_ACCESS_TOKEN.
- Follow steps 1–5 from Run as a Webhook Server above.
-
Build a Lambda-compatible image:
-
Push to ECR:
-
Create a Lambda function from the image. Set timeout to at least 3 minutes.
- Give the Lambda a Function URL.
- Set
AZURE_DEVOPS_CACHE_DIRto/tmp(or another writable path) in the Lambda's environment variables. - Use the Function URL as your webhook URL (steps 8–9 of the webhook server setup). It'll be
https://<LAMBDA_FUNCTION_URL>/webhook.
Using AWS Secrets Manager¶
For production Lambda deployments, use Secrets Manager instead of plain environment variables:
-
Create individual secrets for each GitLab webhook. Format:
-
Create a main config secret for shared settings:
-
Set these env vars on your Lambda:
-
In your GitLab webhook config, set the Secret Token to match the Secrets Manager secret name from step 1 (e.g.
project-webhook-secret-001).Important
When using Secrets Manager, the GitLab webhook secret must equal the Secrets Manager secret name.
-
Add
secretsmanager:GetSecretValueto your Lambda execution role's IAM policy.