|
4 | 4 | pull_request: |
5 | 5 | types: [opened, synchronize, reopened, ready_for_review] |
6 | 6 |
|
7 | | -permissions: |
8 | | - contents: read |
9 | | - pull-requests: write |
10 | | - |
11 | 7 | jobs: |
12 | | - validation: |
13 | | - name: Validation |
14 | | - runs-on: ubuntu-24.04 |
15 | | - permissions: |
16 | | - contents: read |
17 | | - outputs: |
18 | | - should_review: ${{ steps.validate.outputs.should_review }} |
19 | | - |
20 | | - steps: |
21 | | - - name: Check PR requirements |
22 | | - id: check-pr |
23 | | - run: | |
24 | | - if [ "${{ github.event.pull_request.draft }}" == "true" ]; then |
25 | | - echo "⚠️ Validation: PR is a draft - skipping review" |
26 | | - echo "pr_valid=false" >> $GITHUB_OUTPUT |
27 | | - else |
28 | | - echo "✅ Validation: PR is ready for review" |
29 | | - echo "pr_valid=true" >> $GITHUB_OUTPUT |
30 | | - fi |
31 | | -
|
32 | | - - name: Check for Azure credentials |
33 | | - id: check-azure-secret |
34 | | - env: |
35 | | - _AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
36 | | - _AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} |
37 | | - _AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} |
38 | | - run: | |
39 | | - if [ -n "$_AZURE_SUBSCRIPTION_ID" ] && [ -n "$_AZURE_TENANT_ID" ] && [ -n "$_AZURE_CLIENT_ID" ]; then |
40 | | - echo "credentials_valid=true" >> $GITHUB_OUTPUT |
41 | | - echo "✅ Validation: Azure credentials available" |
42 | | - else |
43 | | - echo "credentials_valid=false" >> $GITHUB_OUTPUT |
44 | | - echo "⚠️ Validation: Azure credentials not available" |
45 | | - echo "This is expected for external contributors or forks" |
46 | | - fi |
47 | | -
|
48 | | - - name: Check if prompt file exists |
49 | | - id: check-prompt |
50 | | - env: |
51 | | - GH_TOKEN: ${{ github.token }} |
52 | | - run: | |
53 | | - # Use GitHub API to check file existence WITHOUT checkout |
54 | | - FILE_PATH=".claude/prompts/review-code.md" |
55 | | - REPO="${{ github.repository }}" |
56 | | - REF="${{ github.event.pull_request.head.sha }}" |
57 | | -
|
58 | | - # Check if file exists via API |
59 | | - if gh api "repos/$REPO/contents/$FILE_PATH?ref=$REF" --silent 2>/dev/null; then |
60 | | - echo "prompt_exists=true" >> $GITHUB_OUTPUT |
61 | | - echo "✅ Found $FILE_PATH in $REPO" |
62 | | - else |
63 | | - echo "prompt_exists=false" >> $GITHUB_OUTPUT |
64 | | - echo "⚠️ Validation: No $FILE_PATH found - skipping Claude review" |
65 | | - fi |
66 | | -
|
67 | | - - name: Set validation result |
68 | | - id: validate |
69 | | - run: | |
70 | | - if [ "${{ steps.check-pr.outputs.pr_valid }}" == "true" ] && \ |
71 | | - [ "${{ steps.check-azure-secret.outputs.credentials_valid }}" == "true" ] && \ |
72 | | - [ "${{ steps.check-prompt.outputs.prompt_exists }}" == "true" ]; then |
73 | | - echo "should_review=true" >> $GITHUB_OUTPUT |
74 | | - echo "✅ Validation passed - code review will proceed" |
75 | | - else |
76 | | - echo "should_review=false" >> $GITHUB_OUTPUT |
77 | | - echo "⚠️ Validation failed - code review will be skipped" |
78 | | - fi |
79 | | -
|
80 | 8 | review: |
81 | 9 | name: Review |
82 | | - runs-on: ubuntu-24.04 |
83 | | - needs: validation |
84 | | - if: needs.validation.outputs.should_review == 'true' |
| 10 | + uses: bitwarden/gh-actions/.github/workflows/_review-code.yml@main |
| 11 | + secrets: |
| 12 | + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 13 | + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} |
| 14 | + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} |
85 | 15 | permissions: |
86 | 16 | contents: read |
87 | | - id-token: write |
88 | 17 | pull-requests: write |
89 | | - |
90 | | - steps: |
91 | | - - name: Check out repo |
92 | | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
93 | | - with: |
94 | | - fetch-depth: 0 |
95 | | - persist-credentials: false |
96 | | - |
97 | | - - name: Log in to Azure |
98 | | - uses: bitwarden/gh-actions/azure-login@main |
99 | | - with: |
100 | | - subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
101 | | - tenant_id: ${{ secrets.AZURE_TENANT_ID }} |
102 | | - client_id: ${{ secrets.AZURE_CLIENT_ID }} |
103 | | - |
104 | | - - name: Get Azure Key Vault secrets |
105 | | - id: get-kv-secrets |
106 | | - uses: bitwarden/gh-actions/get-keyvault-secrets@main |
107 | | - with: |
108 | | - keyvault: gh-org-bitwarden |
109 | | - secrets: "ANTHROPIC-API-KEY" |
110 | | - |
111 | | - - name: Log out from Azure |
112 | | - uses: bitwarden/gh-actions/azure-logout@main |
113 | | - |
114 | | - - name: Build review prompt |
115 | | - id: build-prompt |
116 | | - env: |
117 | | - PR_REPO: ${{ github.repository }} |
118 | | - PR_NUMBER: ${{ github.event.pull_request.number }} |
119 | | - PR_TITLE: ${{ github.event.pull_request.title }} |
120 | | - PR_BODY: ${{ github.event.pull_request.body }} |
121 | | - PR_AUTHOR: ${{ github.event.pull_request.user.login }} |
122 | | - PR_COMMIT: ${{ github.event.pull_request.head.sha }} |
123 | | - run: | |
124 | | - PROMPT_FILE=".claude/prompts/review-code.md" |
125 | | -
|
126 | | - # Build the full prompt with GitHub context + repo's prompt |
127 | | - { |
128 | | - printf "REPO: %s\n" "$PR_REPO" |
129 | | - printf "PR NUMBER: %s\n" "$PR_NUMBER" |
130 | | - printf "TITLE: %s\n" "$PR_TITLE" |
131 | | - printf "BODY: %s\n" "$PR_BODY" |
132 | | - printf "AUTHOR: %s\n" "$PR_AUTHOR" |
133 | | - printf "COMMIT: %s\n" "$PR_COMMIT" |
134 | | - printf "\n" |
135 | | - printf "Note: The PR branch is already checked out in the current working directory.\n" |
136 | | - printf "\n---\n\n" |
137 | | - cat "$PROMPT_FILE" |
138 | | - } > /tmp/review-prompt.md |
139 | | -
|
140 | | - # Output the prompt |
141 | | - { |
142 | | - echo 'FINAL_PROMPT<<EOF' |
143 | | - cat /tmp/review-prompt.md |
144 | | - echo 'EOF' |
145 | | - } >> "$GITHUB_OUTPUT" |
146 | | -
|
147 | | - - name: Review with Claude Code |
148 | | - uses: anthropics/claude-code-action@e8bad572273ce919ba15fec95aef0ce974464753 # v1.0.13 |
149 | | - with: |
150 | | - anthropic_api_key: ${{ steps.get-kv-secrets.outputs.ANTHROPIC-API-KEY }} |
151 | | - track_progress: true |
152 | | - use_sticky_comment: true |
153 | | - prompt: ${{ steps.build-prompt.outputs.FINAL_PROMPT }} |
154 | | - claude_args: | |
155 | | - --allowedTools "mcp__github_comment__update_claude_comment,mcp__github_inline_comment__create_inline_comment,Bash(gh pr diff:*),Bash(gh pr view:*)" |
| 18 | + id-token: write |
0 commit comments