Skip to content

[feat] Add comprehensive Claude PR review with inline comments #4453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Jul 29, 2025

Conversation

christian-byrne
Copy link
Contributor

@christian-byrne christian-byrne commented Jul 14, 2025

Summary

This PR implements a comprehensive PR review system powered by Claude that posts individual inline comments on specific lines of code, rather than a single summary comment.

Key Features

  • Inline Comments: Each issue is posted as a separate comment on the exact line of code
  • Comprehensive Analysis: Reviews cover security, performance, architecture, and code quality
  • Natural Language Instructions: Uses clear, maintainable instructions instead of complex bash scripts
  • Proper Formatting: Comments are properly formatted with severity levels and actionable suggestions

Technical Implementation

  1. Workflow Configuration (.github/workflows/claude-pr-review.yml):

    • Triggers on claude-review label
    • Waits for CI checks to complete before reviewing
    • Configures allowed tools including gh api commands
    • Sets up environment variables (PR_NUMBER, GITHUB_TOKEN, etc.)
  2. Review Instructions (.claude/commands/comprehensive-pr-review.md):

    • Natural language instructions for Claude to follow
    • Examples of proper gh api command format (single-line)
    • Categories for different types of issues
    • Clear formatting guidelines for comments

Problem Solved

Previously, Claude would post all review feedback as a single large comment. This made it difficult for developers to:

  • See issues in context
  • Address feedback on specific lines
  • Track which issues have been resolved

With inline comments, each piece of feedback appears directly on the relevant line of code.

Testing

This PR was tested on itself - you can see the inline review comments that were successfully posted by Claude demonstrating the system works correctly.

Future Improvements

  • Add configuration for severity thresholds
  • Support for suggesting code changes directly
  • Integration with existing linting tools

Fixes the issue where PR reviews were posted as summary comments instead of inline feedback.

This service contains multiple intentional violations to test
the Claude PR review action including:
- Security issues (hardcoded secrets, XSS, SQL injection)
- Performance problems (N+1 queries, memory leaks)
- Code quality issues (deep nesting, long functions)
- Library misuse (not using PrimeVue, api.apiURL, etc.)
- TypeScript violations (@ts-expect-error, any types)
@christian-byrne christian-byrne requested a review from a team as a code owner July 14, 2025 23:52
- Removed unused import and variable
- Prefixed unused parameters with underscore
- Used 'as any' instead of @ts-expect-error to avoid type check

All architectural violations remain for Claude to catch.
@christian-byrne christian-byrne added the claude-review Add to trigger a PR code review from Claude Code label Jul 15, 2025
Added minimal browser test to satisfy Danger requirements
for testing changes to src/ files.
Simple one-line change to satisfy Danger requirement for browser test coverage.
@christian-byrne christian-byrne requested a review from a team as a code owner July 15, 2025 14:58
@christian-byrne christian-byrne added claude-review Add to trigger a PR code review from Claude Code and removed claude-review Add to trigger a PR code review from Claude Code labels Jul 15, 2025
Fixed check regex to use lowercase names that match the actual
CI workflow names: eslint, prettier, test
@christian-byrne christian-byrne added claude-review Add to trigger a PR code review from Claude Code and removed claude-review Add to trigger a PR code review from Claude Code labels Jul 15, 2025
- Added id-token: write permission for OIDC
- Changed to claude-code-base-action@beta
- Fixed prompt parameter to reference the review command
- Added allowed_tools parameter
@christian-byrne christian-byrne added claude-review Add to trigger a PR code review from Claude Code and removed claude-review Add to trigger a PR code review from Claude Code labels Jul 15, 2025
- Increased max_turns from 1 to 30 (was stopping after reading file)
- Added WebFetch to allowed tools for knowledge loading
- Improved prompt to be explicit about executing bash blocks
- Claude needs multiple turns to run the full review script
Changed allowed_tools to Bash(*) to permit all commands needed by
the review script including gh, git, curl, jq, etc.
@christian-byrne christian-byrne added claude-review Add to trigger a PR code review from Claude Code and removed claude-review Add to trigger a PR code review from Claude Code labels Jul 15, 2025
The review command had setup code and instructions but was missing
the actual code to analyze files and post comments. Added basic
analysis for hardcoded secrets and console.log as a test.
- Updated workflow prompt to explicitly tell Claude to analyze files
- Removed bash analysis code - Claude should use Read tool to analyze
- Made it clear Claude needs to perform Phases 3-6 analysis itself
- Clarified Claude is in repo root directory
- Specified what files will be available after setup
- Explicit instructions to use Read tool on changed_files.txt
- Clear example of how to call post_review_comment function
@christian-byrne christian-byrne added claude-review Add to trigger a PR code review from Claude Code and removed claude-review Add to trigger a PR code review from Claude Code labels Jul 17, 2025
@christian-byrne christian-byrne removed the claude-review Add to trigger a PR code review from Claude Code label Jul 24, 2025
}

// Async function without error handling
async riskyOperation() {
Copy link

Choose a reason for hiding this comment

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

[Quality] Medium Priority\n\nIssue: Missing error handling in async function\nContext: Unhandled promise rejections can crash the application or leave it in an inconsistent state\nSuggestion: Add proper try-catch blocks and error handling: try { ... } catch (error) { /* handle/log error */ }

}

// Hardcoded strings that should use i18n
getErrorMessages() {
Copy link

Choose a reason for hiding this comment

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

[Quality] Medium Priority\n\nIssue: Hardcoded user-facing strings instead of using i18n\nContext: User-facing strings should support internationalization for accessibility\nSuggestion: Use vue-i18n for all user-facing strings. Place translations in src/locales/en/main.json and use () function

}

// Performance issue - loading everything into memory
async loadAllData() {
Copy link

Choose a reason for hiding this comment

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

[Performance] Medium Priority\n\nIssue: Loading all data into memory without pagination\nContext: Loading thousands of records at once can cause memory issues and poor performance\nSuggestion: Implement pagination, lazy loading, or streaming for large datasets instead of loading everything at once


// Direct window manipulation
if (typeof window !== 'undefined') {
;(window as any).testService = testReviewService // Global pollution
Copy link

Choose a reason for hiding this comment

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

[Quality] Low Priority\n\nIssue: Global window object pollution\nContext: Attaching services to the global window object creates namespace conflicts and makes testing difficult\nSuggestion: Avoid attaching services to global window object; use proper module exports and dependency injection instead

- Implement Claude-powered PR review that posts inline comments
- Fix newline formatting in comment bodies using variables
- Configure allowed tools to support gh api commands
- Convert from multi-line to single-line command format
- Add clear instructions for posting individual line-specific feedback

This enables automated code review with specific, actionable feedback
posted directly on the relevant lines of code in PRs.
@christian-byrne christian-byrne changed the title [test] Test PR for Claude review action [feat] Add comprehensive Claude PR review with inline comments Jul 27, 2025
Copy link

github-actions bot commented Jul 27, 2025

⚠️ Warnings

⚠️ Warning: Visual Documentation Missing

If this PR changes user-facing behavior, visual proof (screen recording or screenshot) is required. PRs without applicable visual documentation may not be reviewed until provided.
You can add it by:

  • GitHub: Drag & drop media directly into the PR description

  • YouTube: Include a link to a short demo

@christian-byrne christian-byrne added claude-review Add to trigger a PR code review from Claude Code and removed claude-review Add to trigger a PR code review from Claude Code labels Jul 28, 2025
Copy link

claude bot commented Jul 28, 2025

Claude finished @christian-byrne's task —— View job


Comprehensive PR Review

I've successfully completed the comprehensive PR review following the instructions in .claude/commands/comprehensive-pr-review.md and posted individual inline comments for each issue found.

Tasks:

  • Read comprehensive PR review instructions from .claude/commands/comprehensive-pr-review.md
  • Get repository information and commit SHA
  • Analyze changed files for issues (architecture, security, performance, code quality)
  • Post individual inline comments using gh api commands (no summary comment)
  • Complete review process

Repository: Comfy-Org/ComfyUI_frontend
Commit SHA: 1677513

Issues Found and Commented:

Posted 5 individual inline comments covering:

  1. Quality Issue (.claude/commands/comprehensive-pr-review.md:141) - Hardcoded repository name in example command that reduces template reusability

  2. Security Issue - Medium (.github/workflows/claude-pr-review.yml:5) - Broad permissions granted that may not all be necessary, violating principle of least privilege

  3. Security Issue - High (.github/workflows/claude-pr-review.yml:78) - Wildcard git permissions could allow dangerous operations like force push or repository damage

  4. Quality Issue - Low (browser_tests/tests/interaction.spec.ts:4) - Generic test comment lacks specific purpose and context

  5. Quality Issue - Medium (src/locales/zh-TW/settings.json:332) - Translation key removed without verification of usage, could cause missing translation errors

Each issue has been posted as a separate inline comment on the specific line of code as instructed. No summary comment was created per the requirements.


-f commit_id="$COMMIT_SHA" \
-f side='RIGHT' || echo "Failed to post comment at $file_path:$line_number"
}
Bash: gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/Comfy-Org/ComfyUI_frontend/pulls/$PR_NUMBER/comments -f body="..." -f commit_id="..." -f path="..." -F line=42 -f side="RIGHT"
Copy link

Choose a reason for hiding this comment

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

[Quality] Medium Priority

Issue: Hardcoded repository name in gh api command example
Context: The example shows a hardcoded ''Comfy-Org/ComfyUI_frontend'' path which may not work for other repositories using this template
Suggestion: Use variables like OWNER/REPO that are dynamically populated from the gh repo view command

@@ -4,6 +4,8 @@ permissions:
contents: read
pull-requests: write
Copy link

Choose a reason for hiding this comment

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

[Security] Medium Priority

Issue: Broad permissions granted to workflow that may not all be necessary
Context: The workflow has write permissions for contents, issues, statuses which increases attack surface if compromised
Suggestion: Follow principle of least privilege - only grant the minimum permissions needed (pull-requests: write and contents: read appear sufficient)

timeout_minutes: 30
allowed_tools: "Bash(git:*),Bash(gh api:*),Bash(gh pr:*),Bash(gh repo:*),Bash(jq:*),Bash(echo:*),Read,Write,Edit,Glob,Grep,WebFetch"
Copy link

Choose a reason for hiding this comment

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

[Security] High Priority

Issue: Wildcard permission for git commands could allow dangerous operations
Context: ''Bash(git:)'' allows any git command including force push, reset --hard, clean -fd which could damage the repository
Suggestion: Be more specific with git permissions like ''Bash(git status:
),Bash(git diff:),Bash(git log:)'' to prevent destructive operations

@@ -1,6 +1,8 @@
import { expect } from '@playwright/test'
import { Position } from '@vueuse/core'

// Test update for PR review validation
Copy link

Choose a reason for hiding this comment

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

[Quality] Low Priority

Issue: Test comment lacks specific purpose or context
Context: Generic comments like ''Test update for PR review validation'' don''t provide value and may be forgotten
Suggestion: Either remove the comment or provide specific context about what validation is being performed

"Comfy_Validation_NodeDefs": {
"name": "驗證節點定義(較慢)",
"tooltip": "建議節點開發者使用。這會在啟動時驗證所有節點定義。"
},
"Comfy_Validation_Workflows": {
Copy link

Choose a reason for hiding this comment

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

[Quality] Medium Priority

Issue: Translation key removed without verification of usage in codebase
Context: The ''Comfy_Validation_NodeDefs'' translation key was removed but may still be referenced elsewhere causing missing translation errors
Suggestion: Before removing translation keys, search codebase to ensure no references remain, or use deprecation warnings first

- Converted bash script logic to natural language instructions
- Maintained all functionality: caching, knowledge loading, deep analysis
- Preserved exact inline comment posting format with gh api commands
- Added phases for environment setup, knowledge base, validation rules
- Included comprehensive summary generation with issue tracking
@christian-byrne christian-byrne added claude-review Add to trigger a PR code review from Claude Code and removed claude-review Add to trigger a PR code review from Claude Code labels Jul 29, 2025
Copy link

claude bot commented Jul 29, 2025

Claude finished @christian-byrne's task —— View job


Comprehensive PR Review

I've successfully completed the comprehensive PR review following the instructions in .claude/commands/comprehensive-pr-review.md and posted individual inline comments for each issue found.

Tasks:

  • Read comprehensive PR review instructions from .claude/commands/comprehensive-pr-review.md
  • Get repository information and commit SHA
  • Analyze changed files for issues (architecture, security, performance, code quality)
  • Post individual inline comments using gh api commands (no summary comment)
  • Complete review process

Repository: Comfy-Org/ComfyUI_frontend
PR Number: 4453
Commit SHA: ee42add

Issues Found and Commented:

Posted 6 individual inline comments covering:

  1. Security Issue - High Priority (.github/workflows/claude-pr-review.yml:78) - Wildcard git permissions could allow dangerous operations like force push or repository damage

  2. Security Issue - Medium Priority (.github/workflows/claude-pr-review.yml:5) - Broad permissions granted that may not all be necessary, violating principle of least privilege

  3. Quality Issue - Low Priority (browser_tests/tests/interaction.spec.ts:4) - Generic test comment lacks specific purpose and context

  4. Quality Issue - Medium Priority (.claude/commands/comprehensive-pr-review.md:249) - Hardcoded repository name in example command that reduces template reusability

  5. Quality Issue - Medium Priority (src/locales/zh-TW/settings.json:332) - Translation key removed without verification of usage, could cause missing translation errors

  6. Quality Issue - Medium Priority (job-logs.txt:1) - Job logs file should not be committed to repository as it contains temporary data

Each issue has been posted as a separate inline comment on the specific line of code as instructed. No summary comment was created per the requirements.


timeout_minutes: 30
allowed_tools: "Bash(git:*),Bash(gh api:*),Bash(gh pr:*),Bash(gh repo:*),Bash(jq:*),Bash(echo:*),Read,Write,Edit,Glob,Grep,WebFetch"
Copy link

Choose a reason for hiding this comment

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

[Security] High Priority

Issue: Wildcard permission for git commands could allow dangerous operations
Context: ''Bash(git:)'' allows any git command including force push, reset --hard, clean -fd which could damage the repository
Suggestion: Be more specific with git permissions like ''Bash(git status:
),Bash(git diff:),Bash(git log:)'' to prevent destructive operations

@@ -4,6 +4,8 @@ permissions:
contents: read
pull-requests: write
Copy link

Choose a reason for hiding this comment

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

[Security] Medium Priority

Issue: Broad permissions granted to workflow that may not all be necessary
Context: The workflow has write permissions for contents, issues, statuses which increases attack surface if compromised
Suggestion: Follow principle of least privilege - only grant the minimum permissions needed (pull-requests: write and contents: read appear sufficient)

@@ -1,6 +1,8 @@
import { expect } from '@playwright/test'
import { Position } from '@vueuse/core'

// Test update for PR review validation
Copy link

Choose a reason for hiding this comment

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

[Quality] Low Priority

Issue: Test comment lacks specific purpose or context
Context: Generic comments like ''Test update for PR review validation'' don''t provide value and may be forgotten
Suggestion: Either remove the comment or provide specific context about what validation is being performed

**Suggestion**: Use parameterized queries or prepared statements"

# Then post the comment (as a single line)
gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/Comfy-Org/ComfyUI_frontend/pulls/$PR_NUMBER/comments -f body="$COMMENT_BODY" -f commit_id="abc123def456" -f path="src/db/queries.js" -F line=42 -f side="RIGHT"
Copy link

Choose a reason for hiding this comment

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

[Quality] Medium Priority

Issue: Hardcoded repository name in gh api command example
Context: The example shows a hardcoded ''Comfy-Org/ComfyUI_frontend'' path which may not work for other repositories using this template
Suggestion: Use variables like OWNER/REPO that are dynamically populated from the gh repo view command

"Comfy_Validation_NodeDefs": {
"name": "驗證節點定義(較慢)",
"tooltip": "建議節點開發者使用。這會在啟動時驗證所有節點定義。"
},
"Comfy_Validation_Workflows": {
Copy link

Choose a reason for hiding this comment

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

[Quality] Medium Priority

Issue: Translation key removed without verification of usage in codebase
Context: The ''Comfy_Validation_NodeDefs'' translation key was removed but may still be referenced elsewhere causing missing translation errors
Suggestion: Before removing translation keys, search codebase to ensure no references remain, or use deprecation warnings first

job-logs.txt Outdated
@@ -0,0 +1,3202 @@
2025-07-26T20:44:29.0264721Z Current runner version: '2.326.0'
Copy link

Choose a reason for hiding this comment

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

[Quality] Medium Priority

Issue: Job logs file should not be committed to repository
Context: The job-logs.txt file contains GitHub Actions execution logs which are temporary data and bloat the repository
Suggestion: Add job-logs.txt to .gitignore and remove this file from the commit

@christian-byrne christian-byrne merged commit 7d8c56c into main Jul 29, 2025
2 checks passed
@christian-byrne christian-byrne deleted the test-claude-review-action branch July 29, 2025 08:16
@christian-byrne christian-byrne mentioned this pull request Jul 29, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
claude-review Add to trigger a PR code review from Claude Code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant