Skip to content

Conversation

@abilpraju-aot
Copy link
Contributor

@abilpraju-aot abilpraju-aot commented Oct 6, 2025

User description

Issue Tracking

JIRA:
Issue Type: BUG/ FEATURE
https://aottech.atlassian.net/browse/FWF-5359
DEPENDENCY PR:

Changes

Screenshots (if applicable)

Notes

Checklist

  • Updated changelog
  • Added meaningful title for pull request

PR Type

Enhancement, Documentation


Description

  • Add Claude AI PR review workflow

  • Configure Anthropic Claude Sonnet 4.5

  • Enable auto review and summaries

  • Add CLAUDE reviewer guidelines


Diagram Walkthrough

flowchart LR
  GHWF["GitHub Actions Workflow (pr_review_agent.yml)"]
  Claude["Anthropic Claude Sonnet 4.5"]
  PR["Pull Requests & Comments"]
  Config["CLAUDE.md Guidelines"]

  PR -- triggers --> GHWF
  GHWF -- runs pr-agent --> Claude
  GHWF -- posts results --> PR
  GHWF -- uses --> Config
Loading

File Walkthrough

Relevant files
Enhancement
pr_review_agent.yml
Add Claude-based PR review GitHub Action                                 

.github/workflows/pr_review_agent.yml

  • Rename job to Claude AI reviewer
  • Trigger on review_requested, comments with @claude
  • Install/use qodo-ai pr-agent with Anthropic
  • Post summary comment with status/checks
+87/-12 
Documentation
CLAUDE.md
Add Claude reviewer configuration and guide                           

CLAUDE.md

  • Add detailed Claude review guidelines
  • Document project architecture and standards
  • Define security, testing, performance priorities
  • Provide language-specific best practices
+296/-0 

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

@github-actions
Copy link

github-actions bot commented Oct 6, 2025

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 Security concerns

Workflow privilege and untrusted input:
The use of pull_request_target with broad write permissions and reacting to issue_comment mentions can expose the repository to privilege escalation if any step runs code from the PR. Although the checkout pins to pull_request.head.sha, ensure no subsequent steps execute scripts from the checked-out code (e.g., npm scripts) and that the action qodo-ai/pr-agent@main does not execute repository-provided config unsafely. Consider:

  • Restricting to pull_request for forks or gating with if: github.event.pull_request.head.repo.full_name == github.repository.
  • Using permissions: least-privilege and pull_request_target with actions: read, contents: read unless writes are strictly needed.
  • Validating/comment-trigger body parsing to avoid abuse (@claude trigger).
⚡ Recommended focus areas for review

Possible Misconfiguration

The workflow sets many tool options via env with dotted keys (e.g., config.model, pr_reviewer.*). Confirm that qodo-ai/pr-agent accepts dotted environment variable names; some versions require YAML config or uppercase underscore env vars. Misrecognition would silently disable desired behavior.

# Use Anthropic Claude API
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Configure to use Claude
config.model: "anthropic/claude-sonnet-4.5"

# Auto-review configuration
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"

# PR actions to trigger on
github_action_config.pr_actions: '["opened", "reopened", "ready_for_review", "review_requested", "synchronize"]'

# Review configuration
pr_reviewer.num_code_suggestions: "6"
pr_reviewer.inline_code_comments: "true"
pr_reviewer.require_focused_review: "true"
pr_reviewer.require_score_review: "true"
pr_reviewer.require_tests_review: "true"
pr_reviewer.require_security_review: "true"
pr_reviewer.require_estimate_effort_to_review: "true"

# Code suggestions configuration
pr_code_suggestions.num_code_suggestions: "6"
pr_code_suggestions.commitable_code_suggestions: "true"
pr_code_suggestions.extra_instructions: "Follow the project's coding standards defined in CONTRIBUTING.md and CLAUDE.md"
pr_code_suggestions.rank_suggestions: "true"

# Description configuration
pr_description.publish_labels: "true"
pr_description.add_original_user_description: "true"
pr_description.generate_ai_title: "true"

# General configuration
config.verbosity_level: "1"
config.publish_output_progress: "true"
Trigger Scope

Using pull_request_target with write permissions and responding to issue_comment when mentioning @claude can execute on untrusted PRs. Validate that the checkout (ref/head.sha) and action usage cannot run arbitrary code from forks, or restrict to trusted actors/branches.

on:
  pull_request_target:
    types: [opened, reopened, ready_for_review, synchronize, review_requested]
    branches:
      - develop
      - master
      - release/**
  issue_comment:
    types: [created]

permissions:
  contents: write
  issues: write
  pull-requests: write
  statuses: write
  checks: write

jobs:
  claude_code_review:
    if: |
      (github.event_name == 'pull_request_target' && !github.event.pull_request.draft) || 
      (github.event_name == 'issue_comment' && 
       github.event.sender.type != 'Bot' && 
       contains(github.event.comment.body, '@claude'))
    runs-on: ubuntu-latest
    name: Claude AI Code Review
    timeout-minutes: 15

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.sha }}

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
Token Permissions

The workflow grants contents, issues, pull-requests, statuses, and checks write. Consider least-privilege—do all writes need to be enabled? Reducing scopes can limit blast radius if compromised.

permissions:
  contents: write
  issues: write
  pull-requests: write
  statuses: write
  checks: write

@github-actions
Copy link

github-actions bot commented Oct 6, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Security
Restrict untrusted PR execution

Using pull_request_target with broad triggers can run untrusted code with elevated
privileges. Restrict execution to trusted actors or safe events to reduce
supply-chain risk. Consider adding actor checks and limiting to comments with a
specific command keyword.

.github/workflows/pr_review_agent.yml [3-11]

 on:
   pull_request_target:
     types: [opened, reopened, ready_for_review, synchronize, review_requested]
     branches:
       - develop
       - master
       - release/**
   issue_comment:
     types: [created]
+jobs:
+  claude_code_review:
+    if: >
+      (github.event_name == 'pull_request_target'
+       && !github.event.pull_request.draft
+       && (github.event.pull_request.head.repo.full_name == github.repository))
+      || (github.event_name == 'issue_comment'
+          && github.event.sender.type != 'Bot'
+          && github.event.comment.author_association != 'NONE'
+          && contains(github.event.comment.body, '/claude review'))
Suggestion importance[1-10]: 9

__

Why: Highlights a real security risk with pull_request_target and proposes precise guards (trusted repo check, keyword command) aligned with the PR’s current triggers; high impact and accurate to the context.

High
Prevent secrets exposure on checkout

Checking out the PR head in a pull_request_target context can expose secrets to
untrusted code. Use a safe checkout strategy by fetching without persisting
credentials and avoid running arbitrary code from the PR.

.github/workflows/pr_review_agent.yml [32-37]

-- name: Checkout repository
+- name: Checkout repository (safe)
   uses: actions/checkout@v4
   with:
     fetch-depth: 0
     ref: ${{ github.event.pull_request.head.sha }}
+    persist-credentials: false
Suggestion importance[1-10]: 8

__

Why: Accurately identifies a common secret-leak risk in pull_request_target and suggests persist-credentials: false; important security improvement with minimal downside.

Medium
Reduce workflow token permissions

The workflow grants broad write permissions which increases blast radius if abused.
Follow least-privilege by setting the default to read and granting only minimal
per-scope permissions required by the action.

.github/workflows/pr_review_agent.yml [13-19]

 permissions:
-  contents: write
+  contents: read
   issues: write
   pull-requests: write
+  checks: write
   statuses: write
-  checks: write
Suggestion importance[1-10]: 7

__

Why: Correctly flags overly broad write permissions and suggests least-privilege; moderate-to-high impact though details depend on action requirements.

Medium

@arun-s-aot
Copy link
Contributor

Lets keep this on hold till we get an answer from Mouad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants