Skip to content

Code Review Using LinearB's AI

Use LinearB's AI with the code-review action to automatically review the introduced changes to the code.

code-review

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:
    # Trigger it only when PR is created or has new commits
    on:
      - pr_created
      - commit
    if:
      - {{ not pr.draft }}
      - {{ pr.author | match(list=['github-actions', '_bot_', 'dependabot', '[bot]']) | nope }}
    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 }}

Configuration Example

manifest:
  version: 1.0

automations:
  linearb_ai_review:
    if:
      - {{ not pr.draft }}
      - {{ pr.author | match(list=['github-actions', '_bot_', 'dependabot', '[bot]']) | nope }}
    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 add your prompts to the review, you can have org wide instructions
# by placing the `REVIEW_RULES.md` in the `cm` repo or team level instructions by adding it to
# the team repo.
# Note: To when the file is in the `cm` repo, use this example: `../cm/REVIEW_RULES.md`
guidelines: {{ "./REVIEW_RULES.md" | readFile() | dump }}

Configuration Example

manifest:
  version: 1.0

automations:
  linearb_ai_review:
    if:
      - {{ pr.author | match(list=['github-actions', '_bot_', 'dependabot', '[bot]']) | nope }}
    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 add your prompts to the review, you can have org wide instructions
# by placing the `REVIEW_RULES.md` in the `cm` repo or team level instructions by adding it to
# the team repo.
# Note: To when the file is in the `cm` repo, use this example: `../cm/REVIEW_RULES.md`
guidelines: {{ "./REVIEW_RULES.md" | readFile() | dump }}

./REVIEW_RULES.md example

This file should be created in your repo root:

1. Do not comment on missing documentation.
2. Do not comment on missing tests.
3. For JavaScript code, enforce using camelCase for variables and functions.

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:

More Automations can be found on the Automation Library and Integrations pages.