Code Review Using LinearB's AI
Use LinearB's AI with the code-review
action to automatically review the introduced changes to the code.
Configuration Description
Conditions (all must be true):
- A PR is created or new code has been committed to the PR.
- The PR is not on Draft staten and was not created by a bot.
Automation Actions:
- Perform an AI-driven code review and append the review comments to the PR.
- Use
guidelines
to add your prompts to the team or org review
Configuration Example
manifest:
version: 1.0
automations:
linearb_ai_review:
# Triggers only when PR is created or has new commits, see docs
# https://docs.gitstream.cm/execution-model/#action-level-execution-control
if:
- {{ not pr.draft }}
- {{ not (is.bot_author or is.bot_branch) }}
run:
- action: code-review@v1
args:
approve_on_LGTM: {{ approve_pr_on_lgtm }} # optional arg, you can remove it
guidelines: {{ guidelines }}
# Define variables
# Add conditions for PR approvals. For example - allow approval only for specific users
approve_pr_on_lgtm: false
# Add `guidelines` to customize the code review prompts:
# - For repository-specific guidelines: Place `REVIEW_RULES.md` at your repository root
# - For organization-wide guidelines: Place the file in your CM repository root and use `../cm/REVIEW_RULES.md`
# - For team-specific guidelines: Place the file in the team repository root
# The `dump` filter ensures proper YAML formatting when the file content is inserted
guidelines: {{ "./REVIEW_RULES.md" | readFile() | dump }}
is:
bot_author: {{ pr.author | match(list=['github-actions', '_bot_', '[bot]', 'dependabot']) | some }}
bot_branch: {{ branch.name | match(list=['renovate/']) | some }}
Localization Support
You can request the AI to provide code review comments in your preferred language by adding it to the guidelines:
automations:
linearb_ai_review:
if:
- {{ not pr.draft }}
run:
- action: code-review@v1
args:
guidelines: |
- Use Spanish language for all comments
- Focus on code quality and best practices
Repository rules file example
-
Add the rules file to your repo root:
-
Load the file in the code review automation:
Additional Resources
gitStream is a workflow automation tool that enables you to use YAML configuration files to optimize your code review process. Add context to PRs, find code experts for reviews, and automate the merge process to maximize developer productivity.
Learn More about how gitStream Works.
Related Automations:
- Estimate the amount of time it would require someone to complete a PR review.
- Flag missing Jira ticket information
- Label PRs that delete files.
- Label PRs that lack tests
- Provide information about what percent of a PR is new code.
- Request PR authors to provide screenshots in relevant PRs.
More Automations can be found on the Automation Library and Integrations pages.