name: DiffScope Review
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get PR diff
id: diff
run: |
git diff origin/${{ github.base_ref }}...HEAD > pr.diff
- name: Run DiffScope
uses: docker://ghcr.io/haasonsaas/diffscope:latest
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
with:
args: review --diff pr.diff --output-format json --output comments.json
- name: Post comments
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const comments = JSON.parse(fs.readFileSync('comments.json', 'utf8'));
for (const comment of comments) {
await github.rest.pulls.createReviewComment({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body: `**${comment.severity}**: ${comment.content}`,
commit_id: context.sha,
path: comment.file_path,
line: comment.line_number
});
}