Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 12 additions & 59 deletions .github/workflows/ocr-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
# and posts review comments directly on the PR.
#
# Triggers:
# - PR opened, synchronized, or reopened (uses pull_request_target for fork secret access)
# - Comment on PR containing '/open-code-review' or '@open-code-review'
# - PR opened (uses pull_request_target for fork secret access)
#
# Required secrets:
# OCR_LLM_URL - LLM API endpoint (e.g., https://api.openai.com/v1/chat/completions)
Expand All @@ -28,52 +27,26 @@ on:
# the diff and does not execute any code from the PR.
pull_request_target:
types: [opened]
issue_comment:
types: [created]

permissions:
contents: read
pull-requests: write

jobs:
code-review:
runs-on: ubuntu-latest
# Run on PR events, or on comments starting with trigger keywords
if: |
github.event_name == 'pull_request_target' ||
(github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/open-code-review')) ||
(github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '@open-code-review'))
runs-on: self-hosted
container:
image: node:20
if: github.event_name == 'pull_request_target'
steps:
- name: Get PR context
id: pr-context
if: github.event_name != 'pull_request_target'
uses: actions/github-script@v7
with:
script: |
// For issue_comment events, get PR info
const prNumber = context.issue.number;
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
core.setOutput('base_ref', pullRequest.base.ref);
core.setOutput('head_ref', pullRequest.head.ref);
core.setOutput('head_sha', pullRequest.head.sha);

- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history needed for merge-base diff
ref: ${{ github.event.pull_request.head.sha || steps.pr-context.outputs.head_sha }}
ref: ${{ github.event.pull_request.head.sha }}

- name: Fetch PR head ref (ensures fork commits are available)
run: git fetch origin pull/${{ github.event.pull_request.number || github.event.issue.number }}/head

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
run: git fetch origin pull/${{ github.event.pull_request.number }}/head

- name: Install OpenCodeReview
run: npm install -g @alibaba-group/open-code-review
Expand All @@ -84,21 +57,14 @@ jobs:
ocr config set llm.auth_token ${{ secrets.OCR_LLM_AUTH_TOKEN }}
ocr config set llm.model ${{ secrets.OCR_LLM_MODEL }}
ocr config set llm.use_anthropic ${{ secrets.OCR_LLM_USE_ANTHROPIC }}
ocr config set llm.extra_body '{"thinking": {"type": "disabled"}}'
ocr config set llm.extra_body '{"enable_thinking": false}'
ocr config set language English

- name: Run OpenCodeReview
id: review
run: |
# Get base ref and head SHA from PR context (different for comment triggers)
# Note: We use HEAD_SHA instead of origin/${HEAD_REF} to support fork PRs,
# because fork branches don't exist on the origin remote.
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
BASE_REF="${{ github.event.pull_request.base.ref }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
else
BASE_REF="${{ steps.pr-context.outputs.base_ref }}"
HEAD_SHA="${{ steps.pr-context.outputs.head_sha }}"
fi
BASE_REF="${{ github.event.pull_request.base.ref }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"

echo "Reviewing PR: ${HEAD_SHA} against origin/${BASE_REF}"

Expand Down Expand Up @@ -159,20 +125,7 @@ jobs:

// Prepare PR review with inline comments
const prNumber = context.issue.number;
let commitSha;

// Get commit SHA from event context
if (context.eventName === 'pull_request_target') {
commitSha = context.payload.pull_request.head.sha;
} else {
// For comment events, we need to fetch the PR
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
commitSha = pullRequest.head.sha;
}
let commitSha = context.payload.pull_request.head.sha;

// Build review comments array for the PR review API
// Only inline comments with line info can be posted via createReview
Expand Down