Use gitStream for Automatic Code Review Assignment
Automatically assign code reviews based on changed resources, code expertise, branch, and more.
Assign Code Experts
When someone applies a suggest-reviewers
label to a PR, use codeExperts to assign recommended reviewers and post a comment with the explainCodeExperts
automation action.
Configuration Description
Conditions (all must be true):
- The PR has a suggest-reviewers label attached to it.
Automation Actions:
- Use
codeExperts
to assign recommended reviewers. - Use
explainCodeExperts
to post a comment that lists the top code experts for the PR.
Assign Code Experts
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
assign_code_experts:
# Triggered when someone applies a suggest-reviewer label to a PR.
if:
- {{ pr.labels | match(term='suggest-reviewer') | some }}
# More info about code experts
# https://docs.gitstream.cm/filter-functions/#codeexperts
run:
- action: add-reviewers@v1
args:
reviewers: {{ repo | codeExperts(gt=10) }}
- action: explain-code-experts@v1
args:
gt: 10
Branch-Based Review Policies
Automatically route and manage PRs based on the target or destination branch.
Configuration Description
Conditions (all must be true):
- The target or source branch name contains a specified prefix.
Automation Actions:
- Implement custom review policies for the branch.
Review Target Branch
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
{% for item in branches %}
review_target_branch_{{ item.name }}:
if:
- {{ pr.target| match(regex=item.prefix) }}
run:
- action: set-required-approvals@v1
args:
approvals: {{ item.reviews }}
- action: add-comment@v1
args:
comment: |
PRs to the {{ item.name }} branch require {{ item.reviews }} review(s).
- action: add-reviewers@v1
args:
reviewers: [{{ item.reviewers }}]
{% endfor %}
branches:
- name: Release
prefix: r/^release/
reviewers: org/release-team
reviews: 4
- name: Experimental
prefix: r/^experimental-/
reviewers: org/experiment-team
reviews: 1
Review Source Branch
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
{% for item in branches %}
review_source_branch{{ item.name }}:
if:
- {{ branch.name | match(regex=item.prefix) }}
run:
- action: set-required-approvals@v1
args:
approvals: {{ item.reviews }}
- action: add-comment@v1
args:
comment: |
Reviewers from the {{ item.name }} team have automatically been assigned to this PR.
- action: add-reviewers@v1
args:
reviewers: [{{ item.reviewers }}]
{% endfor %}
branches:
- name: ABC
prefix: r/^ABC/
reviewers: org/a-team
- name: XYZ
prefix: r/^XYZ-/
reviewers: org/x-team
Review Sensitive Files
Compare the changed files to a pre-defined list of files and directories in. If any files match, require a review from the team my-organization/security
.
Configuration Description
Conditions (all must be true):
- Any files match the files or directories listed in the
sensitive_files
custom expression. Customize this list for your project.
Automation Actions:
- Assign
my-organization/security
to review the PR. Customize this value to match your organization. - Require 2 approvals.
- Post a comment that explains the automation.
Review Sensitive Files
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
# Assign special teams to review sensitive files.
# This requires the `sensitive` custom expression found at the bottom of this file.
review_sensitive_files:
# For all files listed in the sensitive custom expression.
if:
- {{ files | match(list=sensitive_files) | some }}
run:
# Add reviewers from the dev-leads team, and require two approvals
# Modify `my-organization/security` to match your organization.
- action: add-reviewers@v1
args:
reviewers: [my-organization/security]
- action: set-required-approvals@v1
args:
approvals: 2
- action: add-comment@v1
args:
comment: |
This PR affects one or more sensitive files and requires review from the security team.
# The `sensitive_file_review` automation requires this custom expression.
# Modify this list to suit your security needs.
sensitive_files:
- src/app/auth/
- src/app/routing/
- src/app/resources/
Custom Team Review Policies
Automatically assign the PR author's team to review PRs.
Configuration Description
Conditions (all must be true):
- The PR author is a member of one of the teams specified in the
teams
custom expression.
Automation Actions:
- Assign that team to review the PR.
Assign the Author's Team for Review
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
{% for item in teams %}
review_team_{{ item.name }}:
if:
- {{ pr.author_teams | match(regex=item.regex) }}
run:
- action: add-reviewers@v1
args:
reviewers: [{{ item.team }}]
- action: add-comment@v1
args:
comment: |
This {{ item.name }} team has been automatically assigned to review this PR.
{% endfor %}
teams:
- regex: r/ui-team/
name: UI Team
team: org/ui-team
- regex: r/mobile-team/
name: Mobile
team: org/mobile-team
Distribute Code Reviews to Share Knowledge
Require the reviewer as a previous contributor with code expertise between set thresholds when PR contains Share Knowledge
label.
Configuration Description
Conditions (all must be true):
- A
Share Knowledge
label has been applied to the PR
Automation Actions:
- Choose a previous contributor between specified expertise thresholds and assign them as a reviewer.
- Post a comment explaining why this action was taken.
Knowledge Share
# -*- mode: yaml -*-
manifest:
version: 1.0
automations:
share_knowledge:
if:
- {{ pr.labels | match(term='Share Knowledge') | some }}
run:
- action: add-reviewers@v1
args:
reviewers: {{ repo | codeExperts(gt=30, lt=60) | random }}
- action: add-comment@v1
args:
comment: |
gitStream has assigned a reviewer to increase knowledge sharing on this PR.
Notify Watcher
Automatically notify code reviewers based on a resource watchlist.
Configuration Description
Conditions (all must be true):
- The PR modifies any files listed under the
watchers
custom expression.
Automation Actions:
- Post a comment that notifies the responsible team or individual of the changes.
Notify Watcher
# -*- mode: yaml -*-
manifest:
version: 1.0
## change orgName to match your git organization name.
orgName: company
automations:
{% for item in watchers %}
notify_watcher_{{ item.owner if item.owner else item.team }}:
if:
- {{ (files | match(list=item.files) | some) or (source.diff.files | match(attr="diff", list=item.diffs) | some) }}
run:
- action: add-comment@v1
args:
comment: |
@{{ item.owner if item.owner else (["{{ orgName }}/", item.team] | join) }} - this PR has changes you're watching
{% if files | match(list=item.files) | some -%}
files:
{%- for file in files | filter(list=item.files) %}
- {{ file }}
{%- endfor -%}
{%- endif %}
{% if source.diff.files | match(attr="diff", list=item.diffs) | some -%}
diffs:
{%- for diff in item.diffs -%}
{%- if source.diff.files | match(attr="diff", list=diff) | some %}
- {{ diff }}
{%- for file in source.diff.files | filter(attr="diff", list=diff) | map(attr="new_file") %}
- {{ file }}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- endif %}
- action: add-reviewers@v1
args:
reviewers: {{ item.owner }}
team_reviewers: {{ item.team }}
{% endfor %}
watchers:
- owner: juliaspencer
files:
- src/auth
- team: release
files:
- package.json
- yarn.lock