Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions .github/workflows/claude-documentation-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,44 @@ jobs:
--allowedTools "Read,Write,Edit,Bash(vale:*),Bash(gh pr view:*),Bash(gh pr diff:*),Bash(git config:*),Bash(git add:*),Bash(git commit:*),Bash(git push:*),Bash(git status:*),Bash(git diff:*)"
--append-system-prompt "${{ steps.read-prompt.outputs.prompt }}"

- name: Record last comment ID
id: pre-claude
if: steps.pr-info.outputs.is_fork == 'false' && steps.cmd-type.outputs.is_preexisting == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LAST_ID=$(gh api repos/${{ github.repository }}/issues/${{ steps.pr-info.outputs.number }}/comments \
--jq 'if length > 0 then .[-1].id else 0 end' 2>/dev/null || echo "0")
echo "last_comment_id=$LAST_ID" >> "$GITHUB_OUTPUT"

- name: Detect preexisting issues
if: steps.pr-info.outputs.is_fork == 'false' && steps.cmd-type.outputs.is_preexisting == 'true'
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
show_full_output: false
prompt: |
Detect preexisting issues in PR ${{ steps.pr-info.outputs.number }}.

Follow these steps in order:

1. Use `gh pr diff ${{ steps.pr-info.outputs.number }}` to identify which lines are part of the PR diff.

2. Use `gh pr view ${{ steps.pr-info.outputs.number }}` to get the list of changed files, then read the full content of each changed markdown file.

3. Run all three review passes on each file per your instructions, but report ONLY issues on lines that are NOT part of the PR diff.

4. You MUST write your results ONLY to `/tmp/preexisting-issues.md` — always, even if there are no issues. Do not post a comment. Do not write anything else. Use this exact format:

## Preexisting issues
### path/to/file.md
- Line N: issue. Suggested change: '...'

Or if there are no issues:

## Preexisting issues
None.
claude_args: |
--model claude-sonnet-4-5-20250929
--allowedTools "Read,Write,Edit,Bash(gh pr view:*),Bash(gh pr diff:*)"
Expand All @@ -115,6 +146,7 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ steps.pr-info.outputs.number }}
REPO: ${{ github.repository }}
LAST_COMMENT_ID: ${{ steps.pre-claude.outputs.last_comment_id }}
run: |
python3 << 'PYTHON_EOF'
import os
Expand All @@ -123,6 +155,7 @@ jobs:

pr_number = os.environ['PR_NUMBER']
repo = os.environ['REPO']
last_comment_id = int(os.environ.get('LAST_COMMENT_ID', '0'))

FOOTER = (
"\n\n---\n\n"
Expand Down Expand Up @@ -157,8 +190,28 @@ jobs:
else:
clean_body = '## Preexisting issues\nNone.' + FOOTER

subprocess.run(
['gh', 'pr', 'comment', pr_number, '--repo', repo, '--body', clean_body],
check=True,
# Find the action's auto-posted comment (ID > last recorded, posted by a bot)
result = subprocess.run(
['gh', 'api', f'repos/{repo}/issues/{pr_number}/comments'],
capture_output=True, text=True, check=True,
)
comments = json.loads(result.stdout)
new_bot_comments = [c for c in comments
if c['id'] > last_comment_id
and c['user']['login'].endswith('[bot]')]

if new_bot_comments:
# Replace the action's auto-comment in-place with our formatted output
target_id = new_bot_comments[-1]['id']
subprocess.run(
['gh', 'api', f'repos/{repo}/issues/comments/{target_id}',
'-X', 'PATCH', '--input', '-'],
input=json.dumps({'body': clean_body}),
capture_output=True, text=True, check=True,
)
else:
subprocess.run(
['gh', 'pr', 'comment', pr_number, '--repo', repo, '--body', clean_body],
check=True,
)
PYTHON_EOF
39 changes: 31 additions & 8 deletions .github/workflows/claude-documentation-reviewer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,39 @@ jobs:
return valid

def normalize_review_body(body):
"""Convert any heading-formatted issue lines to bullet points."""
lines = []
for line in body.split('\n'):
# Convert "### Line N: ..." or "#### Line N: ..." etc. to "- Line N: ..."
"""Normalize issue formatting to single-line bullet points."""
src = body.split('\n')
result = []
i = 0
while i < len(src):
line = src[i]

# Convert heading format: ### Line N: ... → - Line N: ...
m = re.match(r'^#{1,6}\s+(Line \d+:.+)$', line)
if m:
lines.append(f'- {m.group(1)}')
else:
lines.append(line)
return '\n'.join(lines)
result.append(f'- {m.group(1)}')
i += 1
continue

# Convert bold format: **Line N: title** + sub-bullets → - Line N: single line
m = re.match(r'^\*\*(Line \d+:.*?)\*\*\s*$', line)
if m:
title = m.group(1).rstrip('.')
i += 1
parts = []
while i < len(src) and re.match(r'^\s*[-*]\s+', src[i]):
sub = re.sub(r'^\s*[-*]\s+', '', src[i])
sub = re.sub(r'^(Issue|Fix|Description|Suggested change):\s*', '', sub, flags=re.IGNORECASE)
if sub.strip():
parts.append(sub.strip().rstrip('.'))
i += 1
combined = f'- {title}. {". ".join(parts)}.' if parts else f'- {title}.'
result.append(combined)
continue

result.append(line)
i += 1
return '\n'.join(result)

# Read the review summary Claude wrote
summary_path = '/tmp/review-summary.md'
Expand Down
Loading