This demo shows how to integrate OpenCodeReview into your GitHub Actions workflow to automatically review Pull Requests and post review comments.
PR Created/Updated → GitHub Actions Triggered → OCR Reviews Diff → Comments Posted on PR
OR
Comment with trigger keyword ↗
- When a PR is opened, synchronized, or reopened, the workflow triggers
- Alternatively, when a comment containing
/open-code-reviewor@open-code-reviewis posted on a PR, the workflow triggers - It installs OCR via
npm install -g @alibaba-group/open-code-review - Runs
ocr review --from origin/<base> --to origin/<head> --format jsonto analyze the diff - Parses the JSON output and posts inline review comments on the PR using GitHub's Pull Request Review API
Copy ocr-review.yml to your repository's .github/workflows/ directory:
mkdir -p .github/workflows
cp ocr-review.yml .github/workflows/ocr-review.ymlGo to your repository's Settings → Secrets and variables → Actions and add:
| Secret | Required | Description |
|---|---|---|
OCR_LLM_URL |
Yes | LLM API endpoint URL (e.g., https://api.openai.com/v1/chat/completions) |
OCR_LLM_AUTH_TOKEN |
Yes | API authentication token |
OCR_LLM_MODEL |
No | Model name (defaults to gpt-4o) |
OCR_LLM_USE_ANTHROPIC |
No | Set to true if using Anthropic Claude models |
Note:
GITHUB_TOKENis automatically provided by GitHub Actions with the requiredpull-requests: writepermission.The workflow also configures
llm.extra_bodyto disable thinking mode for compatibility with various LLM providers.
Modify the on.pull_request.types array in the workflow file:
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]By default, the workflow triggers when a PR comment starts with /open-code-review or @open-code-review. You can customize these keywords by modifying the if condition in the workflow:
if: |
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/review')) ||
(github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '@mybot'))Or use a more flexible pattern with contains to trigger on any comment containing the keyword:
if: |
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '/review'))Note: The condition
github.event.issue.pull_requestensures the comment is on a PR, not a regular issue.
- name: Install OpenCodeReview
run: npm install -g @alibaba-group/open-code-review@1.0.0Use the --rule flag to pass a custom rules JSON file:
- name: Run OCR review
run: ocr review --rule ./my-rules.json --from origin/${{ github.base_ref }} --to origin/${{ github.head_ref }}Adjust the --concurrency flag for large PRs to control the number of concurrent LLM requests:
- name: Run OCR review
run: ocr review --concurrency 5 --from origin/${{ github.base_ref }} --to origin/${{ github.head_ref }}Use the --background flag to pass additional context that helps OCR better understand the purpose of the changes:
- name: Run OCR review
run: ocr review --background "${{ github.event.pull_request.title }}" --from origin/${{ github.base_ref }} --to origin/${{ github.head_ref }}This is particularly useful when your PR titles follow semantic conventions (e.g., feat(auth): add OAuth2 support) that clearly summarize what the PR implements. The background information helps OCR provide more relevant and context-aware review comments.
By default, review comments are posted using the built-in GITHUB_TOKEN, which appears as github-actions[bot]. You can customize this by creating a GitHub App and using its credentials instead.
For more details about GitHub Apps, see the GitHub Apps documentation.
- Go to your organization or personal account Settings → Developer settings → GitHub Apps → New GitHub App
- Fill in the following:
- GitHub App name: e.g.,
OpenCodeReview Bot - Homepage URL: Your repository or documentation URL
- Webhook: Uncheck "Active" (not needed for this use case)
- GitHub App name: e.g.,
- Under Repository permissions, set:
- Pull requests: Read and write
- Contents: Read-only (for fetching diffs)
- Metadata: Read-only (required)
- Click Create GitHub App
- After creating the app, scroll down to Private keys
- Click Generate a private key
- Download and save the
.pemfile securely
Note your App ID from the app settings page.
- In the left sidebar, click Install App
- Select the repositories where you want to use OCR
- After installation, note the Installation ID from the URL (e.g.,
https://github.com/settings/installations/12345→ Installation ID is12345)
Add the following secrets to your repository (Settings → Secrets and variables → Actions):
| Secret | Description |
|---|---|
GITHUB_APP_ID |
Your GitHub App's ID |
GITHUB_APP_PRIVATE_KEY |
Contents of the .pem file (including -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY-----) |
GITHUB_APP_INSTALLATION_ID |
The Installation ID from Step 3 |
Add a step to obtain a token from the GitHub App, then use it in the "Post review comments to PR" step:
- name: Get GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GITHUB_APP_ID }}
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
- name: Post review comments to PR
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
# ... existing scriptNow review comments will be posted with your custom GitHub App identity (e.g., OpenCodeReview Bot), providing a more professional and distinguishable appearance in your PRs.
When a PR is reviewed, comments appear directly in the PR's "Files changed" tab:
- ✅ If no issues found: A comment saying "No comments generated. Looks good to me."
- 🔍 If issues found: Inline review comments with suggestions using GitHub's native suggestion syntax
The workflow uses GitHub's suggestion code block syntax, so reviewers can apply fixes with one click:
**Suggestion:**
```suggestion
// Fixed code here
```OCR supports both OpenAI and Anthropic API formats:
- OpenAI-compatible APIs (default):
- OpenAI (GPT-4o, GPT-4, etc.)
- Azure OpenAI
- Self-hosted models (vLLM, Ollama, etc.)
- Anthropic APIs (set
OCR_LLM_USE_ANTHROPIC: true):- Anthropic Claude models
- "Failed to parse OCR output": Check that
OCR_LLM_URLandOCR_LLM_AUTH_TOKENsecrets are correctly set - "Cannot find merge-base": Ensure
fetch-depth: 0is set in the checkout step - Review comments not appearing on correct lines: This can happen when the diff has changed since the review started; the workflow handles this gracefully with a fallback to issue comments
Enable debug logging by adding to the OCR review step:
env:
OCR_DEBUG: "1"