Skip to content

fix: use GraphQL viewer query for authenticated user detection#194

Merged
joshjohanning merged 1 commit into
mainfrom
fix/app-auth-graphql-viewer
Apr 25, 2026
Merged

fix: use GraphQL viewer query for authenticated user detection#194
joshjohanning merged 1 commit into
mainfrom
fix/app-auth-graphql-viewer

Conversation

@joshjohanning

Copy link
Copy Markdown
Owner

Problem

PR #193 tried to fix GitHub App token support by falling back from users.getAuthenticated() to apps.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:

PAT → { viewer: { login: "joshjohanning" } }
App → { viewer: { login: "joshjohanning-repo-settings-sync[bot]" } }

Simpler code (5 lines instead of 14), one API call instead of two fallbacks.

Changes

  • Replace REST auth detection with octokit.graphql('{ viewer { login } }')
  • Remove users.getAuthenticated and apps.getAuthenticated usage
  • Add graphql mock to test suite
  • Bump to v2.9.2

400 tests pass.

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.
Copilot AI review requested due to automatic review settings April 25, 2026 02:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to octokit.graphql('{ viewer { login } }')
  • Update test Octokit mock shape to include graphql
  • Bump version to 2.9.2 and 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

Comment thread src/index.js
Comment thread __tests__/index.test.js
@joshjohanning joshjohanning merged commit 2190fc9 into main Apr 25, 2026
5 checks passed
@joshjohanning joshjohanning deleted the fix/app-auth-graphql-viewer branch April 25, 2026 02:55
@github-actions

Copy link
Copy Markdown

📦 Draft Release Created

A draft release v2.9.2 has been created for this PR.

🔗 View Draft Release

Next Steps

  • Review the release notes
  • Publish the release to make it permanent

This is an automated reminder from the publish-github-action workflow.

@joshjohanning

joshjohanning commented Apr 25, 2026

Copy link
Copy Markdown
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants