AI Review
About 304 wordsAbout 1 min
AI code review can automatically detect potential issues in PRs and improve code quality. Cloud Native Build supports two methods:
| Comparison | AI Review Plugin | NPC Event |
|---|---|---|
| Trigger | Automatically on PR events | On-demand via NPC mention in PR comment |
| Use case | Auto-review every PR | On-demand review, flexible control |
| Configuration | .cnb.yml in current repo | No config needed (custom NPC defined in NPC repo) |
Both methods use the CNB_TOKEN environment variable to call platform APIs. When mentioning a custom NPC, the token represents that NPC's identity.
Use AI Review Plugin
Use the cnbcool/code-review plugin to automatically perform code review when PR events are triggered. This plugin is based on CodeBuddy CLI, supports multiple programming languages, automatically filters non-code files, and submits review results as comments on the PR.
Configuration Example
.cnb.yml
main:
pull_request:
- stages:
- name: Code Review
image: cnbcool/code-review:latest
settings:
comment: true
max_comments: 10
fail_on_critical: falseFor more configuration options, see the cnbcool/code-review plugin.
Trigger via NPC Event
Mention an NPC role in a PR comment to trigger the pull_request.comment@npc event for AI review.
- System NPC: Mention
@CodeBuddyin the PR comment:
@CodeBuddy Code review- Custom NPC: First configure a custom NPC role, then mention it in the PR comment:
@cnb/feedback(Review Expert) Code reviewHow It Works
Notes
- Both methods require the pipeline to have permissions to access the repository and submit comments.
- When triggered by an NPC event, the TOKEN permissions are limited to the current repository.
- If you need to modify code during review, enable NPC Work Mode.