fix: use GraphQL viewer query for authenticated user detection#194
Merged
Conversation
REST endpoints users.getAuthenticated and apps.getAuthenticated both
fail for GitHub App installation tokens. The GraphQL viewer query
works for both PATs and App installation tokens, returning the
correct login (e.g., {app-slug}[bot] for Apps).
Bump to v2.9.2.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes authenticated user/app detection used for stale PR author matching by replacing REST-based fallbacks with a single GraphQL viewer query, intended to work with both PATs and GitHub App installation tokens.
Changes:
- Switch auth detection from
users.getAuthenticated()/apps.getAuthenticated()REST calls tooctokit.graphql('{ viewer { login } }') - Update test Octokit mock shape to include
graphql - Bump version to
2.9.2and refresh coverage badge
Show a summary per file
| File | Description |
|---|---|
src/index.js |
Replaces REST auth detection logic with a GraphQL viewer query for stale PR matching. |
__tests__/index.test.js |
Extends the Octokit mock to include a graphql function. |
package.json |
Bumps package version to 2.9.2. |
package-lock.json |
Synchronizes lockfile version fields with 2.9.2. |
badges/coverage.svg |
Updates the coverage badge output. |
Copilot's findings
- Files reviewed: 3/5 changed files
- Comments generated: 2
📦 Draft Release CreatedA draft release v2.9.2 has been created for this PR. Next Steps
|
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
PR #193 tried to fix GitHub App token support by falling back from
users.getAuthenticated()toapps.getAuthenticated(). But:users.getAuthenticated()→ 403 for App installation tokens ("Resource not accessible by integration")apps.getAuthenticated()→ needs a JWT, not an installation token ("A JSON web token could not be decoded")Result: stale PR check always skipped for GitHub App auth.
Failed run
Fix
Replace both REST calls with a single GraphQL
{ viewer { login } }query. This works for both PATs and App installation tokens:Simpler code (5 lines instead of 14), one API call instead of two fallbacks.
Changes
octokit.graphql('{ viewer { login } }')users.getAuthenticatedandapps.getAuthenticatedusagegraphqlmock to test suite400 tests pass.