- Notifications
You must be signed in to change notification settings - Fork17
AI-based Pull Request Summarizer and Reviewer with Chat Capabilities.
License
tmokmss/bedrock-pr-reviewer
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is a modified version ofcoderabbitai/ai-pr-reviewer to use Amazon Bedrock instead.
ai-pr-reviewer
is an AI-based code reviewer and summarizer for GitHub pull requests using Bedrock's Anthropic Claude models. It is designed to be used as a GitHub Action and can be configured to run on every pull request and review comments.
- PR Summarization: It generates a summary and release notes of the changesin the pull request.
- Line-by-line code change suggestions: Reviews the changes line by line andprovides code change suggestions.
- Continuous, incremental reviews: Reviews are performed on each commitwithin a pull request, rather than a one-time review on the entire pullrequest.
- Cost-effective and reduced noise: Incremental reviews save on Bedrock costsand reduce noise by tracking changed files between commits and the base of thepull request.
- "Light" model for summary: Designed to be used with a "light"summarization model and a "heavy" review model.
- Chat with bot: Supports conversation with the bot in the context of linesof code or entire files, useful for providing context, generating test cases,and reducing code complexity.
- Smart review skipping: By default, skips in-depth review for simplechanges (e.g. typo fixes) and when changes look good for the most part. It canbe disabled by setting
review_simple_changes
andreview_comment_lgtm
totrue
. - Customizable prompts: Tailor the
system_message
,summarize
, andsummarize_release_notes
prompts to focus on specific aspects of the reviewprocess or even change the review objective.
To use this tool, you need to add the provided YAML file to your repository andconfigure the required IAM role. For more information on usage, examples, contributing, andFAQs, you can refer to the sections below.
You have to create an IAM role first for authenticating Bedrock API. You can usethe CloudFormation template to create one. Please replaceSubjectClaimFilters
field value to allow access to your GitHub repository.
ai-pr-reviewer
runs as a GitHub Action. Add the below file to your repository at.github/workflows/ai-pr-reviewer.yml
. Please replacerole-to-assume
field value to the actual IAM role ARN created by the CloudFormation template.
name:Code Reviewpermissions:id-token:writecontents:readpull-requests:writeon:pull_request:pull_request_review_comment:types:[created]concurrency:group:${{ github.repository }}-${{ github.event.number || github.head_ref ||github.sha }}-${{ github.workflow }}-${{ github.event_name =='pull_request_review_comment'&& 'pr_comment' || 'pr' }}cancel-in-progress:${{ github.event_name != 'pull_request_review_comment' }}jobs:review:runs-on:ubuntu-lateststeps: -name:configure aws credentialsuses:aws-actions/configure-aws-credentials@v4with:role-to-assume:arn:aws:iam::123456789012:role/YourOidcIamRolerole-session-name:gha-sessionaws-region:us-east-1 -name:PR reviewuses:tmokmss/bedrock-pr-reviewer@mainenv:GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}with:debug:falsereview_simple_changes:falsereview_comment_lgtm:false
GITHUB_TOKEN
: This should already be available to the GitHub Actionenvironment. This is used to add comments to the pull request.
See:action.yml
Tip: You can change the bot personality by configuring thesystem_message
value. For example, to review docs/blog posts, you can use the following prompt:
Blog Reviewer Prompt
system_message:| You are `/reviewbot` (aka `github-actions[bot]`), a language model trained by Bedrock. Your purpose is to act as a highly experienced DevRel (developer relations) professional with focus on cloud-native infrastructure. Company context - AI reviewer is an AI-powered Code reviewer.It boosts code quality and cuts manual effort. Offers context-aware, line-by-line feedback, highlights critical changes, enables bot interaction, and lets you commit suggestions directly from GitHub. When reviewing or generating content focus on key areas such as - - Accuracy - Relevance - Clarity - Technical depth - Call-to-action - SEO optimization - Brand consistency - Grammar and prose - Typos - Hyperlink suggestions - Graphics or images (suggest Dall-E image prompts if needed) - Empathy - Engagement
You can reply to a review comment made by this action and get a response basedon the diff context. Additionally, you can invite the bot to a conversation bytagging it in the comment (/reviewbot
).
Example:
/reviewbot Please generate a test plan for this file.
Note: A review comment is a comment made on a diff or a file in the pullrequest.
Sometimes it is useful to ignore a PR. For example, if you are using this actionto review documentation, you can ignore PRs that only change the documentation.To ignore a PR, add the following keyword in the PR description:
/reviewbot: ignore
Some of the reviews done by ai-pr-reviewer
Any suggestions or pull requests for improving the prompts are highlyappreciated.
First, you'll need to have a reasonably modern version of
node
handy, testedwith node 17+.
Install the dependencies
$ npm install
Build the typescript and package it for distribution
$ npm run build&& npm run package
GitHub Actions limits the access of secrets from forked repositories. To enablethis feature, you need to use thepull_request_target
event instead ofpull_request
in your workflow file. Note that withpull_request_target
, youneed extra configuration to ensure checking out the right commit:
name:Code Reviewpermissions:contents:readpull-requests:writeon:pull_request_target:types:[opened, synchronize, reopened]pull_request_review_comment:types:[created]concurrency:group:${{ github.repository }}-${{ github.event.number || github.head_ref ||github.sha }}-${{ github.workflow }}-${{ github.event_name =='pull_request_review_comment'&& 'pr_comment' || 'pr' }}cancel-in-progress:${{ github.event_name != 'pull_request_review_comment' }}jobs:review:runs-on:ubuntu-lateststeps: -name:configure aws credentialsuses:aws-actions/configure-aws-credentials@v4with:role-to-assume:arn:aws:iam::123456789012:role/YourOidcIamRolerole-session-name:gha-sessionaws-region:us-east-1 -name:PR reviewuses:tmokmss/bedrock-pr-reviewer@mainenv:GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}with:debug:falsereview_simple_changes:falsereview_comment_lgtm:falsebedrock_light_model:us.anthropic.claude-3-5-haiku-20241022-v1:0bedrock_heavy_model:us.anthropic.claude-3-7-sonnet-20250219-v1:0
See also:https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
Setdebug: true
in the workflow file to enable debug mode, which will show themessages
- Your code (files, diff, PR title/description) will be sent to Bedrock's serversfor processing. Please check with your compliance team before using this onyour private code repositories.
- This action is not affiliated with Bedrock.
Copyright for portions of projectai-pr-reviewer
are held byCodeRabbit as part of projectbedrock-pr-reviewer
. SeeCodeRabbit.LICENSE for the original license.
About
AI-based Pull Request Summarizer and Reviewer with Chat Capabilities.