|
80 | 80 | runs-on: ubuntu-latest |
81 | 81 | outputs: |
82 | 82 | pr_numbers: ${{ steps.resolve.outputs.pr_numbers }} |
| 83 | + env: |
| 84 | + # Mirrors the workflow-level concurrency group so the run's queueing |
| 85 | + # identity is visible in the logs (kept in sync by the workflow tests). |
| 86 | + CONCURRENCY_GROUP: >- |
| 87 | + label-pr-review-state-${{ |
| 88 | + ((github.event_name == 'pull_request_review' && |
| 89 | + github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) && github.run_id) || |
| 90 | + github.event.pull_request.number || |
| 91 | + github.event.issue.number || |
| 92 | + github.event.inputs.pull_request_number || |
| 93 | + github.event.workflow_run.id || |
| 94 | + ((github.event_name == 'schedule' || github.event_name == 'push') && 'sweep') || |
| 95 | + github.run_id |
| 96 | + }} |
83 | 97 | steps: |
84 | 98 | - name: Resolve target PR numbers |
85 | 99 | id: resolve |
|
89 | 103 | script: | |
90 | 104 | const { owner, repo } = context.repo; |
91 | 105 |
|
| 106 | + // A queue-superseded run leaves no other trace in the logs. |
| 107 | + core.info(`Concurrency group: ${process.env.CONCURRENCY_GROUP}`); |
| 108 | +
|
92 | 109 | if (context.eventName === 'issue_comment' && |
93 | 110 | (!context.payload.issue?.pull_request || |
94 | 111 | context.payload.comment?.user?.login?.toLowerCase() !== 'coderabbitai[bot]')) { |
@@ -138,7 +155,21 @@ jobs: |
138 | 155 | const openPrs = await github.paginate(github.rest.pulls.list, { |
139 | 156 | owner, repo, state: 'open', per_page: 100, |
140 | 157 | }); |
141 | | - prNumbers = openPrs.map(pr => pr.number); |
| 158 | + // GitHub rejects matrices over 256 jobs, so the sweep pages the |
| 159 | + // sorted open-PR list: consecutive runs rotate through |
| 160 | + // fixed-size windows by run number, covering every open PR on a |
| 161 | + // bounded cadence without ever exceeding the limit. |
| 162 | + const allNumbers = openPrs.map(pr => pr.number).sort((a, b) => a - b); |
| 163 | + const sweepPageSize = 200; |
| 164 | + const pageCount = Math.max(1, Math.ceil(allNumbers.length / sweepPageSize)); |
| 165 | + const page = context.runNumber % pageCount; |
| 166 | + prNumbers = allNumbers.slice(page * sweepPageSize, (page + 1) * sweepPageSize); |
| 167 | + if (allNumbers.length > sweepPageSize) { |
| 168 | + core.info( |
| 169 | + `Sweep page ${page + 1}/${pageCount}: reconciling ` + |
| 170 | + `${prNumbers.length} of ${allNumbers.length} open PRs` |
| 171 | + ); |
| 172 | + } |
142 | 173 | } |
143 | 174 |
|
144 | 175 | core.info( |
@@ -188,13 +219,28 @@ jobs: |
188 | 219 | runs-on: ubuntu-latest |
189 | 220 | env: |
190 | 221 | PR_NUMBER: ${{ matrix.pr_number }} |
| 222 | + # Mirrors this job's concurrency group so a superseded shard's queueing |
| 223 | + # identity is visible in the logs (kept in sync by the workflow tests). |
| 224 | + CONCURRENCY_GROUP: >- |
| 225 | + label-pr-review-state-reconcile-${{ |
| 226 | + ((github.event_name == 'pull_request_review' && |
| 227 | + github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) && 'ro-') || '' |
| 228 | + }}${{ |
| 229 | + ((github.event_name == 'pull_request_review' && |
| 230 | + github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) && github.run_id) || |
| 231 | + matrix.pr_number || |
| 232 | + github.run_id |
| 233 | + }} |
191 | 234 | steps: |
192 | 235 | - name: Reconcile PR review state labels |
193 | 236 | uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 |
194 | 237 | with: |
195 | 238 | retries: 3 |
196 | 239 | script: | |
197 | 240 | const { owner, repo } = context.repo; |
| 241 | +
|
| 242 | + // A queue-superseded shard leaves no other trace in the logs. |
| 243 | + core.info(`Concurrency group: ${process.env.CONCURRENCY_GROUP}`); |
198 | 244 | const stateLabels = [ |
199 | 245 | 'awaiting-author', |
200 | 246 | 'awaiting-coderabbit', |
@@ -265,17 +311,26 @@ jobs: |
265 | 311 | } |
266 | 312 |
|
267 | 313 | if (!isReadOnlyRun) { |
| 314 | + // One paginated list keeps the per-shard API budget flat no matter |
| 315 | + // how many labels are managed; per-label getLabel calls would |
| 316 | + // multiply across a full sweep against the Actions token pool. |
| 317 | + const repoLabels = await github.paginate(github.rest.issues.listLabelsForRepo, { |
| 318 | + owner, repo, per_page: 100, |
| 319 | + }); |
| 320 | + const existingLabelNames = new Set(repoLabels.map(label => label.name)); |
268 | 321 | for (const label of labelDefinitions) { |
| 322 | + if (existingLabelNames.has(label.name)) continue; |
269 | 323 | try { |
270 | | - await github.rest.issues.getLabel({ owner, repo, name: label.name }); |
271 | | - } catch (error) { |
272 | | - if (error.status !== 404) throw error; |
273 | | - try { |
274 | | - await github.rest.issues.createLabel({ owner, repo, ...label }); |
275 | | - } catch (createError) { |
276 | | - // Concurrent shards for other PRs can win the creation race. |
277 | | - if (createError.status !== 422) throw createError; |
278 | | - } |
| 324 | + await github.rest.issues.createLabel({ owner, repo, ...label }); |
| 325 | + } catch (createError) { |
| 326 | + // Concurrent shards for other PRs can win the creation race. |
| 327 | + // Tolerate only the duplicate-label payload; any other 422 |
| 328 | + // must fail the shard. |
| 329 | + const isDuplicateRace = createError.status === 422 && |
| 330 | + (createError.response?.data?.errors ?? []).some( |
| 331 | + error => error.code === 'already_exists' && error.field === 'name' |
| 332 | + ); |
| 333 | + if (!isDuplicateRace) throw createError; |
279 | 334 | } |
280 | 335 | } |
281 | 336 | } |
@@ -834,8 +889,10 @@ jobs: |
834 | 889 | if (!blocker) continue; |
835 | 890 | const requestedAt = Date.parse(event.created_at ?? ''); |
836 | 891 | const blockedAt = Date.parse(blocker.submitted_at ?? ''); |
837 | | - // A re-request only clears blockers it follows; missing or |
838 | | - // unparsable timestamps fail closed and keep the blocker. |
| 892 | + // A re-request clears a blocker only when it was created |
| 893 | + // at the same time as or after the blocking review; |
| 894 | + // missing or unparsable timestamps fail closed and keep |
| 895 | + // the blocker. |
839 | 896 | if (!Number.isNaN(requestedAt) && !Number.isNaN(blockedAt) && requestedAt >= blockedAt) { |
840 | 897 | maintainerBlockers.delete(requested); |
841 | 898 | } |
|
0 commit comments