Avoid Administration-gated branchProtectionRule in GraphQL fetch. - #56
Conversation
The app token lacks Administration, so that field returns FORBIDDEN and octokit.graphql aborts despite usable Ref.rules data. Use rules plus refUpdateRule, and read GraphQL via POST so partial errors are ignored. Co-authored-by: Cursor <cursoragent@cursor.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Walkthrough
ChangesProtected staging branch detection
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant fetchProtectedBranchNames
participant GitHubGraphQL
participant GitHubREST
fetchProtectedBranchNames->>GitHubGraphQL: List paginated staging/* refs
GitHubGraphQL-->>fetchProtectedBranchNames: Return ref names or errors
fetchProtectedBranchNames->>GitHubREST: Check each branch with repos.getBranch
GitHubREST-->>fetchProtectedBranchNames: Return protected flag
Possibly related PRs
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
Comment |
List staging/* names with GraphQL, then use GET /branches/{branch}.protected
so both classic branch protection and rulesets work without Administration.
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/github.js (1)
42-59: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winValidate GraphQL pagination fields before iterating.
RefConnection.nodesis nullable, so a null value causes thefor...ofloop to throw aTypeError. BecausePageInfo.endCursoris nullable,hasNextPage: truewith a null or unchanged cursor can repeat the same request indefinitely. Reject incomplete pages and require an advancing cursor before continuing.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/github.js` around lines 42 - 59, Validate repository.refs.nodes and repository.refs.pageInfo before iterating in the staging-ref pagination flow. Require nodes to be iterable, and when hasNextPage is true, require a non-null endCursor that differs from the current cursor; otherwise throw the existing GraphQL listing error instead of continuing. Preserve normal branch collection and termination when hasNextPage is false.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/github.js`:
- Around line 9-14: Update fetchProtectedBranchNames around the repos.getBranch
call to catch errors for each stagingBranchName. Skip only a confirmed
stale-branch 404 caused by the branch being deleted, while propagating
authentication, access-related, and all other errors; continue evaluating the
remaining branches after the stale branch is skipped.
---
Outside diff comments:
In `@apps/github.js`:
- Around line 42-59: Validate repository.refs.nodes and repository.refs.pageInfo
before iterating in the staging-ref pagination flow. Require nodes to be
iterable, and when hasNextPage is true, require a non-null endCursor that
differs from the current cursor; otherwise throw the existing GraphQL listing
error instead of continuing. Preserve normal branch collection and termination
when hasNextPage is false.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 3f790127-edba-43bd-b948-f641d075b529
⛔ Files ignored due to path filters (1)
dist/index.jsis excluded by!**/dist/**
📒 Files selected for processing (1)
apps/github.js
The app token lacks Administration, so that field returns FORBIDDEN and octokit.graphql aborts despite usable Ref.rules data. Use rules plus refUpdateRule, and read GraphQL via POST so partial errors are ignored.
Updates
fetchProtectedBranchNamesto list paginatedstaging/*refs throughPOST /graphql, then verify protection through REST. Removes the Administration-gatedbranchProtectionRulequery and adds explicit handling for missing repository or ref data and GraphQL errors.