'Default reviewers gitlab

Long story short: I have a subgroup that contains 100 project, I want to assign default MR reviewers for this subgrouo so it can apply on all the projects there! Is there any hacky way to do it? Gitlab doesnt offer the possibility to configure this per-subgroup level. Thanks



Solution 1:[1]

A hacky way might be to create a job in the MR pipeline to do this using a project access token or group access token with API read/write scope.

Example using python-gitlab's CLI.

First, create a group access token and set it on the subgroup CI/CD variables settings as GROUP_ACCESS_TOKEN.

Then also set a REVIEWER_IDS variable on the subgroup with the user IDs of the default reviewers.

assign-mr:
  stage: .post  # use .post to avoid getting in the way of other jobs
  needs: []  # start immediately
  variables:
    # set these variables at the subgroup level settings:
    # User IDs of the reviewers you want to add to the MR
    # REVIEWER_IDS: "1,2,3"
    # set this as a masked variable at the subgroup settings:
    # GROUP_ACCESS_TOKEN: <secret!>

    GIT_STRATEGY: none  # skip checkout
    GITLAB_URL: "$CI_SERVER_URL"  # used by python-gitlab
    GITLAB_PRIVATE_TOKEN: "$GROUP_ACCESS_TOKEN" # used by python-gitlab

  image:
    name: registry.gitlab.com/python-gitlab/python-gitlab:latest
    entrypoint: [""]
  rules:
    - if '$CI_PIPELINE_SOURCE == "merge_request"'
  script: |
    if [[ -f ".done" ]]; then
        echo "Already successfully updated MR. Skipping!" > /dev/stderr
        exit 0
    fi
    gitlab project-merge-request update \
      --project-id "$CI_PROJECT_ID" \
      --iid "$CI_MERGE_REQUEST_IID" \
      --reviewer-ids "$REVIEWER_IDS" \
   && \
   touch .done  # marker to know if we successfully updated the MR

  cache: # use a cache so we only update the MR once (allowing changes afterwards)
    key: "$CI_MERGE_REQUEST_IID"
    paths:
      - .done

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1