Configuring reviewers

git:reviewer

Add reviewers to a pull request.

# Applicable Events

  • pull_request
  • pull_request.target

# Parameters

# type

Operation type

  • add-reviewer: Adding a reviewer by including the members specified in the reviewers parameter.
  • add-reviewer-from-repo-members: Selecting a member directly from the repository and adding them as a reviewer.
  • add-reviewer-from-group-members: Selecting a member from the parent organization (direct superior organization) of the repository and adding them as a reviewer.
  • add-reviewer-from-outside-collaborator-members: Selecting an external collaborator from outside the repository and adding them as a reviewer.
  • remove-reviewer Removing a specified member from the existing reviewers.

# reviewers

  • type: Array<String> | String
  • required: false

Usernames of the reviewers to add or remove. Separate multiple usernames using , or ;.

For type values add-reviewer or remove-reviewer, it is a required field.

If both reviewers and reviewersConfig are configured, a specified number of reviewers will be randomly selected from both options.

# count

  • type: Number
  • required: false

Specify the number of reviewers to add and randomly select them.

  • type=add-reviewer,The default value for count is the total number of reviewers in the reviewers list, which means all reviewers will be added by default.
  • type=add-reviewer-from-repo-members,The default value for count is 1.
  • type=add-reviewer-from-group-members,The default value for count is 1.
  • type=add-reviewer-from-outside-collaborator-members,The default value for count is 1.

If the number of existing reviewers is less than the specified count, it will be supplemented to meet the required count.

If the number of existing reviewers is greater than or equal to the specified count, then no action will be taken.

# exclude

  • type: Array<String> | String
  • required: false

Exclude the specified users.

# reviewersConfig

In the file reviewer configuration, if there is a configuration that includes the current change file's reviewer, they will be added as a reviewer.

The statement is effective when the type is set to add-reviewer.

It supports two formats:

  • The string format supports passing the relative path of the configuration file (supports JSON files):
reviewersConfig: config.json
{
   "./src": "name1,name2",
   ".cnb.yml": "name3"
}
  • The object format supports passing the file reviewer configuration directly.
reviewersConfig:
  ./src: name1,name2
  .cnb.yml: name3

In the file reviewer configuration, the key represents the relative path of the file, and the value represents the reviewer's English name, separated by commas.

If both reviewers and reviewersConfig are configured, a specified number of reviewers will be randomly selected from both configurations.

# role

Roles that reviewers can be assigned The optional roles include: Developer, Master, Owner. 如果选择 Developer,则可添加 Developer 及以上权限成员,包括 DeveloperMasterOwner

Schema Definition

# REVIEW_OPERATION_TYPE

  • Enum<String>

add-reviewer | add-reviewer-from-repo-members | add-reviewer-from-group-members | add-reviewer-from-outside-collaborator-members | remove-reviewer

IReviewersConfig

{

    [key: String]: String

}

# ROLE_TYPE

  • Enum<String>

Developer | Master | Owner

# Output Results

{
    // Current valid reviewers
    reviewers,

    // Reviewers formatted for @mention notifications
    reviewersForAt
}

# Configuration Example

  • Add Reviewers
main:
  pull_request:
    - stages:
        - name: Add Reviewers
          type: git:reviewer
          options:
            type: add-reviewer
            reviewers: aaa;bbb
  • Remove Specific Reviewer
main:
  pull_request:
    - stages:
        - name: Remove Reviewer
          type: git:reviewer
          options:
            type: remove-reviewer
            reviewers: aaa
  • Add Reviewer Based on File Modifications (Using ifModify)




 
 
 





main:
  pull_request:
    - stages:
        - name: Need Special Review for Configuration Changes
          ifModify:
            - ".cnb.yml"
            - "configs/**"
          type: git:reviewer
          options:
            type: add-reviewer
            reviewers: bbb
  • Add Reviewers Based on Conditions (Using if)




 
 
 




main:
  pull_request:
    - stages:
        - name: Release After Work Hours? Specify Reviewers.
          if: |
            [ $(date +%H) -ge 18 ]
          type: git:reviewer
          options:
            type: add-reviewer
            reviewers: bbb
  • Randomly Select a Reviewer
main:
  pull_request:
    - stages:
        - name: Random
          image: tencentcom/random
          settings:
            from:
              - aaa
              - bbb
          exports:
            result: CURR_REVIEWER
        - name: Show CURR_REVIEWER
          script: echo ${CURR_REVIEWER}
        - name: Add Reviewer
          type: git:reviewer
          options:
            type: add-reviewer
            reviewers: ${CURR_REVIEWER}
  • Select a Reviewer from Repository Members
main:
  pull_request:
    - stages:
        - name: Add Reviewer
          type: git:reviewer
          options:
            type: add-reviewer-from-repo-members

# Best Practice

Establish a Dedicated Code Review Group for Cross-Review and Automated Merging

  1. Randomly select N reviewers for a pull request and notify them in a group.
  2. Automatically merge the pull request after it has been approved.
  3. Record the reviewers' information in the commit message.
  4. Configure Git to automatically merge pull requests that meet the multi-reviewer criteria.
main:
  review:
    - stages:
        - name: Auto-Merge after Code Review Approval
          type: git:auto-merge
          options:
            mergeType: squash
            removeSourceBranch: true
            mergeCommitMessage: $CNB_LATEST_COMMIT_MESSAGE
          exports:
            reviewedBy: REVIEWED_BY
        # Send review message to WeChat Work bot
        - name: Notify
          image: tencentcom/wecom-message
          settings:
            msgType: markdown
            robot: "155af237-6041-4125-9340-000000000000"
            content: |
              > Auto-Merge after Code Review Approval <@${CNB_BUILD_USER}> 
              > 
              > ${CNB_PULL_REQUEST_TITLE}
              > [${CNB_EVENT_URL}](${CNB_EVENT_URL})
              > 
              > ${REVIEWED_BY}

  pull_request:
    - stages:
        # ... other tasks omitted

        # Send to dedicated code review group
        - name: Add Reviewers
          type: git:reviewer
          options:
            reviewers: aaa,bbb,ccc,ddd
            count: 2
          exports:
            reviewersForAt: CURR_REVIEWER_FOR_AT
        - name: Notify
          image: tencentcom/wecom-message
          settings:
            msgType: markdown
            robot: "155af237-6041-4125-9340-000000000000"
            message: |
              > ${CURR_REVIEWER_FOR_AT}
              > 
              > ${CNB_PULL_REQUEST_TITLE}
              > [${CNB_EVENT_URL}](${CNB_EVENT_URL})
              > 
              > from ${CNB_BUILD_USER}