Conversation
- Extract PROGRAMMATIC_EVENTS as a module-level constant - Destructure context variables at top of main() - Simplify workflowId extraction using workflowRefMatch?.[1] - Use ?? instead of || for env var defaults - Simplify permission data access with nested destructuring - Use ?? for runsPerEvent accumulation - Add 2 new tests: runs without updated_at and multi-page pagination Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Refactors the check_rate_limit.cjs GitHub Script to use more modern JavaScript patterns and adds tests to cover pagination and counting behavior when updated_at is missing.
Changes:
- Refactored
check_rate_limit.cjs(module-level constants, destructuring, optional chaining,??usage, simplified nested access). - Added two new unit tests for missing
updated_athandling and multi-page pagination.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/check_rate_limit.cjs | Refactors rate-limit checking logic for readability and reuse (constants, destructuring, nullish coalescing). |
| actions/setup/js/check_rate_limit.test.cjs | Adds tests for runs missing updated_at and for fetching additional pages when page 1 is full. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
| const maxRuns = parseInt(process.env.GH_AW_RATE_LIMIT_MAX ?? "5", 10); | ||
| const windowMinutes = parseInt(process.env.GH_AW_RATE_LIMIT_WINDOW ?? "60", 10); | ||
| const eventsList = process.env.GH_AW_RATE_LIMIT_EVENTS ?? ""; | ||
| // Default: admin, maintain, and write roles are exempt from rate limiting | ||
| const ignoredRolesList = process.env.GH_AW_RATE_LIMIT_IGNORED_ROLES || "admin,maintain,write"; | ||
| const ignoredRolesList = process.env.GH_AW_RATE_LIMIT_IGNORED_ROLES ?? "admin,maintain,write"; |
There was a problem hiding this comment.
Switching these env var defaults from || to ?? changes behavior when the variable is set to an empty string. For numeric vars (e.g., GH_AW_RATE_LIMIT_MAX/_WINDOW), parseInt("") becomes NaN, which can break the rate-limit comparisons; for GH_AW_RATE_LIMIT_IGNORED_ROLES, an empty string disables the default exemptions. Consider treating empty/whitespace-only values as unset (e.g., normalize with .trim() and fall back), and/or validate parseInt results and default when Number.isNaN.
🧪 Test Quality Sentinel ReportTest Quality Score: 90/100✅ Excellent test quality
Test Classification Details
Flagged Tests — Requires ReviewNo tests flagged for behavioral issues. One minor note: i️ Test inflation ratio (not a failure)File: Test Detail✅
|
|
@copilot review comments |
…s in check_rate_limit.cjs Agent-Logs-Url: https://github.com/github/gh-aw/sessions/8c57323f-841b-4fd1-8dde-bc3da1f2ca4c Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed in 1625510. For each env var, Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…_limit.cjs Agent-Logs-Url: https://github.com/github/gh-aw/sessions/8c57323f-841b-4fd1-8dde-bc3da1f2ca4c Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Summary
Cleaned
check_rate_limit.cjs(github-script context) with modern JavaScript patterns and 2 additional tests.Changes to
check_rate_limit.cjsPROGRAMMATIC_EVENTSas a module-level constant — removes the inline array from theelsebranch, making it reusable and easy to scanconst actor = context.actorassignments with a single destructuring at the top ofmain()workflowRefMatchbefore theifblock and usedworkflowRefMatch?.[1]optional chaining instead of nestedif (match && match[1])??instead of||forprocess.env.*defaults (more precise: only falls back onnull/undefined, not empty string)permResponse+permissionData.permissioninto a single nested destructuring??forrunsPerEventaccumulation —(runsPerEvent[runEvent] ?? 0) + 1is more semantically correct than|| 0Changes to
check_rate_limit.test.cjsAdded 2 new tests (29 → 31 tests):
should count runs without updated_at— verifies that the duration check is skipped whenupdated_atis absent (theif (run.created_at && run.updated_at)guard), and the run is still countedshould fetch additional pages when first page is full— verifies multi-page pagination by returning 100 runs from another actor on page 1 (none qualify) and 2 runs from the test user on page 2Context
core,github,contextglobals)Validation ✅
npm run format:cjs✓npm run lint:cjs✓npm run typecheck✓npm run test:js -- --no-file-parallelism✓ (31/31 passed)