Skip to content

[GithubSize] Support file paths via query parameter - #12107

Open
Kryptonzy wants to merge 1 commit into
badges:masterfrom
Kryptonzy:agent/fix-github-file-size-path
Open

[GithubSize] Support file paths via query parameter#12107
Kryptonzy wants to merge 1 commit into
badges:masterfrom
Kryptonzy:agent/fix-github-file-size-path

Conversation

@Kryptonzy

Copy link
Copy Markdown

Summary

Add a query-parameter form of the GitHub file-size badge so filenames that look like badge output formats can be requested without ambiguity:

/github/size/badges/shields.json?path=package.json

The existing path-based form remains supported for backward compatibility.

Fixes #10548.

Root cause and approach

In /github/size/badges/shields/package.json, Shields interprets the final .json as the requested badge format. The service consequently receives package as the file path and asks GitHub for the wrong file.

The service route now permits the path segment to be omitted and accepts path in its validated query schema. handle() prefers the existing route path when present, otherwise uses the query path, and returns a clear path is required error if neither is supplied. A second OpenAPI route documents the query form. This adds an unambiguous entry point without breaking existing badge URLs.

Verification

  • npm run test:services -- --only=GithubSize --fgrep='filename matching a badge format' — 1 passing.
  • npm run test:services -- --only=GithubSize --fgrep='File size without a path' — 1 passing.
  • The success regression mocks GitHub's contents API, asserts the request reaches /contents/package.json, and verifies a 1 KiB badge.
  • npx --no-install eslint services/github/github-size.service.js services/github/github-size.tester.js — passed.
  • npx --no-install prettier --check services/github/github-size.service.js services/github/github-size.tester.js — passed.
  • npm run defs — passed.

Scope

Only GithubSize routing/query validation, its OpenAPI definition, and two focused service tests change. Existing route-path and branch behavior are retained.

AI assistance

OpenAI Codex (GPT-5) was used to inspect the route/format interaction, implement the minimal backward-compatible change, and run/review the tests and final diff. The repository does not prohibit AI-assisted contributions; this usage is disclosed explicitly.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor
Messages
📖 ✨ Thanks for your contribution to Shields, @Kryptonzy!

Generated by 🚫 dangerJS against 03765a2

@Kryptonzy
Kryptonzy marked this pull request as ready for review August 10, 2026 12:44
@Kryptonzy
Kryptonzy force-pushed the agent/fix-github-file-size-path branch from 3d77fe6 to 03765a2 Compare August 10, 2026 15:23
@PyvesB

PyvesB commented Aug 11, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution @Kryptonzy ! Perhaps we could stop explicitly supporting the old route, and add a redirector to the new one with the query path parameter, for backwards compatibility. @DCjanus what do you think?

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

GitHub file size badge doesn't work for some files

2 participants