-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (101 loc) · 4.3 KB
/
Copy pathcoderabbit-nudge.yml
File metadata and controls
113 lines (101 loc) · 4.3 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
name: coderabbit-nudge
# CodeRabbit rate-limits per developer; when it does, it posts a "Review limit
# reached" comment and only retries on its own after the stated cooldown, or
# when someone explicitly comments "@coderabbitai review". If nobody pushes a
# new commit to a stalled PR in the meantime, that comment just sits there
# forever. This is the backstop: on our own PRs, if the *last* CodeRabbit
# comment is a rate-limit notice and we haven't already nudged it since, poke
# it with "@coderabbitai review" so it wakes up on its own schedule instead of
# waiting for a human to notice.
#
# Scope is deliberately narrow: only PRs opened by the repo owner, or PRs that
# carry a "Co-Authored-By: Claude" trailer in any commit (our own automated
# work) — not every open PR in the repo.
on:
schedule:
# Hourly, not more often: CodeRabbit's own cooldown is ~an hour, so a tighter
# loop would just burn its rate-limit window (or push us into usage-based
# billing) without getting reviews any sooner. Offset from the hour boundary:
# scheduled runs queue up right at :00 across all of GitHub, so a few minutes
# off reduces the chance of a delayed run.
- cron: "3 * * * *"
workflow_dispatch:
permissions:
contents: read
pull-requests: write
issues: write
jobs:
nudge:
name: wake CodeRabbit up if it rate-limited on our PRs
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
const RATE_LIMIT_MARK = "review limit reached";
const NUDGE_BODY = "@coderabbitai review";
const CODERABBIT_LOGIN = "coderabbitai[bot]";
const prs = await github.paginate(github.rest.pulls.list, {
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
per_page: 100,
});
for (const pr of prs) {
const isOwnerPr = pr.user?.login === context.repo.owner;
let isOurWork = isOwnerPr;
if (!isOurWork) {
const commits = await github.paginate(
github.rest.pulls.listCommits,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
per_page: 100,
}
);
isOurWork = commits.some((c) =>
/co-authored-by:\s*claude/i.test(c.commit.message)
);
}
if (!isOurWork) continue;
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
per_page: 100,
}
);
const rabbitComments = comments.filter(
(c) => c.user?.login === CODERABBIT_LOGIN
);
if (rabbitComments.length === 0) continue;
const lastRabbit = rabbitComments[rabbitComments.length - 1];
const isRateLimited = (lastRabbit.body ?? "")
.toLowerCase()
.includes(RATE_LIMIT_MARK);
if (!isRateLimited) {
core.info(`PR #${pr.number}: last CodeRabbit comment is not a rate-limit notice, skipping.`);
continue;
}
const lastNudge = comments
.filter(
(c) =>
c.user?.login === "github-actions[bot]" &&
c.body.trim() === NUDGE_BODY
)
.pop();
if (lastNudge && new Date(lastNudge.created_at) > new Date(lastRabbit.created_at)) {
core.info(`PR #${pr.number}: already nudged since the last rate-limit notice, skipping.`);
continue;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: NUDGE_BODY,
});
core.info(`PR #${pr.number}: CodeRabbit was rate-limited, posted "${NUDGE_BODY}" to wake it up.`);
}