Skip to content

fix: improve PR fetch error handling and document fine-grained PAT 403 issue#90

Merged
unhappychoice merged 1 commit intomainfrom
fix/pr-fetch-403-handling
Apr 5, 2026
Merged

fix: improve PR fetch error handling and document fine-grained PAT 403 issue#90
unhappychoice merged 1 commit intomainfrom
fix/pr-fetch-403-handling

Conversation

@unhappychoice
Copy link
Copy Markdown
Member

Summary

  • Retry PR fetches only on 429 (rate limit), not on 403 (permission/policy errors)
  • Log the response body message on non-OK responses so users can see the actual cause (e.g. organization lifetime policy)
  • Add 200ms inter-request delay to follow GitHub API best practices
  • Document the fine-grained PAT organization lifetime policy issue in docs/troubleshooting.md

Background

When using a fine-grained PAT with a lifetime exceeding 366 days, GitHub's default organization token policy blocks API access to repositories in organizations the user belongs to, even for public repositories. This causes 403 Forbidden errors during PR fetching.

The error message from GitHub is:

The 'org-name' organization forbids access via a fine-grained personal access tokens if the token's lifetime is greater than 366 days.

This is an inconsistency in GitHub's implementation: the approval policy correctly exempts public resources, but the lifetime policy does not. The same issue has been reported in composer/composer#12711.

Previously, the error was logged as just 403 Forbidden without the response body, making it impossible for users to diagnose the cause.

…3 issue

- Retry only on 429 (rate limit), not on 403 (permission/policy errors)
- Log response body message on 403 so users can see the actual cause
- Add inter-request delay (200ms) to respect GitHub API best practices
- Document the fine-grained PAT organization lifetime policy issue
  in troubleshooting.md with references and workarounds
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 58.82353% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/collector/fetch-repo-prs.ts 58.82% 11 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@unhappychoice unhappychoice merged commit 2954468 into main Apr 5, 2026
2 of 3 checks passed
@unhappychoice unhappychoice deleted the fix/pr-fetch-403-handling branch April 5, 2026 04:36
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.

1 participant