Skip to content
Merged
Changes from 9 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
295 changes: 155 additions & 140 deletions .github/workflows/qwen-code-pr-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: '🧐 Qwen Pull Request Review'

on:
pull_request_target:
types: ['opened']
types: ['opened', 'reopened', 'ready_for_review']
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
issue_comment:
types: ['created']
pull_request_review_comment:
types: ['created']
pull_request_review:
Expand All @@ -13,178 +15,191 @@ on:
description: 'PR number to review'
required: true
type: 'number'
review_mode:
description: 'dry-run (no comments) or comment (post inline comments)'
required: true
default: 'comment'
type: 'choice'
options:
- 'dry-run'
- 'comment'
timeout_minutes:
description: 'Review timeout in minutes'
required: false
default: '60'
type: 'number'

jobs:
review-pr:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] Missing github.repository guard in the job if: condition.

All other workflows in this repo (10+ files including ci.yml, release.yml, gemini-scheduled-pr-triage.yml, etc.) guard with github.repository == 'QwenLM/qwen-code' to prevent execution on forks. Without it, forks that inherit this workflow produce noisy failed runs.

Suggested change
review-pr:
if: |-
github.repository == 'QwenLM/qwen-code' &&
(github.event_name == 'workflow_dispatch' ||

— qwen3.7-max via Qwen Code /review

if: |-
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request_target' &&
github.event.action == 'opened' &&
!github.event.pull_request.draft &&
(github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'COLLABORATOR')) ||
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(github.event.comment.body, '@qwen /review') &&
contains(github.event.comment.body, '@qwen-code /review') &&
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
(github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR')) ||
(github.event_name == 'pull_request_review_comment' &&
contains(github.event.comment.body, '@qwen /review') &&
contains(github.event.comment.body, '@qwen-code /review') &&
(github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR')) ||
(github.event_name == 'pull_request_review' &&
contains(github.event.review.body, '@qwen /review') &&
contains(github.event.review.body, '@qwen-code /review') &&
(github.event.review.author_association == 'OWNER' ||
github.event.review.author_association == 'MEMBER' ||
github.event.review.author_association == 'COLLABORATOR'))
timeout-minutes: 15
runs-on: 'ubuntu-latest'
concurrency:
group: 'qwen-pr-review-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}'
cancel-in-progress: true
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
timeout-minutes: 60
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
runs-on: ['self-hosted', 'linux', 'x64', 'ecs-qwen']
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
permissions:
contents: 'read'
id-token: 'write'
pull-requests: 'write'
issues: 'write'
steps:
- name: 'Checkout PR code'
uses: 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' # v6.0.2
- name: 'Checkout base branch'
uses: 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' # v6.0.2
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
with:
token: '${{ secrets.GITHUB_TOKEN }}'
fetch-depth: 0
ref: '${{ github.event.repository.default_branch }}'
fetch-depth: 1

- name: 'Get PR details (pull_request_target & workflow_dispatch)'
id: 'get_pr'
if: |-
${{ github.event_name == 'pull_request_target' || github.event_name == 'workflow_dispatch' }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: 'Resolve PR context'
id: 'context'
run: |-
set -euo pipefail

if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
PR_NUMBER=${{ github.event.inputs.pr_number }}
PR_NUMBER="${{ github.event.inputs.pr_number }}"
REVIEW_MODE="${{ github.event.inputs.review_mode }}"
elif [ "${{ github.event_name }}" = "issue_comment" ]; then
PR_NUMBER="${{ github.event.issue.number }}"
REVIEW_MODE="comment"
else
PR_NUMBER=${{ github.event.pull_request.number }}
PR_NUMBER="${{ github.event.pull_request.number }}"
REVIEW_MODE="comment"
fi
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
# Get PR details
PR_DATA=$(gh pr view $PR_NUMBER --json title,body,additions,deletions,changedFiles,baseRefName,headRefName)
echo "pr_data=$PR_DATA" >> "$GITHUB_OUTPUT"
# Get file changes
CHANGED_FILES=$(gh pr diff $PR_NUMBER --name-only)
echo "changed_files<<EOF" >> "$GITHUB_OUTPUT"
echo "$CHANGED_FILES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

- name: 'Get PR details (issue_comment)'
id: 'get_pr_comment'
if: |-
${{ github.event_name == 'issue_comment' }}

TIMEOUT_MINUTES="${{ github.event.inputs.timeout_minutes || '60' }}"

{
echo "pr_number=$PR_NUMBER"
echo "review_mode=$REVIEW_MODE"
echo "timeout_minutes=$TIMEOUT_MINUTES"
} >> "$GITHUB_OUTPUT"

- name: 'Run review'
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
COMMENT_BODY: '${{ github.event.comment.body }}'
GITHUB_TOKEN: '${{ secrets.CI_BOT_PAT }}'
OPENAI_API_KEY: '${{ secrets.REVIEW_OPENAI_API_KEY }}'
OPENAI_BASE_URL: '${{ secrets.REVIEW_OPENAI_BASE_URL }}'
OPENAI_MODEL: '${{ vars.QWEN_PR_REVIEW_MODEL }}'
PR_NUMBER: '${{ steps.context.outputs.pr_number }}'
REVIEW_MODE: '${{ steps.context.outputs.review_mode }}'
TIMEOUT_MINUTES: '${{ steps.context.outputs.timeout_minutes }}'
run: |-
PR_NUMBER=${{ github.event.issue.number }}
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
# Extract additional instructions from comment
ADDITIONAL_INSTRUCTIONS=$(echo "$COMMENT_BODY" | sed 's/.*@qwen \/review//' | xargs)
echo "additional_instructions=$ADDITIONAL_INSTRUCTIONS" >> "$GITHUB_OUTPUT"
# Get PR details
PR_DATA=$(gh pr view $PR_NUMBER --json title,body,additions,deletions,changedFiles,baseRefName,headRefName)
echo "pr_data=$PR_DATA" >> "$GITHUB_OUTPUT"
# Get file changes
CHANGED_FILES=$(gh pr diff $PR_NUMBER --name-only)
echo "changed_files<<EOF" >> "$GITHUB_OUTPUT"
echo "$CHANGED_FILES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

- name: 'Run Qwen PR Review'
uses: 'QwenLM/qwen-code-action@5fd6818d04d64e87d255ee4d5f77995e32fbf4c2'
set -euo pipefail

REPO="${GITHUB_REPOSITORY}"
REVIEW_URL="https://github.com/${REPO}/pull/${PR_NUMBER}"
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved

if [ -z "${GITHUB_TOKEN:-}" ]; then
echo "CI_BOT_PAT secret is required for Qwen PR review." >&2
exit 1
fi
if [ -z "${OPENAI_API_KEY:-}" ]; then
echo "REVIEW_OPENAI_API_KEY secret is required for Qwen PR review." >&2
exit 1
fi
if [ -z "${OPENAI_BASE_URL:-}" ]; then
echo "REVIEW_OPENAI_BASE_URL secret is required for Qwen PR review." >&2
exit 1
fi

case "$TIMEOUT_MINUTES" in
''|*[!0-9]*)
echo "Invalid timeout_minutes: ${TIMEOUT_MINUTES}" >&2
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
exit 1
;;
esac
if [ "$TIMEOUT_MINUTES" -le 5 ]; then
echo "timeout_minutes must be greater than 5" >&2
exit 1
fi
if [ "$TIMEOUT_MINUTES" -gt 60 ]; then
echo "timeout_minutes must not exceed the 60 minute job timeout" >&2
exit 1
fi

if ! PR_STATE="$(gh pr view "$PR_NUMBER" --repo "$REPO" --json state --jq '.state')"; then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] Two separate gh pr view API calls (here and line 187) fetch one field each. These can be combined into a single call to reduce API round-trips:

if ! PR_INFO="$(gh pr view "$PR_NUMBER" --repo "$REPO" --json state,isCrossRepository)"; then
  fail "Failed to fetch PR #${PR_NUMBER} metadata."
fi
PR_STATE="$(echo "$PR_INFO" | jq -r '.state')"
IS_FORK="$(echo "$PR_INFO" | jq -r '.isCrossRepository')"

— qwen3.7-max via Qwen Code /review

echo "Failed to determine state for PR #${PR_NUMBER}." >&2
exit 1
fi
if [ "$PR_STATE" != "OPEN" ]; then
echo "Skipping: PR #${PR_NUMBER} is ${PR_STATE}."
exit 0
fi

if ! IS_FORK="$(gh pr view "$PR_NUMBER" --repo "$REPO" --json isCrossRepository --jq '.isCrossRepository')"; then
echo "Failed to determine whether PR #${PR_NUMBER} is a fork PR." >&2
exit 1
fi
if [ "$IS_FORK" = "true" ]; then
echo "Skipping: PR #${PR_NUMBER} is a fork PR."
exit 0
fi

REVIEW_FLAGS=""
if [ "$REVIEW_MODE" = "comment" ]; then
REVIEW_FLAGS="--comment"
fi

Comment thread
yiliang114 marked this conversation as resolved.
Resolved
PROMPT="/review ${REVIEW_URL} ${REVIEW_FLAGS}

IMPORTANT: This is a non-interactive CI run.
- Do NOT ask any confirmation questions. Do NOT use the ask_user_question tool.
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
- Treat these CI instructions as the automation policy for this run: do not run dependency installation, build, test, or autofix steps against PR-controlled code.
- Only use shell commands for trusted qwen review helper subcommands and read-only inspection. Do not execute project scripts, package-manager scripts, or files from the PR worktree.
- Keep verification bounded. If the CI verification budget is exhausted, report unverified findings under \"Unverified due to CI budget\" with a count; do not mark them confirmed.
- If the timeout is close, stop with the findings already verified instead of continuing silently. In comment mode, submit the partial PR review through the normal /review flow.
- If presubmit detects overlapping comments from a previous review, proceed without asking.
- If any step would normally require user confirmation, skip the confirmation and proceed with the default action."

MODEL_ARGS=()
if [ -n "${OPENAI_MODEL:-}" ]; then
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
MODEL_ARGS=(--model "$OPENAI_MODEL")
fi

QWEN_TIMEOUT=$((TIMEOUT_MINUTES - 5))
timeout --kill-after=10s "${QWEN_TIMEOUT}m" qwen \
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
--auth-type openai \
--approval-mode yolo \
"${MODEL_ARGS[@]}" \
--prompt "$PROMPT" \
--output-format stream-json \
> >(tee "/tmp/qwen-review-pr-${PR_NUMBER}.jsonl")
Comment thread
yiliang114 marked this conversation as resolved.
Resolved

if [ ! -s "/tmp/qwen-review-pr-${PR_NUMBER}.jsonl" ]; then
echo "Qwen review completed but produced no output." >&2
exit 1
fi

- name: 'Post fallback comment on failure'
if: |-
failure() &&
steps.context.outputs.review_mode == 'comment' &&
steps.context.outputs.pr_number != ''
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
PR_NUMBER: '${{ steps.get_pr.outputs.pr_number || steps.get_pr_comment.outputs.pr_number }}'
PR_DATA: '${{ steps.get_pr.outputs.pr_data || steps.get_pr_comment.outputs.pr_data }}'
CHANGED_FILES: '${{ steps.get_pr.outputs.changed_files || steps.get_pr_comment.outputs.changed_files }}'
ADDITIONAL_INSTRUCTIONS: '${{ steps.get_pr.outputs.additional_instructions || steps.get_pr_comment.outputs.additional_instructions }}'
REPOSITORY: '${{ github.repository }}'
with:
OPENAI_API_KEY: '${{ secrets.OPENAI_API_KEY }}'
OPENAI_BASE_URL: '${{ secrets.OPENAI_BASE_URL }}'
OPENAI_MODEL: '${{ secrets.OPENAI_MODEL }}'
settings_json: |-
{
"coreTools": [
"run_shell_command",
"write_file"
],
"sandbox": false
}
prompt: |-
You are an expert code reviewer. You have access to shell commands to gather PR information and perform the review.

IMPORTANT: Use the available shell commands to gather information. Do not ask for information to be provided.

Start by running these commands to gather the required data:
1. Run: echo "$PR_DATA" to get PR details (JSON format)
2. Run: echo "$CHANGED_FILES" to get the list of changed files
3. Run: echo "$PR_NUMBER" to get the PR number
4. Run: echo "$ADDITIONAL_INSTRUCTIONS" to see any specific review instructions from the user
5. Run: gh pr diff $PR_NUMBER to see the full diff
6. For any specific files, use: cat filename, head -50 filename, or tail -50 filename

Additional Review Instructions:
If ADDITIONAL_INSTRUCTIONS contains text, prioritize those specific areas or focus points in your review.
Common instruction examples: "focus on security", "check performance", "review error handling", "check for breaking changes"

Once you have the information, provide a comprehensive code review by:
1. Writing your review to a file: write_file("review.md", "<your detailed review feedback here>")
2. Posting the review: gh pr comment $PR_NUMBER --body-file review.md --repo $REPOSITORY

Review Areas:
- **Security**: Authentication, authorization, input validation, data sanitization
- **Performance**: Algorithms, database queries, caching, resource usage
- **Reliability**: Error handling, logging, testing coverage, edge cases
- **Maintainability**: Code structure, documentation, naming conventions
- **Functionality**: Logic correctness, requirements fulfillment

Output Format:
Structure your review using this exact format with markdown:

## 📋 Review Summary
Provide a brief 2-3 sentence overview of the PR and overall assessment.

## 🔍 General Feedback
- List general observations about code quality
- Mention overall patterns or architectural decisions
- Highlight positive aspects of the implementation
- Note any recurring themes across files

## 🎯 Specific Feedback
Only include sections below that have actual issues. If there are no issues in a priority category, omit that entire section.

### 🔴 Critical
(Only include this section if there are critical issues)
Issues that must be addressed before merging (security vulnerabilities, breaking changes, major bugs):
- **File: `filename:line`** - Description of critical issue with specific recommendation

### 🟡 High
(Only include this section if there are high priority issues)
Important issues that should be addressed (performance problems, design flaws, significant bugs):
- **File: `filename:line`** - Description of high priority issue with suggested fix

### 🟢 Medium
(Only include this section if there are medium priority issues)
Improvements that would enhance code quality (style issues, minor optimizations, better practices):
- **File: `filename:line`** - Description of medium priority improvement

### 🔵 Low
(Only include this section if there are suggestions)
Nice-to-have improvements and suggestions (documentation, naming, minor refactoring):
- **File: `filename:line`** - Description of suggestion or enhancement

**Note**: If no specific issues are found in any category, simply state "No specific issues identified in this review."

## ✅ Highlights
(Only include this section if there are positive aspects to highlight)
- Mention specific good practices or implementations
- Acknowledge well-written code sections
- Note improvements from previous versions
GITHUB_TOKEN: '${{ secrets.CI_BOT_PAT }}'
PR_NUMBER: '${{ steps.context.outputs.pr_number }}'
RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
run: |-
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
gh pr comment "$PR_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--body "_Qwen Code review did not complete successfully. See [workflow logs](${RUN_URL})._"
Loading