Skip to content

BeeCR CI/CD job component (GitLab 17+)

⚠️ Note: This section describes how to set up code review as a GitLab CI/CD component (generally available in GitLab 17). If you are looking to set up code review in a "legacy" way via templates, please refer to the "CI/CD job template" document. If you prefer not to use CI/CD at all, please refer to the alternative integration method via "Webhook".

🚀 Quick start

  1. Define the following CI/CD variables in your project (or group or GitLab instance):
    • BEECR_API_KEY with an API key provided to you by the BeeCR team.
    • BEECR_GITLAB_TOKEN with your GitLab access token (project or group). The token must have at least developer-level permissions with the "api" scope.

      💡 Tip: We recommend giving it a nice name, such as BeeCR Code Reviewer, because code review comments will be authored by GitLab Bot under this name.

  2. In your project's settings, make sure that CI/CD is enabled and that at least one GitLab runner is available.
  3. Create (or modify if it exists) a .gitlab-ci.yml file in the root of your repository by adding a review stage to the stages definition and including the beecr component using the include keyword.
    stages:
      - review
    
    include:
      - component: gitlab.com/cvisionlab/beecr/beecr@1.4.2
    
  1. Define the following CI/CD variables in your project (or group or GitLab instance):
    • BEECR_GITLAB_TOKEN with your GitLab access token (project or group). The token must have at least developer-level permissions with the "api" scope.

      💡 Tip: We recommend giving it a nice name, such as BeeCR Code Reviewer, because code review comments will be authored by GitLab Bot under this name.

  2. In your project's settings, make sure that CI/CD is enabled and that at least one GitLab runner is available.
  3. Create (or modify if it exists) a .gitlab-ci.yml file in the root of your repository by adding a review stage to the stages definition and including the beecr component using the include keyword.
    stages:
      - review
    
    include:
      - component: gitlab.com/cvisionlab/beecr/beecr@1.4.2
    

📄 Conventions

  1. The job runs only for merge requests.
  2. Review results are added as comments to the files.
  3. If the commit message contains any of message includes one of:
    [no_review], [skip_review], [no review], [skip review], [no-review], [skip-review], [mute],
    :no_review:, :skip_review:, :no review:, :skip review:, :no-review:, :skip-review:, :mute:,
    the review job is not triggered.

🛠 Configuration

Credentials

Credentials for the code review job can be configured via environment variables. The following variables have to be defined:

  • BEECR_API_KEY defines an BeeCR key for accessing the API.
  • BEECR_GITLAB_TOKEN is a GitLab personal, project, or group access token used to interact with GitLab via API. Developer-level permission with "api" scope is required.

Credentials for the code review job can be configured via environment variables. The following variable have to be defined:

  • BEECR_GITLAB_TOKEN is a GitLab personal, project, or group access token used to interact with GitLab via API. Developer-level permission with "api" scope is required.

💡 Tip: GitLab provides two alternative ways to set variables:

We recommend setting variables that contain secret information (API keys, tokens, etc.) via the GitLab settings and enabling "mask mode" for them to prevent leakage.

Other options

See the following lists for the input options that influence jobs defined in this CI/CD component:

  • url defines the BeeCR Code Review service url.
    By default, the url is https://beecr.io/api/v1.
  • stage defines the stage at which the job will be executed.
    By default, the stage is review.
  • when defines whether the job will be executed manually or not.
    Use "manual" to make the review job runs manually.
    Default is "always".
  • target defines a regex pattern for matching files.
    By default, the target regex is \.(py|c|h|cpp|hpp|cs|java|kt|swift|php|go|sh|(j|t)sx?)$ which enables the review for files with the following languages:
    • Python
    • C/C++
    • C#
    • Java
    • Kotlin
    • Swift
    • PHP
    • Go
    • Bash/Shell
    • JavaScript/Typescript
  • target-extra defines an additional regex pattern for matching files. Useful if you don't want to redefine target.
    By default, it is empty.
  • target-exclude defines a regex pattern to exclude files from review (even if they are matched by target or target-extra). Useful if you don't want to redefine target.
    By default, it is empty.
  • language defines the review language.
    By default, review comments will be produced in English.

Example

Example of configuration:

stages:
  - review

include:
  - component: gitlab.com/cvisionlab/beecr/beecr@1.4.2
    inputs:
      target-extra: '\.json$'

▶️ Manual execution

For some reasons, you may wish to control the code review job execution manually. For those purposes, simply set value manual to the when input option:

stages:
  - review

include:
  - component: gitlab.com/cvisionlab/beecr/beecr@1.4.2
    inputs:
      when: manual

📌 Pin/unpin version

All the examples above refer to a specific CI/CD job version. If you wish to refer to the latest version, simply use main in the component URL instead of the specific release tag (e.g., 1.4.2). Example:

stages:
  - review

include:
  - component: gitlab.com/cvisionlab/beecr/beecr@main