Automated Code Review

Set up automated pull request and merge request reviews with Droid

Set up Droid to review pull requests and merge requests in GitHub, GitLab, Bitbucket, or Azure DevOps. Droid reviews the changes in CI and reports findings in the pull or merge request. For changes you have not pushed yet, use Local Code Review instead.

These examples use the main branch of Droid Action. Once your workflow is running, see Review commands and fixes to read a review, request another pass, or ask Droid to fix a finding. On GitHub and GitLab, you can also read Droid's comments beside the diff, reply, and merge in Code Review in the Factory App.

Setup

Use the /install-code-review command to set up automated code review for GitHub, GitLab, Bitbucket, or Azure DevOps:

Start Droid:

Bash
droid

Then enter the setup command:

> /install-code-review

The guided flow will:

  1. 1
    Detect your SCM platform (GitHub, GitLab, Bitbucket, or Azure DevOps)
  2. 2
    Verify prerequisites (CLI tools, permissions)
  3. 3
    Walk you through review configuration (depth, security, triggers)
  4. 4
    Open a pull request or merge request with the workflow or pipeline files

For manual setup, use the examples below and the authentication instructions.

GitHub workflows

Keep automatic reviews and on-demand commands in separate workflows. Both examples use the Factory Droid GitHub App. Update both files when you upgrade the action.

Save this as .github/workflows/droid-review.yml. The job reviews non-draft pull requests as they open, reopen, receive new commits, or become ready for review. This example enables automatic code review and therefore also enables security analysis by default. checks: write is needed only for the optional review check.

YAML
name: Droid Auto Review
on:
  pull_request:
    types: [opened, reopened, synchronize, ready_for_review]
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
  cancel-in-progress: true
jobs:
  review:
    if: ${{ !github.event.pull_request.draft }}
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write
      checks: write
    steps:
      - uses: actions/checkout@v5
        with:
          persist-credentials: false
      - uses: Factory-AI/droid-action@main
        with:
          factory_api_key: ${{ secrets.FACTORY_API_KEY }}
          automatic_review: 'true'

Save this as .github/workflows/droid.yml. It handles top-level pull request comments and comments in inline review threads. The workflow runs from the default branch for top-level comments, so merge the workflow there before trying a command.

YAML
name: Droid Review Commands
on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
jobs:
  command:
    if: |
      contains(github.event.comment.body, '@droid') &&
      (github.event_name == 'pull_request_review_comment' || github.event.issue.pull_request)
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write
      checks: write
    steps:
      - uses: actions/checkout@v5
        with:
          persist-credentials: false
      - uses: Factory-AI/droid-action@main
        with:
          factory_api_key: ${{ secrets.FACTORY_API_KEY }}

Droid checks the triggering user's access before handling commands. Bots are not allowed by default; if you need a bot to trigger commands, list only that bot in allowed_bots.

GitHub normally withholds secrets from automatic reviews and inline comment workflows on fork pull requests. With the workflow above, inline replies on such PRs cannot authenticate. A user with write access can post a command such as @droid review as a top-level comment instead. That event uses the base repository's workflow, but does not grant permission to publish a fix to the fork. Do not switch to pull_request_target and run fork code with access to secrets. Restrict access to runners and credentials; not passing a token to Droid does not isolate it from other code running as the same user.

GitLab CI/CD

Use a merge request pipeline. Add the following include to your .gitlab-ci.yml or to a file it includes. Set both the template ref (ref) and the runtime ref (droid_action_ref) to main.

YAML
include:
  - project: 'factory-components/droid-action'
    ref: main
    file: '/templates/droid-review.yml'
    inputs:
      droid_action_ref: 'main'

The component enables automatic code and security review by default. It posts native discussions and can publish a Droid Review commit status, not a GitHub check or an MR approval. If your pipeline declares custom stages, make sure it includes test or set the component's stage input.

Set FACTORY_API_KEY and GITLAB_TOKEN as masked project or group CI/CD variables. The token's account posts the feedback. Prefer a short-lived project access token with api scope and the lowest role for the operation: Reporter for comments, Developer or higher for status and branch publication. Protected variables may not be available to ordinary MR pipelines. Masking does not prevent job code from reading available credentials, so run the job only on trusted branches and runners. Do not give untrusted forks access to parent-project secrets.

See GitLab setup for credential scope, organization guidelines, optional note routing, and the component's inputs. See GitLab commands to trigger a manual review or fix.

Other CI platforms

Follow the setup guide for your platform:

  • Bitbucket setup covers Bitbucket Cloud (including shared pipelines) and Bitbucket Data Center with Jenkins, Bamboo, or another CI system.
  • Azure DevOps setup covers Azure DevOps Services and Azure DevOps Server 2020 or later. Add the pipeline to the target branch as a Build validation policy.

These platforms run automatic reviews. Pull request @droid commands are not supported. Set DROID_ACTION_REF to main in the copied pipeline or template.

How it works

Once enabled, Droid reads the diff and prior feedback, generates candidate findings, and validates them before publishing comments and a summary. On GitHub and GitLab, subsequent reviews use incremental review by default. A clean review can produce a successful check or status, not an approval.

Authentication

Automated review needs two separate kinds of access: permission to run Droid, and permission to post on your pull requests. You set them up independently.

Factory API key (run Droid)

Droid runs using your Factory API key. Create one in the Factory API keys settings, then add it to your repository or organization as a secret named FACTORY_API_KEY. Set the secret before running either workflow. It authenticates Droid, not the source control provider.

GitHub access (post reviews)

To post feedback on your PRs, Droid needs a GitHub token. There are two ways to provide one:

  • Factory Droid GitHub App (recommended). Install the app on the repositories you want Droid to review from your organization settings. If github_token is omitted, the action uses id-token: write to request a short-lived installation token. The action requests contents read and pull requests write for review; fix and report publication request contents write. The check uses the workflow token separately, so its checks: write permission does not come from the app. The action revokes tokens it mints when it finishes. Do not reuse the output token in later steps.

  • Your own token (override). To use a personal access token or your own GitHub App, pass it as github_token. For review, scope it to the repository with contents read and pull requests write. Add contents write only for operations that publish repository changes. You do not need id-token: write when you supply a token.

    YAML
    - uses: Factory-AI/droid-action@main
      with:
        factory_api_key: ${{ secrets.FACTORY_API_KEY }}
        github_token: ${{ secrets.MY_GITHUB_TOKEN }}
Note

On Bitbucket Pipelines, set FACTORY_API_KEY and DROID_BITBUCKET_TOKEN (a Bitbucket access token) as secured variables. The Data Center templates read the same two secrets under their CI's own names: the Jenkinsfile from the Secret text credentials factory-api-key and bitbucket-droid-token, and the Bamboo Specs from the secret variables FACTORY_API_KEY_SECRET and DROID_BITBUCKET_TOKEN_SECRET. On Azure DevOps, add FACTORY_API_KEY as a secret in the droid-review variable group. Reviews post with the pipeline's System.AccessToken, so the build service identity needs Contribute to pull requests.

For the security architecture behind the GitHub App, see Securing the GitHub Action and CI.

Review depth

Choose review_depth during /install-code-review setup, in the workflow, or in the base-branch configuration.

PresetModel aliasReasoning
deep (default)openai-latest-balancedMedium. Use for a more thorough review.
shallowopenai-latest-fastNo explicit effort override. Use for a faster, lower-cost review.
YAML
with:
  automatic_review: 'true'
  review_depth: deep  # or shallow

Factory can update the model behind an alias without a workflow change. Use a preset unless you need to choose a provider or reasoning effort.

Note

If your workflow sets review_model, security_model, or reasoning_effort from an earlier setup, remove them so reviews follow the preset and stay current.

Advanced: model overrides

Warning

Most teams should use review_depth and skip this section. Overrides are only needed if your organization requires a specific model provider.

review_model and reasoning_effort override the code review preset. Security review uses security_model if set, then review_model, then the depth preset. A standalone PR security review with an explicit security_model does not inherit the preset's reasoning effort. fill_model sets the model for PR description fill, which does not use a depth preset.

If you set a model, use a provider tier alias. Factory keeps each alias on its recommended model for that provider and tier, so your reviews still pick up new models automatically. An alias stays in the same price tier when its model changes.

ProviderAliases
OpenAIopenai-latest-premium, openai-latest-balanced, openai-latest-fast
Anthropicanthropic-latest-premium, anthropic-latest-balanced, anthropic-latest-fast
Open-weight modelsoss-latest-premium, oss-latest-balanced, oss-latest-fast
YAML
with:
  automatic_review: 'true'
  review_model: openai-latest-premium  # or anthropic-latest-balanced

Your organization's model policy is checked against the model an alias currently resolves to. If that model is not allowed, Droid falls back to your organization's default model and says so in the tracking comment.

Exact model IDs from Models are also accepted, but they never upgrade on their own, so reviews stay on that model until you edit the workflow. We do not recommend them.

Security review

Security review is a dedicated workflow for STRIDE, OWASP, OWASP LLM Top 10, and supply-chain analysis. See Security Review for automatic PR security reviews, scheduled scans, and local full-codebase audits with the built-in security-review skill.

What Droid reviews

The automated reviewer focuses on clear bugs and issues:

  • Dead/unreachable code
  • Broken control flow (missing break, fallthrough bugs)
  • Async/await mistakes
  • Null/undefined dereferences
  • Resource leaks
  • SQL/XSS injection vulnerabilities
  • Missing error handling
  • Off-by-one errors
  • Race conditions

It skips stylistic concerns, minor optimizations, and architectural opinions.

Customizing the workflow

On GitHub, use workflow inputs for CI-specific overrides and .factory/review.yaml for repository defaults.

Base-branch configuration

Droid reads .factory/review.yaml from the pull request's base commit, not from the proposed changes. Merge a change to that file into the target branch before expecting it to apply. The file is limited to 64 KiB and rejects unknown settings, duplicate keys, or invalid values.

.factory/review.yaml
review_depth: deep
review_incremental: true
review_summary: comment
fail_on_severity: P1
review_max_auto_runs: 5
automatic_security_review: false

Droid applies built-in defaults first, then the base file, then nonempty workflow inputs. In workflow with:, use strings such as 'false' and '0' to override inherited values. Use '[]' to clear a list input and fail_on_severity: 'off' to turn off an inherited priority gate. In the file, use native YAML types, including [] for an empty list and "" to clear fail_on_severity.

Use the file only for the settings identified below and the corresponding security settings. Model overrides, credentials, and diagnostics stay in the workflow. GitLab also reads the file from the MR target commit, but has its own component defaults.

Change the trigger conditions

Set the GitHub events that start the workflow with on.pull_request.types. Within those events, review_auto_triggers can further narrow when Droid runs. To review drafts automatically, remove the draft exclusion in the example job and set review_drafts: 'true'.

Use a path filter to skip starting the workflow for unrelated changes:

YAML
on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
    paths:
      - 'src/**'  # Only review changes in src/
      - '!**/*.test.ts'  # Skip test files

Do not use this workflow-level path filter if Droid Review is a required check. When GitHub skips the workflow, Droid cannot publish the check, and the pull request can stay blocked while GitHub waits for it. To exclude files from the review without filtering out the workflow event, use review_ignore_paths.

Custom review guidelines

Add repository-specific review guidelines by creating .factory/skills/review-guidelines/SKILL.md:

Markdown
---
name: review-guidelines
description: Repository-specific rules for code review.
---
 
Flag queries that can make a separate database call for each item in an unbounded list.

Droid uses these guidelines in both candidate generation and validation. No workflow changes are needed. On GitHub and GitLab, Droid reads the guidelines from the pull or merge request's target branch, not its proposed changes. On GitLab, you can also configure organization-wide guidelines; repository guidelines take precedence if they conflict.

The review-guidelines skill applies to code review only. Security review reads its own security-review-guidelines skill; see Security review custom guidelines. If you want a rule applied in both, add it to both skills.

Skip certain PRs

Add conditions to skip reviews for specific cases:

YAML
jobs:
  code-review:
    # Skip bot PRs and PRs with [skip-review] in title
    if: |
      github.event.pull_request.draft == false &&
      !contains(github.event.pull_request.user.login, '[bot]') &&
      !contains(github.event.pull_request.title, '[skip-review]')

Limit comment count

Use review_severity_threshold and review_ignore_paths to narrow what Droid reports. To ask for fewer comments, add a guideline like this. It is an instruction to the reviewer, not an enforced comment limit.

Guidelines:
- Submit at most 5 comments total, prioritizing the most critical issues

All workflow inputs

These are effective defaults for the GitHub Action before adding repository settings or workflow overrides. The first two tables also list keys accepted in .factory/review.yaml. See Security Review for security settings and the action manifest for the full input list.

When and what to review

SettingDefaultWhat it controls
automatic_reviewfalseRun on automatic PR events without a mention.
automatic_security_reviewFollows automatic_reviewEnable or disable the automatic security pass separately.
review_auto_triggersopened, reopened, synchronize, ready_for_reviewAutomatic events to handle if the workflow also listens for them.
review_draftsfalseReview drafts automatically. Does not restrict manual reviews.
review_depthdeepSelect the review preset.
review_incrementaltrueFocus re-reviews on changes since the previous review.
review_max_auto_runs0 (unlimited)Pause after this many automatic reviews (up to 10,000). @droid resume resets the count.
review_auto_resolvetrueResolve previous Droid threads only when validation confirms the finding was fixed.
review_severity_thresholdP2Lowest code finding priority to report. Accepts P0 (highest), P1, or P2.
review_ignore_pathsGenerated, build, coverage, and lock filesExclude paths using globs. A custom list replaces the defaults.

Output, checks, and fixes

SettingDefaultWhat it controls
review_summarycommentPut the summary in a comment, in a generated description block, or turn it off.
review_summary_sectionsverdict, findings, changes, detailsSelect sections in a list (comma- or newline-separated in workflow inputs). Also accepts diagram, risk, and effort. Use [] to remove optional sections.
review_badgesimageUse image, emoji, or text severity badges.
review_diagramautoLet Droid include a diagram, or set off.
review_reactionstrueSignal review progress and outcome with reactions.
review_check_runtruePublish the Droid Review check using checks: write on the workflow token. If permission is missing, Droid warns and continues.
fail_on_severityUnsetFail the check for a finding at or above P0, P1, or P2. This is separate from the reporting threshold.
fix_modecommitChoose how fixes are published: commit, pr, or off.
show_dropped_findingsfalseShow findings that validation dropped and why.
include_agent_promptstrueInclude prompts for handing findings to a coding agent and the Fix in Factory button when the summary includes findings.
review_effort, review_category_chips, review_suggest_reviewersfalseShow a review effort estimate, finding categories, or reviewer suggestions from CODEOWNERS. Droid does not assign reviewers.
review_pre_merge_checksNoneInclude optional, informational title, description, or linked_issue checks in the review.

A clean review reports a successful check. Open findings normally report a neutral check unless a configured priority gate or security setting makes it fail. A review error can also report a neutral check, so read the summary and workflow logs. A check conclusion is separate from the workflow result or a human approval. Require Droid Review in your GitHub branch rules if you want the code review check to gate merges.

Workflow-only inputs

InputDefaultWhat it controls
include_suggestionstrueInclude suggestion blocks for high-confidence changes.
review_candidates_max_turns100Cap agent turns for candidate generation. An empty value removes the cap.
review_validator_max_turns40Cap agent turns for validation. An empty value removes the cap.
review_model, security_model, reasoning_effort, fill_modelUnsetOverride the model or reasoning effort.

Troubleshooting

For GitHub diagnostics, first open the Actions run linked from the review. If you need prompts or session logs, temporarily set upload_debug_artifacts: 'true'. The droid-review-debug-<run_id> artifact is retained for seven days. It redacts known credential values but can still contain pull request content and tool output. Anyone who can read the Actions run can download it. Leave show_full_output off in sensitive environments because it can expose unredacted data in logs.

The GitLab component keeps .droid-debug/ artifacts for one week. They also can contain MR content and model output after credential redaction. Limit artifact access and see GitLab platform differences for pipeline and fork behavior.