Skip to content

Commit f0a76a3

Browse files
committed
move pr commenting script out of yml
1 parent a497f96 commit f0a76a3

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

.github/workflows/pr-comment-test.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,22 @@ jobs:
2929
id: check_review
3030
shell: bash
3131
run: |
32-
mkdir -p ${{ github.workspace }}/foo/bar/review-inline.txt
32+
mkdir -p ${{ github.workspace }}/foo/bar
3333
echo ">> This is a clean performance optimization" > ${{ github.workspace }}/foo/bar/review-inline.txt
3434
review_file=$(find ${{ github.workspace }} -name review-inline.txt)
3535
cat $review_file
3636
echo "review_file=$review_file" >> $GITHUB_OUTPUT
3737
38-
- name: Comment on PR with review results
38+
- name: Comment on PR
3939
if: steps.check_review.outputs.review_file != ''
4040
uses: actions/github-script@v8
41+
env:
42+
REVIEW_FILE: ${{ steps.check_review.outputs.review_file }}
4143
with:
44+
github-token: ${{ steps.app-token.outputs.token }}
4245
script: |
43-
const fs = require('fs');
44-
const reviewContent = fs.readFileSync('${{ steps.check_review.outputs.review_file }}', 'utf8');
45-
const jobSummaryUrl = `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`;
46-
const commentBody = `Job summary: ${jobSummaryUrl}
47-
Review contents:
48-
\`\`\`
49-
${reviewContent}
50-
\`\`\``;
51-
github.rest.issues.createComment({
52-
issue_number: context.issue.number,
53-
owner: context.repo.owner,
54-
repo: context.repo.repo,
55-
body: commentBody
56-
});
46+
const commentScript = require('./ci/claude/post-pr-comment.js');
47+
await commentScript({github, context});
5748
5849
- name: Fail job if review file exists
5950
if: steps.check_review.outputs.review_file != ''

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)