Skip to content

Authenticate the GitHub API call to avoid rate limiting - #134

Merged
kbond merged 3 commits into
SymfonyCasts:1.xfrom
Amoifr:1.x
Jul 23, 2026
Merged

Authenticate the GitHub API call to avoid rate limiting#134
kbond merged 3 commits into
SymfonyCasts:1.xfrom
Amoifr:1.x

Conversation

@Amoifr

@Amoifr Amoifr commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #60

TailwindVersionFinder queries the GitHub API to resolve the latest Tailwind release, but the request is anonymous, so it hits the low unauthenticated rate limit (60 requests/hour, shared per IP). That is what bit @nicolas-grekas during a workshop where everyone shared the same IP. The test suite already works around this by reading GITHUB_TOKEN, but the runtime code did not.

This authenticates the call with auth_bearer whenever a GitHub token can be found, looked up in this order:

  1. the GITHUB_TOKEN / GH_TOKEN environment variables (same convention as the existing test);
  2. the COMPOSER_AUTH environment variable;
  3. Composer's global auth.json (COMPOSER_HOME/auth.json, otherwise ~/.composer/auth.json and ~/.config/composer/auth.json), reading the github-oauth token developers usually already have configured (@nicolas-grekas' first idea).

Without any token the behavior is unchanged (still anonymous, just rate limited as before), so nothing breaks for existing setups.

Tests use a MockHttpClient to assert the Authorization header is sent for each source and absent otherwise, with the environment isolated so the existing live test keeps reading GITHUB_TOKEN.

A couple of deliberate scope choices, happy to adjust:

  • I only read Composer's global auth.json, not a project-level one, since the github-oauth token is almost always global. Easy to add if you'd prefer.
  • I did not implement the "commit the resolved version" idea from the issue; that felt like a separate feature.

Thanks a lot for the bundle, and @bocharsky-bw for keeping this one alive! 🙏

Amoifr and others added 3 commits July 21, 2026 14:09
Resolve the GitHub token once in the constructor and layer `auth_bearer`
onto the injected client with `ScopingHttpClient`, instead of rebuilding
the request options and re-reading the token on every paginated `tags()`
call.

Merge the token coverage into `TailwindVersionFinderTest`.
@kbond

kbond commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Thanks @Amoifr, great addition! I made a few minor modifications.

@kbond
kbond merged commit 5bd355d into SymfonyCasts:1.x Jul 23, 2026
12 checks passed
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.

Rate limiting when hitting the github API

2 participants