Skip to content

Commit ff03b67

Browse files
authored
ai-code-review.yml: post comments on PRs (#395)
If Claude produced a review file it means it found a potential regression/bug. In that case, post a comment on PR with the inline review and fail the CI job.
1 parent ce8d072 commit ff03b67

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

.github/workflows/ai-code-review.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: AI Code Review
22

33
permissions:
44
contents: read
5-
pull-requests: read
6-
issues: read
75
id-token: write
6+
issues: write
7+
pull-requests: write
88

99
on:
1010
pull_request:
@@ -38,7 +38,6 @@ jobs:
3838
ai-review:
3939
needs: get-commits
4040
runs-on: 'ubuntu-latest'
41-
continue-on-error: true
4241
strategy:
4342
matrix:
4443
commit: ${{ fromJson(needs.get-commits.outputs.commits) }}
@@ -94,21 +93,32 @@ jobs:
9493
Using the prompt `review/review-core.md` and the prompt directory `review`
9594
do a code review of the top commit in the Linux repository.
9695
97-
- name: Dump review-inline.txt if exists
96+
# If Claude produced review-inline.txt then it found something
97+
# Post a comment on PR and fail the job
98+
- name: Check review-inline.txt
99+
id: check_review
98100
shell: bash
99101
run: |
100102
review_file=$(find ${{ github.workspace }} -name review-inline.txt)
101-
cat $review_file
102103
if [ -s "$review_file" ]; then
103-
cp -f $review_file ${{ github.workspace }}/review-inline.txt || true
104-
echo "### Inline review" >> $GITHUB_STEP_SUMMARY
105-
echo "```" >> $GITHUB_STEP_SUMMARY
106-
cat $review_file >> $GITHUB_STEP_SUMMARY
107-
echo "```" >> $GITHUB_STEP_SUMMARY
104+
cat $review_file || true
105+
echo "review_file=$review_file" >> $GITHUB_OUTPUT
108106
fi
109107
110-
- uses: actions/upload-artifact@v4
108+
- name: Comment on PR
109+
if: steps.check_review.outputs.review_file != ''
110+
uses: actions/github-script@v8
111+
env:
112+
REVIEW_FILE: ${{ steps.check_review.outputs.review_file }}
111113
with:
112-
name: ai-review-output
113-
if-no-files-found: ignore
114-
path: ${{ github.workspace }}/review-inline.txt
114+
github-token: ${{ steps.app-token.outputs.token }}
115+
script: |
116+
const commentScript = require('./ci/claude/post-pr-comment.js');
117+
await commentScript({github, context});
118+
119+
- name: Fail CI job if review file exists
120+
if: steps.check_review.outputs.review_file != ''
121+
run: |
122+
echo "Review file found - failing the CI job"
123+
exit 42
124+

ci/claude/post-pr-comment.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = async ({github, context}) => {
2+
const fs = require('fs');
3+
4+
const jobSummaryUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
5+
const reviewContent = fs.readFileSync(process.env.REVIEW_FILE, 'utf8');
6+
const commentBody = `AI review job summary: ${jobSummaryUrl}
7+
8+
Inline review:
9+
\`\`\`
10+
${reviewContent}
11+
\`\`\``;
12+
13+
await github.rest.issues.createComment({
14+
issue_number: context.issue.number,
15+
owner: context.repo.owner,
16+
repo: context.repo.repo,
17+
body: commentBody
18+
});
19+
};
20+

0 commit comments

Comments
 (0)