Skip to content

BeeCR CI/CD job template (legacy)

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

🚀 Quick start

  1. Define the following CI/CD variables in your project (or group or GitLab instance) settings:
    • 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 template using the include keyword.
    stages:
      - review
    
    include:
      - remote: 'https://gitlab.com/cvisionlab/beecr/-/raw/1.4.2/templates/beecr/template-always.yml'
    
  1. Define the following CI/CD variables in your project (or group or GitLab instance) settings:
    • 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 template using the include keyword.
    stages:
      - review
    
    include:
      - remote: 'https://gitlab.com/cvisionlab/beecr/-/raw/1.4.2/templates/beecr/template-always.yml'
    

📄 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

The code review job can be configured via environment variables in two alternative ways:

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

See the following lists for the settings that influence jobs defined in this template.

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.

Other options

  • BEECR_URL defines the BeeCR Code Review service url.
    By default, the url is https://beecr.io/api/v1.
  • BEECR_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
  • BEECR_TARGET_EXTRA defines an additional regex pattern for matching files. Useful if you don't want to redefine BEECR_TARGET.
    By default, it is empty.
  • BEECR_TARGET_EXCLUDE defines a regex pattern to exclude files from review (even if they are matched by BEECR_TARGET or BEECR_TARGET_EXTRA). Useful if you don't want to redefine BEECR_TARGET.
    By default, it is empty.
  • BEECR_LANGUAGE defines the review language.
    By default, review comments will be produced in English.

💡 Tip: When you define CI/CD variables via the UI, pay attention to the "Expand variable reference" option (which is enabled by default). It may cause undesired behavior when the $ character is used in the value (which is common, for example, if your value is a RegEx pattern).

Example

Example of configuration by deep merging:

stages:
  - review

include:
  - remote: 'https://gitlab.com/cvisionlab/beecr/-/raw/1.4.2/templates/beecr/template-always.yml'

beecr:
  variables:
    BEECR_TARGET_EXTRA: '\.json$'

▶️ Manual execution

For some reasons, you may wish to control the code review job execution manually. For those purposes, simply include the template-manual.yml file instead of template-always.yml:

stages:
  - review

include:
  - remote: 'https://gitlab.com/cvisionlab/beecr/-/raw/1.4.2/templates/beecr/template-manual.yml'

📌 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 template URL instead of the specific release tag (e.g., 1.4.2). Example:

stages:
  - review

include:
  - remote: 'https://gitlab.com/cvisionlab/beecr/-/raw/main/templates/beecr/template-always.yml'