|
| 1 | +name: Billy Code Review |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + paths: |
| 7 | + - '**.js' |
| 8 | + - '**.ts' |
| 9 | + - '**.jsx' |
| 10 | + - '**.tsx' |
| 11 | + - '**.py' |
| 12 | + - '**.java' |
| 13 | + - '**.go' |
| 14 | + - '**.rs' |
| 15 | + - '**.rb' |
| 16 | + - '**.php' |
| 17 | + - '**.cpp' |
| 18 | + - '**.c' |
| 19 | + - '**.cs' |
| 20 | + |
| 21 | +jobs: |
| 22 | + billy-review: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + pull-requests: write |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout code |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Get changed files |
| 35 | + id: changed-files |
| 36 | + uses: tj-actions/changed-files@v41 |
| 37 | + with: |
| 38 | + files: | |
| 39 | + **.js |
| 40 | + **.ts |
| 41 | + **.jsx |
| 42 | + **.tsx |
| 43 | + **.py |
| 44 | + **.java |
| 45 | + **.go |
| 46 | + **.rs |
| 47 | + **.rb |
| 48 | + **.php |
| 49 | + **.cpp |
| 50 | + **.c |
| 51 | + **.cs |
| 52 | +
|
| 53 | + - name: Review changed files with Billy |
| 54 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 55 | + env: |
| 56 | + BILLY_API_URL: ${{ secrets.BILLY_API_URL || 'https://billy.chitty.cc' }} |
| 57 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + run: | |
| 59 | + # Initialize review results |
| 60 | + REVIEW_COMMENT="## 💩 Billy's Code Review\n\n" |
| 61 | + REVIEW_COMMENT+="> Calling BS on your BS code since 2024\n\n" |
| 62 | + |
| 63 | + # Track if we found any issues |
| 64 | + FOUND_ISSUES=false |
| 65 | + |
| 66 | + # Review each changed file |
| 67 | + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do |
| 68 | + echo "Reviewing: $file" |
| 69 | + |
| 70 | + # Detect language from extension |
| 71 | + ext="${file##*.}" |
| 72 | + case "$ext" in |
| 73 | + js) lang="javascript" ;; |
| 74 | + ts) lang="typescript" ;; |
| 75 | + jsx) lang="javascript" ;; |
| 76 | + tsx) lang="typescript" ;; |
| 77 | + py) lang="python" ;; |
| 78 | + java) lang="java" ;; |
| 79 | + go) lang="go" ;; |
| 80 | + rs) lang="rust" ;; |
| 81 | + rb) lang="ruby" ;; |
| 82 | + php) lang="php" ;; |
| 83 | + cpp|cc|cxx) lang="cpp" ;; |
| 84 | + c) lang="c" ;; |
| 85 | + cs) lang="csharp" ;; |
| 86 | + *) lang="unknown" ;; |
| 87 | + esac |
| 88 | + |
| 89 | + # Read file content |
| 90 | + if [ ! -f "$file" ]; then |
| 91 | + echo "File not found: $file" |
| 92 | + continue |
| 93 | + fi |
| 94 | + |
| 95 | + # Read file content and create JSON payload with proper escaping |
| 96 | + payload=$(jq -n \ |
| 97 | + --rawfile code "$file" \ |
| 98 | + --arg language "$lang" \ |
| 99 | + --arg context "File: $file (GitHub PR Review)" \ |
| 100 | + '{code: $code, language: $language, context: $context}') |
| 101 | + |
| 102 | + # Call Billy's API |
| 103 | + response=$(curl -s -X POST "$BILLY_API_URL/review" \ |
| 104 | + -H "Content-Type: application/json" \ |
| 105 | + -d "$payload") |
| 106 | + |
| 107 | + # Check if we got a valid response |
| 108 | + if [ $? -eq 0 ] && [ -n "$response" ]; then |
| 109 | + review=$(echo "$response" | jq -r '.review // empty') |
| 110 | + |
| 111 | + if [ -n "$review" ]; then |
| 112 | + FOUND_ISSUES=true |
| 113 | + REVIEW_COMMENT+="### 📄 \`$file\`\n\n" |
| 114 | + REVIEW_COMMENT+="\`\`\`\n$review\n\`\`\`\n\n" |
| 115 | + REVIEW_COMMENT+="---\n\n" |
| 116 | + fi |
| 117 | + else |
| 118 | + echo "Failed to get review for $file" |
| 119 | + fi |
| 120 | + done |
| 121 | + |
| 122 | + # Post review comment if we found issues |
| 123 | + if [ "$FOUND_ISSUES" = true ]; then |
| 124 | + REVIEW_COMMENT+="\n\n**Billy says:** 💩 BS detected and called out. You're welcome.\n\n" |
| 125 | + REVIEW_COMMENT+="_Powered by [Billy Bullshit](https://billy.chitty.cc) - Your brutally honest code reviewer_" |
| 126 | + |
| 127 | + # Post comment to PR |
| 128 | + curl -X POST \ |
| 129 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 130 | + -H "Accept: application/vnd.github.v3+json" \ |
| 131 | + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ |
| 132 | + -d "$(jq -n --arg body "$REVIEW_COMMENT" '{body: $body}')" |
| 133 | + |
| 134 | + echo "✅ Review posted to PR" |
| 135 | + else |
| 136 | + echo "ℹ️ No issues found or no reviewable files changed" |
| 137 | + fi |
| 138 | +
|
| 139 | + - name: Review summary |
| 140 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 141 | + run: | |
| 142 | + echo "## Billy Review Complete" |
| 143 | + echo "Reviewed ${{ steps.changed-files.outputs.all_changed_files_count }} file(s)" |
| 144 | + echo "Check PR comments for Billy's brutally honest feedback" |
0 commit comments