|
| 1 | +name: coderabbit-nudge |
| 2 | + |
| 3 | +# CodeRabbit rate-limits per developer; when it does, it posts a "Review limit |
| 4 | +# reached" comment and only retries on its own after the stated cooldown, or |
| 5 | +# when someone explicitly comments "@coderabbitai review". If nobody pushes a |
| 6 | +# new commit to a stalled PR in the meantime, that comment just sits there |
| 7 | +# forever. This is the backstop: on our own PRs, if the *last* CodeRabbit |
| 8 | +# comment is a rate-limit notice and we haven't already nudged it since, poke |
| 9 | +# it with "@coderabbitai review" so it wakes up on its own schedule instead of |
| 10 | +# waiting for a human to notice. |
| 11 | +# |
| 12 | +# Scope is deliberately narrow: only PRs opened by the repo owner, or PRs that |
| 13 | +# carry a "Co-Authored-By: Claude" trailer in any commit (our own automated |
| 14 | +# work) — not every open PR in the repo. |
| 15 | + |
| 16 | +on: |
| 17 | + schedule: |
| 18 | + # Hourly, not more often: CodeRabbit's own cooldown is ~an hour, so a tighter |
| 19 | + # loop would just burn its rate-limit window (or push us into usage-based |
| 20 | + # billing) without getting reviews any sooner. Offset from the hour boundary: |
| 21 | + # scheduled runs queue up right at :00 across all of GitHub, so a few minutes |
| 22 | + # off reduces the chance of a delayed run. |
| 23 | + - cron: "3 * * * *" |
| 24 | + workflow_dispatch: |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: read |
| 28 | + pull-requests: write |
| 29 | + issues: write |
| 30 | + |
| 31 | +jobs: |
| 32 | + nudge: |
| 33 | + name: wake CodeRabbit up if it rate-limited on our PRs |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7 |
| 37 | + with: |
| 38 | + script: | |
| 39 | + const RATE_LIMIT_MARK = "review limit reached"; |
| 40 | + const NUDGE_BODY = "@coderabbitai review"; |
| 41 | + const CODERABBIT_LOGIN = "coderabbitai[bot]"; |
| 42 | +
|
| 43 | + const prs = await github.paginate(github.rest.pulls.list, { |
| 44 | + owner: context.repo.owner, |
| 45 | + repo: context.repo.repo, |
| 46 | + state: "open", |
| 47 | + per_page: 100, |
| 48 | + }); |
| 49 | +
|
| 50 | + for (const pr of prs) { |
| 51 | + const isOwnerPr = pr.user?.login === context.repo.owner; |
| 52 | +
|
| 53 | + let isOurWork = isOwnerPr; |
| 54 | + if (!isOurWork) { |
| 55 | + const commits = await github.paginate( |
| 56 | + github.rest.pulls.listCommits, |
| 57 | + { |
| 58 | + owner: context.repo.owner, |
| 59 | + repo: context.repo.repo, |
| 60 | + pull_number: pr.number, |
| 61 | + per_page: 100, |
| 62 | + } |
| 63 | + ); |
| 64 | + isOurWork = commits.some((c) => |
| 65 | + /co-authored-by:\s*claude/i.test(c.commit.message) |
| 66 | + ); |
| 67 | + } |
| 68 | + if (!isOurWork) continue; |
| 69 | +
|
| 70 | + const comments = await github.paginate( |
| 71 | + github.rest.issues.listComments, |
| 72 | + { |
| 73 | + owner: context.repo.owner, |
| 74 | + repo: context.repo.repo, |
| 75 | + issue_number: pr.number, |
| 76 | + per_page: 100, |
| 77 | + } |
| 78 | + ); |
| 79 | +
|
| 80 | + const rabbitComments = comments.filter( |
| 81 | + (c) => c.user?.login === CODERABBIT_LOGIN |
| 82 | + ); |
| 83 | + if (rabbitComments.length === 0) continue; |
| 84 | +
|
| 85 | + const lastRabbit = rabbitComments[rabbitComments.length - 1]; |
| 86 | + const isRateLimited = (lastRabbit.body ?? "") |
| 87 | + .toLowerCase() |
| 88 | + .includes(RATE_LIMIT_MARK); |
| 89 | + if (!isRateLimited) { |
| 90 | + core.info(`PR #${pr.number}: last CodeRabbit comment is not a rate-limit notice, skipping.`); |
| 91 | + continue; |
| 92 | + } |
| 93 | +
|
| 94 | + const lastNudge = comments |
| 95 | + .filter( |
| 96 | + (c) => |
| 97 | + c.user?.login === "github-actions[bot]" && |
| 98 | + c.body.trim() === NUDGE_BODY |
| 99 | + ) |
| 100 | + .pop(); |
| 101 | + if (lastNudge && new Date(lastNudge.created_at) > new Date(lastRabbit.created_at)) { |
| 102 | + core.info(`PR #${pr.number}: already nudged since the last rate-limit notice, skipping.`); |
| 103 | + continue; |
| 104 | + } |
| 105 | +
|
| 106 | + await github.rest.issues.createComment({ |
| 107 | + owner: context.repo.owner, |
| 108 | + repo: context.repo.repo, |
| 109 | + issue_number: pr.number, |
| 110 | + body: NUDGE_BODY, |
| 111 | + }); |
| 112 | + core.info(`PR #${pr.number}: CodeRabbit was rate-limited, posted "${NUDGE_BODY}" to wake it up.`); |
| 113 | + } |
0 commit comments