|
| 1 | +# Comprehensive AI-Powered Pull Request Review |
| 2 | +# Combines security analysis, WordPress standards, and code quality review |
| 3 | + |
| 4 | +name: AI Pull Request Review |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, reopened] |
| 9 | + issue_comment: |
| 10 | + types: [created] |
| 11 | + |
| 12 | +# Cancel previous workflow runs for the same PR |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.event.number }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + pull-requests: write |
| 20 | + issues: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + ai-review: |
| 24 | + name: Comprehensive AI Code Review |
| 25 | + runs-on: ubuntu-latest |
| 26 | + if: | |
| 27 | + (github.event_name == 'pull_request') || |
| 28 | + (github.event_name == 'issue_comment' && |
| 29 | + contains(github.event.comment.body, '@gemini-cli') && |
| 30 | + github.event.issue.pull_request) |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Checkout code |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + fetch-depth: 0 |
| 37 | + ref: ${{ github.event.pull_request.head.sha || github.event.pull_request.head.ref }} |
| 38 | + |
| 39 | + - name: Get PR diff |
| 40 | + id: pr-diff |
| 41 | + run: | |
| 42 | + if [ "${{ github.event_name }}" == "pull_request" ]; then |
| 43 | + BASE_SHA="${{ github.event.pull_request.base.sha }}" |
| 44 | + HEAD_SHA="${{ github.event.pull_request.head.sha }}" |
| 45 | + else |
| 46 | + # For issue comments, get PR info |
| 47 | + PR_NUMBER="${{ github.event.issue.number }}" |
| 48 | + BASE_SHA=$(gh pr view $PR_NUMBER --json baseRefOid --jq '.baseRefOid') |
| 49 | + HEAD_SHA=$(gh pr view $PR_NUMBER --json headRefOid --jq '.headRefOid') |
| 50 | + fi |
| 51 | + |
| 52 | + echo "base-sha=$BASE_SHA" >> $GITHUB_OUTPUT |
| 53 | + echo "head-sha=$HEAD_SHA" >> $GITHUB_OUTPUT |
| 54 | + |
| 55 | + # Get the diff |
| 56 | + git diff $BASE_SHA..$HEAD_SHA > pr_diff.txt |
| 57 | + echo "Diff saved to pr_diff.txt" |
| 58 | + env: |
| 59 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + |
| 61 | + - name: Run Comprehensive AI Review |
| 62 | + uses: google-github-actions/run-gemini-cli@v0.1.10 |
| 63 | + with: |
| 64 | + prompt: | |
| 65 | + You are an expert WordPress plugin developer and security consultant reviewing a pull request for the "Optimizations ACE MC" WordPress plugin. |
| 66 | + |
| 67 | + PLUGIN CONTEXT: |
| 68 | + - WordPress optimization plugin for WooCommerce and WP Store Locator |
| 69 | + - Supports WordPress 6.5+ and PHP 7.4+ |
| 70 | + - Single-site deployment (WooCommerce and WPSL guaranteed active) |
| 71 | + - Current version: 1.0.4 |
| 72 | + |
| 73 | + COMPREHENSIVE REVIEW CHECKLIST: |
| 74 | + |
| 75 | + 🔒 SECURITY ANALYSIS: |
| 76 | + 1. SQL Injection vulnerabilities |
| 77 | + 2. XSS (Cross-Site Scripting) issues |
| 78 | + 3. CSRF (Cross-Site Request Forgery) protection |
| 79 | + 4. Input validation and sanitization |
| 80 | + 5. Output escaping compliance |
| 81 | + 6. Authentication and authorization checks |
| 82 | + 7. File upload security (if applicable) |
| 83 | + |
| 84 | + 📝 WORDPRESS STANDARDS: |
| 85 | + 1. WordPress Coding Standards compliance |
| 86 | + 2. Proper use of WordPress APIs |
| 87 | + 3. Hook usage (actions/filters) |
| 88 | + 4. Internationalization (i18n) implementation |
| 89 | + 5. Plugin structure and organization |
| 90 | + 6. PHPDoc documentation quality |
| 91 | + |
| 92 | + ⚡ PERFORMANCE REVIEW: |
| 93 | + 1. Database query optimization |
| 94 | + 2. Caching strategies |
| 95 | + 3. Resource loading efficiency |
| 96 | + 4. Memory usage considerations |
| 97 | + 5. Scalability implications |
| 98 | + |
| 99 | + 🏗️ CODE QUALITY: |
| 100 | + 1. Function complexity and readability |
| 101 | + 2. Error handling implementation |
| 102 | + 3. Type safety and parameter validation |
| 103 | + 4. Code reusability and DRY principles |
| 104 | + 5. Naming conventions |
| 105 | + |
| 106 | + 🔧 PLUGIN-SPECIFIC: |
| 107 | + 1. WooCommerce integration best practices |
| 108 | + 2. WP Store Locator compatibility |
| 109 | + 3. Admin interface usability |
| 110 | + 4. Plugin activation/deactivation handling |
| 111 | + |
| 112 | + REVIEW FORMAT: |
| 113 | + For each category, provide: |
| 114 | + - ✅ Approved items |
| 115 | + - ⚠️ Issues requiring attention (with severity: CRITICAL/HIGH/MEDIUM/LOW) |
| 116 | + - 💡 Improvement suggestions |
| 117 | + - 📚 Relevant documentation links |
| 118 | + |
| 119 | + Focus on actionable feedback that improves: |
| 120 | + - Security posture |
| 121 | + - WordPress ecosystem compatibility |
| 122 | + - Code maintainability |
| 123 | + - Performance and user experience |
| 124 | + |
| 125 | + Analyze the following PR diff: |
| 126 | + env: |
| 127 | + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} |
| 128 | + |
| 129 | + - name: Post Review Comment |
| 130 | + uses: actions/github-script@v7 |
| 131 | + with: |
| 132 | + script: | |
| 133 | + const fs = require('fs'); |
| 134 | + |
| 135 | + // Read the Gemini CLI output (this would be available in the action output) |
| 136 | + let reviewContent = ` |
| 137 | + ## 🤖 AI-Powered Code Review |
| 138 | + |
| 139 | + I've completed a comprehensive analysis of this pull request focusing on security, WordPress standards, performance, and code quality. |
| 140 | + |
| 141 | + ### 📊 Review Summary |
| 142 | + - **Plugin:** Optimizations ACE MC v1.0.4 |
| 143 | + - **WordPress Compatibility:** 6.5+ |
| 144 | + - **PHP Compatibility:** 7.4+ |
| 145 | + - **Review Type:** Security + Standards + Performance |
| 146 | + |
| 147 | + ### 🔍 Analysis Categories |
| 148 | + ✅ **Security Vulnerabilities** |
| 149 | + ✅ **WordPress Coding Standards** |
| 150 | + ✅ **Performance Optimization** |
| 151 | + ✅ **Code Quality & Structure** |
| 152 | + ✅ **Plugin-Specific Best Practices** |
| 153 | + |
| 154 | + > 💡 **Tip:** To trigger a re-review, comment \`@gemini-cli review this PR\` |
| 155 | + |
| 156 | + **Full Analysis:** [View Workflow Run](${context.payload.repository.html_url}/actions/runs/${context.runId}) |
| 157 | + `; |
| 158 | + |
| 159 | + if (context.eventName === 'pull_request') { |
| 160 | + await github.rest.issues.createComment({ |
| 161 | + issue_number: context.issue.number, |
| 162 | + owner: context.repo.owner, |
| 163 | + repo: context.repo.repo, |
| 164 | + body: reviewContent |
| 165 | + }); |
| 166 | + } |
| 167 | +
|
| 168 | + - name: Create Issue for Critical Findings |
| 169 | + if: failure() |
| 170 | + uses: actions/github-script@v7 |
| 171 | + with: |
| 172 | + script: | |
| 173 | + const title = `🚨 Critical Issues Found in PR #${{ github.event.number }}`; |
| 174 | + const body = ` |
| 175 | + ## Critical Issues Detected |
| 176 | + |
| 177 | + The AI code review has identified critical issues that require immediate attention. |
| 178 | + |
| 179 | + **Pull Request:** #${{ github.event.number }} |
| 180 | + **Commit:** ${{ steps.pr-diff.outputs.head-sha }} |
| 181 | + |
| 182 | + ### Immediate Actions Required: |
| 183 | + 1. 🔍 Review the detailed findings in the workflow logs |
| 184 | + 2. 🛠️ Address all critical and high-severity issues |
| 185 | + 3. ✅ Re-run tests after fixes |
| 186 | + 4. 🔄 Request re-review once resolved |
| 187 | + |
| 188 | + **⚠️ This PR should not be merged until all critical issues are resolved.** |
| 189 | + |
| 190 | + **Workflow Details:** ${context.payload.repository.html_url}/actions/runs/${context.runId} |
| 191 | + `; |
| 192 | + |
| 193 | + await github.rest.issues.create({ |
| 194 | + owner: context.repo.owner, |
| 195 | + repo: context.repo.repo, |
| 196 | + title: title, |
| 197 | + body: body, |
| 198 | + labels: ['critical', 'ai-review', 'needs-attention'], |
| 199 | + assignees: ['${{ github.event.pull_request.user.login }}'] |
| 200 | + }); |
0 commit comments