-
Notifications
You must be signed in to change notification settings - Fork 3
149 lines (135 loc) · 5.11 KB
/
diffscope.yml
File metadata and controls
149 lines (135 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: DiffScope Review
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, review_requested]
permissions:
contents: read
pull-requests: write
concurrency:
group: diffscope-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
review:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository && !github.event.pull_request.draft
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v5
with:
node-version: 24
cache: npm
cache-dependency-path: web/package-lock.json
- uses: dtolnay/rust-toolchain@1.88.0
- uses: Swatinem/rust-cache@v2
- name: Build frontend
working-directory: web
run: |
npm ci
npm run build
- name: Build current DiffScope binary
run: cargo build --release
- name: Get PR diff
run: |
git fetch origin ${{ github.base_ref }} --depth=1
git diff origin/${{ github.base_ref }}...HEAD > pr.diff
- name: Select review provider
id: provider
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
if [ -n "${ANTHROPIC_API_KEY}" ]; then
{
echo "configured=true"
echo "model=anthropic/claude-opus-4.5"
echo "adapter=anthropic"
} >> "$GITHUB_OUTPUT"
elif [ -n "${OPENROUTER_API_KEY}" ]; then
{
echo "configured=true"
echo "model=anthropic/claude-opus-4.5"
echo "adapter=openrouter"
} >> "$GITHUB_OUTPUT"
elif [ -n "${OPENAI_API_KEY}" ]; then
{
echo "configured=true"
echo "model=gpt-4o"
echo "adapter=openai"
} >> "$GITHUB_OUTPUT"
else
echo "configured=false" >> "$GITHUB_OUTPUT"
echo "::notice::DiffScope review skipped; no ANTHROPIC_API_KEY, OPENROUTER_API_KEY, or OPENAI_API_KEY secret is configured"
fi
- name: Run DiffScope from this branch
if: steps.provider.outputs.configured == 'true'
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
./target/release/diffscope \
--model "${{ steps.provider.outputs.model }}" \
--adapter "${{ steps.provider.outputs.adapter }}" \
--output-format json \
review --diff pr.diff --output comments.json
- name: Upload review artifact
if: always() && steps.provider.outputs.configured == 'true'
uses: actions/upload-artifact@v4
with:
retention-days: 14
name: diffscope-review-${{ github.event.pull_request.number }}
path: comments.json
if-no-files-found: ignore
- name: Post comments
if: steps.provider.outputs.configured == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
if (!fs.existsSync('comments.json')) {
core.notice('DiffScope did not produce comments.json');
return;
}
const comments = JSON.parse(fs.readFileSync('comments.json', 'utf8'));
const headSha = context.payload.pull_request.head.sha;
const fallback = [];
for (const comment of comments) {
if (!comment.file_path || !comment.line_number || comment.line_number < 1) {
continue;
}
const body = [
`**${comment.severity}**: ${comment.content}`,
comment.suggestion ? `\nSuggestion: ${comment.suggestion}` : ''
].join('');
try {
await github.rest.pulls.createReviewComment({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body,
commit_id: headSha,
path: comment.file_path,
line: comment.line_number,
side: "RIGHT"
});
} catch (error) {
fallback.push(`- **${comment.severity}** ${comment.file_path}:${comment.line_number} ${comment.content}`);
}
}
if (fallback.length > 0) {
const body = [
"Some review comments could not be placed inline and are listed below:",
"",
...fallback.slice(0, 100)
].join("\n");
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
}