@@ -12,6 +12,137 @@ jobs:
1212 claude-review :
1313 runs-on : ubuntu-latest
1414
15+ permissions :
16+ contents : read
17+ pull-requests : write
18+
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v4
22+ with :
23+ fetch-depth : 2
24+
25+ - name : Fetch system prompt from private repo
26+ id : fetch-prompt
27+ env :
28+ GH_TOKEN : ${{ secrets.NETWRIX_PROMPT_REPO_TOKEN }}
29+ run : |
30+ echo "Fetching system prompt..."
31+
32+ RESPONSE=$(curl -s -w "\n%{http_code}" \
33+ -H "Authorization: token $GH_TOKEN" \
34+ -H "Accept: application/vnd.github.v3.raw" \
35+ https://api.github.com/repos/netwrix/action-agent-prompts/contents/docs-dev.md?ref=main)
36+
37+ HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
38+ CONTENT=$(echo "$RESPONSE" | head -n-1)
39+
40+ if [ "$HTTP_CODE" != "200" ]; then
41+ echo "Failed to fetch system prompt (HTTP $HTTP_CODE)"
42+ exit 1
43+ fi
44+
45+ echo "$CONTENT" > /tmp/system-prompt.md
46+ echo "System prompt fetched successfully"
47+
48+ - name : Check for Docusaurus changes
49+ id : check-files
50+ run : |
51+ CHANGED_FILES=$(git diff --name-only HEAD~1)
52+
53+ DOCUSAURUS_FILES=$(echo "$CHANGED_FILES" | grep -E "(docusaurus\.config\.js|sidebars?\.js|babel\.config\.js|package\.json|\.github/|src/)" || true)
54+
55+ if [ -z "$DOCUSAURUS_FILES" ]; then
56+ echo "No Docusaurus infrastructure files changed. Skipping review."
57+ echo "skip_review=true" >> $GITHUB_OUTPUT
58+ else
59+ echo "skip_review=false" >> $GITHUB_OUTPUT
60+ echo "### 🎯 Docusaurus Files Changed" >> $GITHUB_STEP_SUMMARY
61+ echo '```' >> $GITHUB_STEP_SUMMARY
62+ echo "$DOCUSAURUS_FILES" >> $GITHUB_STEP_SUMMARY
63+ echo '```' >> $GITHUB_STEP_SUMMARY
64+ fi
65+
66+ - name : Create review prompt
67+ if : steps.check-files.outputs.skip_review != 'true'
68+ run : |
69+ cat > /tmp/review-prompt.txt << 'REVIEW_PROMPT_EOF'
70+ Review this pull request focusing exclusively on Docusaurus infrastructure and configuration files.
71+
72+ Analyze changes to:
73+ - docusaurus.config.js (site configuration, plugins, themes)
74+ - sidebars.js (navigation structure)
75+ - package.json (dependencies, scripts)
76+ - Build configuration files
77+ - Source code in src/ directory
78+ - GitHub Actions workflows
79+
80+ For each issue found, provide:
81+ 1. Clear explanation of the problem
82+ 2. Specific code suggestion with reasoning
83+ 3. Potential impact on the documentation site
84+
85+ Ignore all .md and .mdx files - focus only on the technical infrastructure.
86+ REVIEW_PROMPT_EOF
87+
88+ - name : Read system prompt for append
89+ if : steps.check-files.outputs.skip_review != 'true'
90+ id : read-prompt
91+ run : |
92+ SYSTEM_PROMPT=$(cat /tmp/system-prompt.md)
93+ echo "system_content<<EOF" >> $GITHUB_OUTPUT
94+ echo "$SYSTEM_PROMPT" >> $GITHUB_OUTPUT
95+ echo "EOF" >> $GITHUB_OUTPUT
96+
97+ - name : Run Claude Code Review
98+ if : steps.check-files.outputs.skip_review != 'true'
99+ id : claude-review
100+ uses : anthropics/claude-code-base-action@beta
101+ with :
102+ prompt_file : /tmp/review-prompt.txt
103+ append_system_prompt : ${{ steps.read-prompt.outputs.system_content }}
104+ allowed_tools : " Read,Grep,Glob,LS"
105+ anthropic_api_key : ${{ secrets.ANTHROPIC_API_KEY }}
106+ timeout_minutes : " 15"
107+ max_turns : " 20"
108+ model : " claude-sonnet-4-20250514"
109+
110+ - name : Post review summary (bash)
111+ if : steps.claude-review.conclusion == 'success'
112+ env :
113+ EXECUTION_FILE : ${{ steps.claude-review.outputs.execution_file }}
114+ GH_TOKEN : ${{ secrets.NETWRIX_PROMPT_REPO_TOKEN }}
115+ PR_NUMBER : ${{ github.event.pull_request.number }}
116+ run : |
117+ if [ ! -f "$EXECUTION_FILE" ]; then
118+ echo "No execution file found"
119+ exit 0
120+ fi
121+
122+ # Extract the last assistant message using jq
123+ REVIEW_CONTENT=$(jq -r '.[] | select(.role == "assistant") | .content' "$EXECUTION_FILE" | tail -1)
124+
125+ if [ -z "$REVIEW_CONTENT" ]; then
126+ echo "No review content found"
127+ exit 0
128+ fi
129+
130+ # Create comment file with proper escaping
131+ cat > /tmp/comment.md << 'HEADER'
132+ ## 🤖 Claude Docusaurus Rname: Claude Code Documentation Review
133+ on :
134+ pull_request :
135+ branches :
136+ - main
137+ - dev
138+ - fix/homepage-updates
139+ paths-ignore :
140+ - ' **.md'
141+ - ' **.mdx'
142+ jobs :
143+ claude-review :
144+ runs-on : ubuntu-latest
145+
15146 permissions :
16147 contents : read
17148 pull-requests : write
107238 max_turns : " 20"
108239 model : " claude-sonnet-4-20250514"
109240
110- - name : Post review summary (bash)
241+ - name : Post review summary (bash)
111242 if : steps.claude-review.conclusion == 'success'
112243 env :
113244 EXECUTION_FILE : ${{ steps.claude-review.outputs.execution_file }}
@@ -119,11 +250,19 @@ EOF
119250 exit 0
120251 fi
121252
122- # Extract the last assistant message using jq
123- REVIEW_CONTENT=$(jq -r '.[] | select(.role == "assistant") | .content' "$EXECUTION_FILE" | tail -1)
253+ # Extract the last assistant message using jq - handle the nested structure
254+ REVIEW_CONTENT=$(jq -r '
255+ .[] |
256+ select(.type == "assistant") |
257+ .message.content[]? |
258+ select(.type == "text") |
259+ .text
260+ ' "$EXECUTION_FILE" | tail -1)
124261
125262 if [ -z "$REVIEW_CONTENT" ]; then
126263 echo "No review content found"
264+ echo "Execution file contents:"
265+ cat "$EXECUTION_FILE" | jq '.' | head -100
127266 exit 0
128267 fi
129268
@@ -144,6 +283,29 @@ HEADER
144283<sub>Automated review by Claude Code</sub>
145284FOOTER
146285
286+ # Post comment using GitHub API
287+ jq -n --arg body "$(cat /tmp/comment.md)" '{body : $body}' | \
288+ curl -X POST \
289+ -H "Authorization : token $GH_TOKEN" \
290+ -H "Accept : application/vnd.github.v3+json" \
291+ " https://api.github.com/repos/${{ github.repository }}/issues/$PR_NUMBER/comments" \
292+ -d @-
293+
294+ echo "Review posted successfully"eview
295+
296+ HEADER
297+
298+ # Append the review content
299+ echo "$REVIEW_CONTENT" >> /tmp/comment.md
300+
301+ # Add footer
302+ cat >> /tmp/comment.md << 'FOOTER'
303+
304+ ---
305+
306+ <sub>Automated review by Claude Code</sub>
307+ FOOTER
308+
147309 # Post comment using GitHub API
148310 jq -n --arg body "$(cat /tmp/comment.md)" '{body : $body}' | \
149311 curl -X POST \
0 commit comments