Sourcery code reviews in GitLab are currently in a closed alpha, but you are able to use Sourcery to review any GitLab merge requests.

To get access to the alpha program and set up Sourcery in GitLab please follow the steps below.

  1. Sign up for a Sourcery account.
  2. Email to request access to the alpha program.
  3. Add the Sourcery review pipeline below into your projects .gitlab-ci.yml
  4. Create a Project/Group Access Token for posting reviews to merge requests - SOURCERY_AI_BOT
  5. Go to Settings > Access Tokens
  6. Create a new Access Token with name SOURCERY_AI_BOT and scope api
  7. Click on "Create access token"
  8. Store your Sourcery token as a Project/Group CI/CD variable - SOURCERY_TOKEN
  9. First get your Sourcery token
  10. Go to Settings > CI/CD
  11. Expand the Variables section.
  12. Add a new variable:
    • Value:
    • Flags:
    • โŒ Protect variable
    • โœ… Mask variable
    • โŒ Expand variable reference
  13. Click on "Add variable"
  14. Open a new merge request to see Sourceryโ€™s comments on your code changes.
  stage: test
  image: python:slim
      - pip install --pre sourcery-nightly
      - sourcery login --token $SOURCERY_TOKEN
      - |
        sourcery assistant review gitlab-merge-request \
            --gitlab-token $SOURCERY_AI_BOT \
            --project $CI_PROJECT_PATH \
            --merge-request $CI_MERGE_REQUEST_IID \
            --commit $CI_COMMIT_SHA
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'