-
Notifications
You must be signed in to change notification settings - Fork 1
323 lines (289 loc) · 14.4 KB
/
Copy pathjules_bugbot.yml
File metadata and controls
323 lines (289 loc) · 14.4 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
name: 🐛 Watchdog PR Review (Jules)
on:
pull_request:
types: [opened, synchronize, reopened]
issue_comment:
types: [created]
permissions:
checks: write
pull-requests: write
contents: read
jobs:
watchdog-review:
runs-on: ubuntu-latest
# Run on PR events (not from Jules/Watchdog) OR on "bugbot go" comment on a PR
if: >-
(github.event_name == 'pull_request' &&
github.event.pull_request.user.login != 'jules[bot]' &&
github.event.pull_request.user.login != 'jules-google[bot]' &&
github.event.pull_request.user.login != 'google-labs-jules[bot]' &&
!contains(github.event.pull_request.title, 'Watchdog') &&
!contains(github.event.pull_request.title, 'Sentinel') &&
!contains(github.event.pull_request.title, 'Palette') &&
!contains(github.event.pull_request.title, 'Bolt'))
||
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(github.event.comment.body, 'bugbot go'))
steps:
- name: Resolve PR Context
id: pr_context
uses: actions/github-script@v7
with:
script: |
let prNumber, headRef, baseRef, headSha, prTitle;
if (context.eventName === 'pull_request') {
prNumber = context.payload.pull_request.number;
headRef = context.payload.pull_request.head.ref;
baseRef = context.payload.pull_request.base.ref;
headSha = context.payload.pull_request.head.sha;
prTitle = context.payload.pull_request.title;
} else {
// issue_comment — fetch PR details
prNumber = context.payload.issue.number;
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
headRef = pr.head.ref;
baseRef = pr.base.ref;
headSha = pr.head.sha;
prTitle = pr.title;
// React with 👀 to acknowledge the command
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'eyes'
});
}
core.setOutput('pr_number', prNumber);
core.setOutput('head_ref', headRef);
core.setOutput('base_ref', baseRef);
core.setOutput('head_sha', headSha);
core.setOutput('pr_title', prTitle);
- name: Create Pending Check
id: create_check
uses: actions/github-script@v7
with:
script: |
const check = await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Watchdog / Jules Bugbot',
head_sha: '${{ steps.pr_context.outputs.head_sha }}',
status: 'in_progress',
output: {
title: 'Watchdog is reviewing your code...',
summary: '🐛 Analyzing PR diff for bugs. This may take a few minutes.'
}
});
core.setOutput('check_id', check.data.id);
- name: Create Jules Session
id: create_session
env:
JULES_API_KEY: ${{ secrets.JULES_API_KEY }}
run: |
SESSION_RESPONSE=$(curl -s -w "\n%{http_code}" \
'https://jules.googleapis.com/v1alpha/sessions' \
-X POST \
-H "Content-Type: application/json" \
-H "X-Goog-Api-Key: ${JULES_API_KEY}" \
-d @- <<PAYLOAD
{
"title": "Watchdog: PR #${{ steps.pr_context.outputs.pr_number }}",
"prompt": "You are Watchdog — a precision PR bug reviewer and fixer. Read .jules/bugbot_prompt.md for your full instructions.\n\nReview Pull Request #${{ steps.pr_context.outputs.pr_number }} on repo ${{ github.repository }}.\n- Head branch: ${{ steps.pr_context.outputs.head_ref }}\n- Base branch: ${{ steps.pr_context.outputs.base_ref }}\n- PR Title: ${{ steps.pr_context.outputs.pr_title }}\n\nFollow ALL instructions in .jules/bugbot_prompt.md exactly.",
"sourceContext": {
"source": "sources/github/AEmotionStudio/ComfyUI-FFMPEGA",
"githubRepoContext": {
"startingBranch": "${{ steps.pr_context.outputs.head_ref }}"
}
},
"automationMode": "AUTO_CREATE_PR"
}
PAYLOAD
)
HTTP_CODE=$(echo "$SESSION_RESPONSE" | tail -1)
BODY=$(echo "$SESSION_RESPONSE" | sed '$d')
echo "HTTP Status: $HTTP_CODE"
echo "Response: $BODY"
if [ "$HTTP_CODE" -ge 400 ]; then
echo "::error::Jules API returned HTTP $HTTP_CODE"
echo "session_id=" >> "$GITHUB_OUTPUT"
exit 1
fi
SESSION_ID=$(echo "$BODY" | jq -r '.id // empty')
echo "session_id=$SESSION_ID" >> "$GITHUB_OUTPUT"
echo "Jules session created: $SESSION_ID"
- name: Poll Jules Session Status
id: poll_status
if: steps.create_session.outputs.session_id != ''
env:
JULES_API_KEY: ${{ secrets.JULES_API_KEY }}
run: |
SESSION_ID="${{ steps.create_session.outputs.session_id }}"
MAX_POLLS=60 # 60 polls × 30s = 30 min max
POLL_INTERVAL=30 # seconds
echo "Polling session $SESSION_ID (max ${MAX_POLLS} polls, ${POLL_INTERVAL}s interval)"
for i in $(seq 1 $MAX_POLLS); do
sleep $POLL_INTERVAL
STATUS_RESPONSE=$(curl -s \
"https://jules.googleapis.com/v1alpha/sessions/${SESSION_ID}" \
-H "X-Goog-Api-Key: ${JULES_API_KEY}")
SESSION_STATUS=$(echo "$STATUS_RESPONSE" | jq -r '.status // .state // empty')
echo "Poll $i/$MAX_POLLS: status=$SESSION_STATUS"
# Check for terminal states
case "$SESSION_STATUS" in
COMPLETED|completed|Completed)
echo "final_status=completed" >> "$GITHUB_OUTPUT"
echo "Session completed successfully"
exit 0
;;
FAILED|failed|Failed|ERROR|error|Error)
echo "final_status=failed" >> "$GITHUB_OUTPUT"
echo "Session failed"
exit 0
;;
CANCELLED|cancelled|Cancelled)
echo "final_status=cancelled" >> "$GITHUB_OUTPUT"
echo "Session was cancelled"
exit 0
;;
esac
done
echo "final_status=timeout" >> "$GITHUB_OUTPUT"
echo "::warning::Jules session timed out after $((MAX_POLLS * POLL_INTERVAL))s"
- name: Check for Jules Output
id: check_review
if: steps.create_session.outputs.session_id != ''
uses: actions/github-script@v7
with:
script: |
const prNumber = ${{ steps.pr_context.outputs.pr_number }};
// Check if Jules left any review comments on this PR
const reviews = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
const julesLogins = ['google-labs-jules[bot]', 'jules[bot]', 'google-labs-jules'];
const julesReview = reviews.data.find(r => julesLogins.includes(r.user.login));
const hasRequestedChanges = reviews.data.some(r =>
julesLogins.includes(r.user.login) && r.state === 'CHANGES_REQUESTED'
);
const hasApproval = reviews.data.some(r =>
julesLogins.includes(r.user.login) && r.state === 'APPROVED'
);
// Check if Jules created a fix PR referencing this PR
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 20
});
const fixPr = prs.find(pr =>
pr.title.toLowerCase().includes('watchdog') &&
(pr.body || '').includes(`${prNumber}`)
);
core.setOutput('has_review', julesReview ? 'true' : 'false');
core.setOutput('has_issues', hasRequestedChanges ? 'true' : 'false');
core.setOutput('has_approval', hasApproval ? 'true' : 'false');
core.setOutput('has_fix_pr', fixPr ? 'true' : 'false');
core.setOutput('fix_pr_url', fixPr ? fixPr.html_url : '');
- name: Update Check — Completed
if: always() && steps.create_check.outputs.check_id
uses: actions/github-script@v7
with:
script: |
const checkId = ${{ steps.create_check.outputs.check_id }};
const sessionId = '${{ steps.create_session.outputs.session_id }}';
const finalStatus = '${{ steps.poll_status.outputs.final_status }}';
const hasIssues = '${{ steps.check_review.outputs.has_issues }}';
const hasReview = '${{ steps.check_review.outputs.has_review }}';
const hasApproval = '${{ steps.check_review.outputs.has_approval }}';
const hasFixPr = '${{ steps.check_review.outputs.has_fix_pr }}';
const fixPrUrl = '${{ steps.check_review.outputs.fix_pr_url }}';
const sessionUrl = `https://jules.google.com/session/${sessionId}`;
let conclusion, title, summary;
if (!sessionId) {
conclusion = 'failure';
title = 'Watchdog failed to start';
summary = '❌ Could not create Jules session. Check the JULES_API_KEY secret.';
} else if (finalStatus === 'timeout') {
conclusion = 'neutral';
title = 'Watchdog timed out';
summary = `⏱️ Jules session timed out. [View session](${sessionUrl})`;
} else if (finalStatus === 'failed' || finalStatus === 'cancelled') {
conclusion = 'neutral';
title = `Watchdog session ${finalStatus}`;
summary = `⚠️ Jules session ${finalStatus}. [View session](${sessionUrl})`;
} else if (hasFixPr === 'true') {
conclusion = 'neutral';
title = 'Watchdog created a fix PR';
summary = `🐛 Bugs found and a fix PR was created: ${fixPrUrl}\n\n[View Jules session](${sessionUrl})`;
} else if (hasIssues === 'true') {
conclusion = 'neutral';
title = 'Watchdog found potential issues';
summary = `🐛 Bugs were found. Check the review comments.\n\n[View Jules session](${sessionUrl})`;
} else if (hasApproval === 'true') {
conclusion = 'success';
title = 'Watchdog review passed';
summary = `✅ Watchdog reviewed and approved the code.\n\n[View Jules session](${sessionUrl})`;
} else if (hasReview === 'true') {
conclusion = 'success';
title = 'Watchdog review passed';
summary = `✅ Watchdog reviewed the code.\n\n[View Jules session](${sessionUrl})`;
} else {
// Jules completed but produced no visible output
conclusion = 'neutral';
title = 'Watchdog completed — no output';
summary = `⚠️ Watchdog finished but did not post a review or create a fix PR. Check the session for details.\n\n[View Jules session](${sessionUrl})`;
}
await github.rest.checks.update({
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: checkId,
status: 'completed',
conclusion: conclusion,
output: {
title: title,
summary: summary
}
});
- name: Post Summary Comment
if: always() && steps.create_session.outputs.session_id != ''
uses: actions/github-script@v7
with:
script: |
const prNumber = ${{ steps.pr_context.outputs.pr_number }};
const sessionId = '${{ steps.create_session.outputs.session_id }}';
const finalStatus = '${{ steps.poll_status.outputs.final_status }}';
const hasFixPr = '${{ steps.check_review.outputs.has_fix_pr }}';
const fixPrUrl = '${{ steps.check_review.outputs.fix_pr_url }}';
const hasIssues = '${{ steps.check_review.outputs.has_issues }}';
const hasApproval = '${{ steps.check_review.outputs.has_approval }}';
const hasReview = '${{ steps.check_review.outputs.has_review }}';
const sessionUrl = `https://jules.google.com/session/${sessionId}`;
let body;
if (!sessionId) {
return; // Nothing to report
} else if (finalStatus === 'timeout') {
body = `### ⏱️ Watchdog timed out\n\nJules session did not complete within 30 minutes.\n\n[View session](${sessionUrl})`;
} else if (finalStatus === 'failed' || finalStatus === 'cancelled') {
body = `### ⚠️ Watchdog session ${finalStatus}\n\nJules session ${finalStatus} unexpectedly.\n\n[View session](${sessionUrl})`;
} else if (hasFixPr === 'true') {
body = `### 🐛 Watchdog found a bug and created a fix\n\n**Fix PR:** ${fixPrUrl}\n\nPlease review the fix PR for details on what was found and how it was resolved.\n\n[View Jules session](${sessionUrl})`;
} else if (hasIssues === 'true') {
body = `### 🐛 Watchdog found potential issues\n\nCheck the review comments above for details.\n\n[View Jules session](${sessionUrl})`;
} else if (hasApproval === 'true' || hasReview === 'true') {
body = `### ✅ Watchdog review passed\n\nNo bugs detected in the changed code.\n\n[View Jules session](${sessionUrl})`;
} else {
body = `### ⚠️ Watchdog completed — no output\n\nWatchdog finished analyzing but did not post a review or create a fix PR. This may mean no bugs were found, or that Jules encountered an issue.\n\n[View Jules session](${sessionUrl})`;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});