Skip to content

Commit 63f6e77

Browse files
authored
Merge pull request #469 from netwrix/dev
post Vale issues as inline PR review comments
2 parents f1f31a4 + 12d4964 commit 63f6e77

1 file changed

Lines changed: 52 additions & 19 deletions

File tree

.github/workflows/claude-doc-pr.yml

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,25 @@ jobs:
4848
echo "count=$(echo "$CHANGED_MD_FILES" | wc -l | tr -d ' ')" >> "$GITHUB_OUTPUT"
4949
fi
5050
51-
- name: Delete previous bot review comments
51+
- name: Delete previous bot comments
5252
if: steps.changed-files.outputs.count > 0
5353
env:
5454
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5555
run: |
5656
PR_NUMBER=${{ github.event.pull_request.number }}
57+
# Delete previous review comments
5758
COMMENT_IDS=$(gh api repos/${{ github.repository }}/issues/${PR_NUMBER}/comments \
5859
--jq '[.[] | select(.user.login == "github-actions[bot]" and (.body | contains("Documentation PR Review"))) | .id] | .[]' 2>/dev/null || true)
5960
for ID in $COMMENT_IDS; do
6061
gh api repos/${{ github.repository }}/issues/comments/${ID} -X DELETE 2>/dev/null || true
6162
done
63+
# Dismiss previous Vale reviews so they don't pile up
64+
REVIEW_IDS=$(gh api repos/${{ github.repository }}/pulls/${PR_NUMBER}/reviews \
65+
--jq '[.[] | select(.user.login == "github-actions[bot]" and .state == "COMMENTED") | .id] | .[]' 2>/dev/null || true)
66+
for ID in $REVIEW_IDS; do
67+
gh api repos/${{ github.repository }}/pulls/${PR_NUMBER}/reviews/${ID}/dismissals \
68+
-f message="Superseded by new review" -f event="DISMISS" 2>/dev/null || true
69+
done
6270
6371
- name: Install Vale
6472
if: steps.changed-files.outputs.count > 0
@@ -67,26 +75,53 @@ jobs:
6775
curl -sfL "https://github.com/errata-ai/vale/releases/download/${VERSION}/vale_${VERSION#v}_Linux_64-bit.tar.gz" \
6876
| sudo tar -xz -C /usr/local/bin vale
6977
70-
- name: Run Vale on changed files
78+
- name: Run Vale and post inline comments
7179
id: vale
7280
if: steps.changed-files.outputs.count > 0
81+
env:
82+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7383
run: |
7484
IFS=',' read -ra FILES <<< "${{ steps.changed-files.outputs.files }}"
75-
VALE_OUTPUT=""
85+
VALE_COUNT=0
86+
COMMENTS_JSON="[]"
87+
7688
for FILE in "${FILES[@]}"; do
7789
if [ -f "$FILE" ]; then
7890
RESULT=$(vale --output=line "$FILE" 2>&1 || true)
7991
if [ -n "$RESULT" ]; then
80-
VALE_OUTPUT+="**${FILE}**"$'\n\n'"${RESULT}"$'\n\n'
81-
else
82-
VALE_OUTPUT+="**${FILE}** — No issues found."$'\n\n'
92+
while IFS= read -r LINE; do
93+
# Format: file:line:col:rule:message
94+
LINE_NUM=$(echo "$LINE" | cut -d: -f2)
95+
RULE=$(echo "$LINE" | cut -d: -f4)
96+
MESSAGE=$(echo "$LINE" | cut -d: -f5-)
97+
if [ -n "$LINE_NUM" ] && [ -n "$MESSAGE" ]; then
98+
BODY="**Vale** (\`${RULE}\`): ${MESSAGE}"
99+
COMMENTS_JSON=$(echo "$COMMENTS_JSON" | jq \
100+
--arg path "$FILE" \
101+
--argjson line "$LINE_NUM" \
102+
--arg body "$BODY" \
103+
'. += [{"path": $path, "line": $line, "body": $body}]')
104+
VALE_COUNT=$((VALE_COUNT + 1))
105+
fi
106+
done <<< "$RESULT"
83107
fi
84108
fi
85109
done
86-
# Save to file for Claude to read
87-
echo "$VALE_OUTPUT" > /tmp/vale-results.txt
88-
echo "Vale results saved to /tmp/vale-results.txt"
89-
cat /tmp/vale-results.txt
110+
111+
echo "vale_count=$VALE_COUNT" >> "$GITHUB_OUTPUT"
112+
113+
if [ "$VALE_COUNT" -gt 0 ]; then
114+
echo "Posting $VALE_COUNT Vale inline comments"
115+
# Post as a PR review with inline comments
116+
jq -n \
117+
--arg body "**Vale found ${VALE_COUNT} issue(s).** See inline comments below." \
118+
--argjson comments "$COMMENTS_JSON" \
119+
'{"body": $body, "event": "COMMENT", "comments": $comments}' \
120+
| gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews \
121+
--input - 2>&1
122+
else
123+
echo "No Vale issues found"
124+
fi
90125
91126
- name: Get PR diff
92127
id: diff
@@ -98,7 +133,7 @@ jobs:
98133
echo "Diff saved to /tmp/pr-diff.txt"
99134
wc -l /tmp/pr-diff.txt
100135
101-
- name: Run doc-pr review
136+
- name: Run editorial review
102137
if: steps.changed-files.outputs.count > 0
103138
uses: anthropics/claude-code-action@v1
104139
env:
@@ -109,22 +144,22 @@ jobs:
109144
show_full_output: true
110145
prompt: |
111146
You are a documentation reviewer. Your ONLY job is to:
112-
1. Read pre-computed Vale results and PR diff
147+
1. Read the PR diff and changed files
113148
2. Do a brief editorial review
114149
3. Post a formatted review comment to the PR
115150
116151
CONTEXT:
117152
- Repository: ${{ github.repository }}
118153
- PR number: ${{ github.event.pull_request.number }}
119154
- Changed files: ${{ steps.changed-files.outputs.files }}
120-
- Vale results are at: /tmp/vale-results.txt
155+
- Vale issues: ${{ steps.vale.outputs.vale_count }} (already posted as inline comments)
121156
- PR diff is at: /tmp/pr-diff.txt
122157
123158
INSTRUCTIONS:
124159
125-
Step 1: Read /tmp/vale-results.txt to get the Vale linting results.
160+
Step 1: Read /tmp/pr-diff.txt to see what changed. Then read each changed file to understand context.
126161
127-
Step 2: Read /tmp/pr-diff.txt to see what changed. Then read each changed file to understand context. Do a brief editorial review focusing on:
162+
Step 2: Do a brief editorial review of ONLY added/modified lines, focusing on:
128163
- Voice: passive voice, first person, impersonal phrases
129164
- Clarity: hard-to-parse sentences, ambiguous references
130165
- Surface: wordiness, redundancy
@@ -133,14 +168,12 @@ jobs:
133168
134169
## Documentation PR Review
135170
136-
### Vale Linting
137-
(list Vale issues as bullet points: **Line N**: Message. Suggested fix: "...")
138-
139171
### Editorial Review
140172
(list editorial issues as bullet points: **Category** — Line N: description. Suggested fix: "...")
173+
(if no issues found, write "No editorial issues found.")
141174
142175
### Summary
143-
N Vale issues, N editorial suggestions across N files.
176+
N Vale issues (see inline comments), N editorial suggestions across N files.
144177
145178
---
146179
**What to do next:**

0 commit comments

Comments
 (0)