|
| 1 | +# ============================================================ |
| 2 | +# Java PR Review — powered by claude-java-plugins |
| 3 | +# ============================================================ |
| 4 | +# Copy this file to .github/workflows/java-pr-review.yml |
| 5 | +# in your Java project. |
| 6 | +# |
| 7 | +# Requirements: |
| 8 | +# 1. Add ANTHROPIC_API_KEY to your repo secrets: |
| 9 | +# Settings → Secrets and variables → Actions → New secret |
| 10 | +# 2. Install claude-java-plugins: |
| 11 | +# /plugin marketplace add ducpm2303/claude-java-plugins |
| 12 | +# /plugin install java-core@java-plugins |
| 13 | +# /plugin install java-spring@java-plugins # if Spring Boot project |
| 14 | +# /plugin install java-quality@java-plugins # for security + perf + test review |
| 15 | +# |
| 16 | +# What it does: |
| 17 | +# - Reviews every PR that touches Java/build files |
| 18 | +# - Runs security scan (OWASP Top 10) |
| 19 | +# - Runs performance scan (N+1, threading, memory) |
| 20 | +# - Checks test quality and coverage gaps |
| 21 | +# - Posts a consolidated review comment on the PR |
| 22 | +# ============================================================ |
| 23 | + |
| 24 | +name: Java PR Review |
| 25 | + |
| 26 | +on: |
| 27 | + pull_request: |
| 28 | + types: [opened, synchronize] |
| 29 | + paths: |
| 30 | + - '**/*.java' |
| 31 | + - '**/pom.xml' |
| 32 | + - '**/build.gradle' |
| 33 | + - '**/build.gradle.kts' |
| 34 | + |
| 35 | +# Cancel in-progress runs on the same PR to save API costs |
| 36 | +concurrency: |
| 37 | + group: java-pr-review-${{ github.event.pull_request.number }} |
| 38 | + cancel-in-progress: true |
| 39 | + |
| 40 | +jobs: |
| 41 | + java-review: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + permissions: |
| 44 | + contents: read |
| 45 | + pull-requests: write |
| 46 | + |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + fetch-depth: 0 # full history for better diff context |
| 51 | + |
| 52 | + - uses: anthropics/claude-code-action@v1 |
| 53 | + with: |
| 54 | + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 55 | + # Optional: pin to a specific model for cost control |
| 56 | + # claude_args: --model claude-sonnet-4-6 |
| 57 | + prompt: | |
| 58 | + You are reviewing a Java pull request. Analyse only the changed files |
| 59 | + in this PR (do not review unchanged files). |
| 60 | +
|
| 61 | + Run these three checks in sequence. Complete all three before posting. |
| 62 | +
|
| 63 | + --- |
| 64 | +
|
| 65 | + ## Check 1 — Code Review (java-core) |
| 66 | +
|
| 67 | + For each changed .java file: |
| 68 | + - Logic errors, null pointer risks, or incorrect control flow |
| 69 | + - Naming violations: classes should be PascalCase, methods camelCase, |
| 70 | + constants SCREAMING_SNAKE_CASE |
| 71 | + - Version-inappropriate patterns (flag Java 8 idioms if project uses Java 17+) |
| 72 | + - Resource leaks (unclosed streams, connections) |
| 73 | + - Missing or incorrect exception handling |
| 74 | +
|
| 75 | + --- |
| 76 | +
|
| 77 | + ## Check 2 — Security Scan (java-quality) |
| 78 | +
|
| 79 | + - Hardcoded credentials, API keys, or tokens in source code |
| 80 | + - SQL string concatenation (SQL injection risk) |
| 81 | + - Missing @Valid on @RequestBody parameters |
| 82 | + - Logging of passwords, tokens, or PII |
| 83 | + - Weak cryptography (MD5, SHA-1, DES) |
| 84 | + - @CrossOrigin(origins = "*") in non-test code |
| 85 | +
|
| 86 | + --- |
| 87 | +
|
| 88 | + ## Check 3 — Performance Scan (java-quality) |
| 89 | +
|
| 90 | + - @OneToMany or @ManyToMany without FetchType.LAZY |
| 91 | + - Repository method calls inside loops (N+1 pattern) |
| 92 | + - findAll() without Pageable on large entity tables |
| 93 | + - String concatenation inside loops (use StringBuilder) |
| 94 | + - Creating DateTimeFormatter, Pattern, or ObjectMapper inside methods |
| 95 | +
|
| 96 | + --- |
| 97 | +
|
| 98 | + ## Output Format |
| 99 | +
|
| 100 | + Post a single consolidated comment structured as: |
| 101 | +
|
| 102 | + ### Java PR Review |
| 103 | +
|
| 104 | + **Summary:** [1-2 sentences about the overall change] |
| 105 | +
|
| 106 | + **Security** — [CLEAN / X issue(s) found] |
| 107 | + **Performance** — [CLEAN / X issue(s) found] |
| 108 | + **Code Quality** — [CLEAN / X issue(s) found] |
| 109 | +
|
| 110 | + --- |
| 111 | +
|
| 112 | + #### Issues (sorted by severity) |
| 113 | +
|
| 114 | + | Severity | File | Finding | |
| 115 | + |----------|------|---------| |
| 116 | + | 🔴 CRITICAL | `path/File.java:42` | SQL injection risk: string concat in query | |
| 117 | + | 🟠 HIGH | `path/File.java:18` | N+1: repository call inside loop | |
| 118 | + | 🟡 MEDIUM | `path/File.java:55` | Missing @Valid on request body | |
| 119 | + | 🔵 NOTE | `path/File.java:10` | Consider using var (Java 10+) | |
| 120 | +
|
| 121 | + #### Positive Notes |
| 122 | + [Highlight anything done well — good patterns, good test coverage, correct use of version features] |
| 123 | +
|
| 124 | + --- |
| 125 | +
|
| 126 | + Rules: |
| 127 | + - Only report actual findings, not hypothetical ones |
| 128 | + - Do NOT comment on formatting, whitespace, or import order (use a linter for that) |
| 129 | + - Do NOT repeat findings — one entry per issue |
| 130 | + - If all three checks are clean, post a short "LGTM" comment with a brief summary |
0 commit comments