Repository navigation
165 lines (149 loc) · 6.27 KB
/
Copy pathbugbot-review.yml
File metadata and controls
165 lines (149 loc) · 6.27 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
# Require Cursor Bugbot on maintainer PRs only. Fork and external contributor PRs
# often never receive the Bugbot GitHub App check, so this job passes automatically
# when the author is not @unjica. Use this as a required check instead of
# requiring "Cursor Bugbot" directly in branch protection.
#
# --- TEMPORARILY DISABLED (revert to re-enable) ---
# Set BUGBOT_REVIEW_ENABLED to "true" below and restore the gate script from git
# history (see commit that introduced this pause). Also re-enable the Cursor
# Bugbot GitHub App for this repo in the Cursor dashboard if it was paused:
# https://www.cursor.com/dashboard/bugbot
# Docs: CONTRIBUTING.md § AI code review (Bugbot), docs/RELEASE.md develop gates.
name: Bugbot review
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches: [main, develop]
check_run:
types: [completed]
branches: [main, develop]
permissions:
pull-requests: read
checks: read
concurrency:
group: bugbot-review-${{ github.event.pull_request.number || github.event.check_run.check_suite.pull_requests[0].number }}
cancel-in-progress: true
env:
# Flip to "true" to restore the Cursor Bugbot gate for @unjica PRs.
BUGBOT_REVIEW_ENABLED: "false"
jobs:
bugbot-review:
runs-on: ubuntu-latest
if: |
(github.event_name == 'pull_request' && github.event.pull_request.draft == false) ||
(github.event_name == 'check_run' && github.event.check_run.name == 'Cursor Bugbot')
steps:
- name: Gate maintainer PRs on Cursor Bugbot
uses: actions/github-script@v7
env:
MAINTAINER: unjica
BUGBOT_REVIEW_ENABLED: ${{ env.BUGBOT_REVIEW_ENABLED }}
with:
# GitHub occasionally returns HTML 5xx ("Unicorn") instead of JSON; retry those.
retries: 5
script: |
if (process.env.BUGBOT_REVIEW_ENABLED !== "true") {
core.info(
"bugbot-review is temporarily disabled (BUGBOT_REVIEW_ENABLED=false). Passing as no-op success."
);
return;
}
const maintainer = process.env.MAINTAINER.toLowerCase();
const { owner, repo } = context.repo;
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
function isTransientGithubError(error) {
const status = error?.status ?? error?.response?.status;
if (typeof status === "number" && status >= 500) return true;
const message = String(error?.message ?? error ?? "");
return (
message.includes("<!DOCTYPE html>") ||
message.includes("Unicorn") ||
message.includes("503") ||
message.includes("502") ||
message.includes("invalid character '<'")
);
}
async function withTransientRetry(label, fn, attempts = 5) {
let lastError;
for (let attempt = 1; attempt <= attempts; attempt += 1) {
try {
return await fn();
} catch (error) {
lastError = error;
if (!isTransientGithubError(error) || attempt === attempts) {
throw error;
}
const delayMs = Math.min(30_000, 2_000 * attempt);
core.warning(
`${label} failed (attempt ${attempt}/${attempts}): ${error.message?.slice?.(0, 120) ?? error}. Retrying in ${delayMs}ms…`
);
await wait(delayMs);
}
}
throw lastError;
}
let pull_number;
if (context.payload.pull_request) {
pull_number = context.payload.pull_request.number;
} else {
const prs = context.payload.check_run.check_suite?.pull_requests ?? [];
if (prs.length === 0) {
core.info("Bugbot completed outside a PR — nothing to gate.");
return;
}
pull_number = prs[0].number;
}
const { data: pr } = await withTransientRetry("pulls.get", () =>
github.rest.pulls.get({ owner, repo, pull_number })
);
if (pr.draft) {
core.info("Draft PR — skipping gate.");
return;
}
const author = pr.user.login.toLowerCase();
if (author !== maintainer) {
core.info(
`Author @${pr.user.login} is not @${process.env.MAINTAINER} — Cursor Bugbot not required.`
);
return;
}
let bugbot;
for (let attempt = 0; attempt < 30; attempt += 1) {
try {
const { data } = await withTransientRetry(
"checks.listForRef",
() =>
github.rest.checks.listForRef({
owner,
repo,
ref: pr.head.sha,
}),
3
);
bugbot = data.check_runs.find((run) => run.name === "Cursor Bugbot");
if (bugbot?.status === "completed") break;
core.info(`Cursor Bugbot still ${bugbot?.status ?? "missing"} — waiting…`);
} catch (error) {
if (!isTransientGithubError(error)) throw error;
core.warning(
`checks.listForRef still unavailable after retries — waiting before next poll…`
);
}
await wait(10_000);
}
if (!bugbot) {
core.setFailed(
"Maintainer PR requires Cursor Bugbot. Comment `bugbot run` on the PR or run `/review-bugbot` locally before push."
);
return;
}
if (bugbot.status !== "completed") {
core.setFailed(`Cursor Bugbot is still ${bugbot.status}.`);
return;
}
const allowed = new Set(["success", "neutral", "skipped"]);
if (!allowed.has(bugbot.conclusion)) {
core.setFailed(`Cursor Bugbot concluded: ${bugbot.conclusion}.`);
return;
}
core.info(`Cursor Bugbot: ${bugbot.conclusion}`);