Skip to content

fix: support GitHub App tokens for stale PR author matching#193

Merged
joshjohanning merged 2 commits into
mainfrom
fix/app-auth-stale-prs
Apr 24, 2026
Merged

fix: support GitHub App tokens for stale PR author matching#193
joshjohanning merged 2 commits into
mainfrom
fix/app-auth-stale-prs

Conversation

@joshjohanning

Copy link
Copy Markdown
Owner

Problem

The stale PR auto-close feature (PR #192) uses users.getAuthenticated() to determine who created the PR. This endpoint fails for GitHub App installation tokens, causing authenticatedLogin to be empty and the stale PR check to be skipped entirely.

Discovered via this workflow run — debug log showed:

[debug] Skipping stale PR check — authenticated user unknown

Fix

Try users.getAuthenticated() first (works for PATs), then fall back to apps.getAuthenticated() (works for GitHub App tokens). The app endpoint returns the app slug, which maps to the bot login {app-slug}[bot].

Changes

  • src/index.js: Add apps.getAuthenticated() fallback in run()
  • __tests__/index.test.js: Add apps.getAuthenticated mock to mockOctokit
  • Bump to v2.9.1

Testing

399 tests pass.

users.getAuthenticated() fails for GitHub App installation tokens.
Fall back to apps.getAuthenticated() to get the bot login
({app-slug}[bot]) for PR author matching.

Bump to v2.9.1.
Copilot AI review requested due to automatic review settings April 24, 2026 19:09

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 stale PR author matching when the action is authenticated with a GitHub App installation token by falling back from users.getAuthenticated() to apps.getAuthenticated() and mapping the returned app slug to the bot login ({slug}[bot]).

Changes:

  • Add an apps.getAuthenticated() fallback to determine authenticatedLogin when users.getAuthenticated() fails.
  • Extend the Jest Octokit mock to include rest.apps.getAuthenticated.
  • Bump package version to v2.9.1 (and refresh lockfile / coverage badge).
Show a summary per file
File Description
src/index.js Adds GitHub App auth fallback to populate authenticatedLogin for stale PR author matching.
__tests__/index.test.js Updates the Octokit REST mock to include apps.getAuthenticated.
package.json Bumps version to 2.9.1.
package-lock.json Syncs lockfile version fields to 2.9.1.
badges/coverage.svg Updates the generated coverage badge value.

Copilot's findings

  • Files reviewed: 3/5 changed files
  • Comments generated: 2

Comment thread src/index.js Outdated
Comment thread src/index.js Outdated
- Include users.getAuthenticated error in debug when both auth
  methods fail for easier diagnosis
- Add test verifying {app-slug}[bot] login format works for
  stale PR author matching
@joshjohanning joshjohanning merged commit 088fdb3 into main Apr 24, 2026
4 checks passed
@joshjohanning joshjohanning deleted the fix/app-auth-stale-prs branch April 24, 2026 20:19
@github-actions

Copy link
Copy Markdown

📦 Draft Release Created

A draft release v2.9.1 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.

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