Skip to content

fix: use raw accept header in getContent to support CODEOWNERS files > 1 MB#15

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-raw-file-contents-issue
Draft

fix: use raw accept header in getContent to support CODEOWNERS files > 1 MB#15
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-raw-file-contents-issue

Conversation

Copilot AI commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

octokit.rest.repos.getContent returns base64-encoded content capped at ~1 MB, but GitHub supports CODEOWNERS files up to 3 MB. Using the application/vnd.github.raw accept header bypasses that cap entirely (100 MB limit).

src/main.ts

  • Add headers: { accept: 'application/vnd.github.raw' } to the getContent call
  • With the raw header, response.data is the file content as a plain string — remove base64 decoding, encoding-type guard, and array/directory guard (directories now yield a GitHub API error caught by the existing catch block)
const response = await octokit.rest.repos.getContent({
  owner,
  repo,
  path: codeownersPath,
  ref: headSha,
  headers: {
    accept: 'application/vnd.github.raw'
  }
})
const codeownersRaw = response.data as unknown as string

__tests__/main.test.ts

  • Update all getContent mocks from { data: { content: b64(x), encoding: 'base64' } } to { data: x }
  • Replace the "fails when file is too large (encoding none)" test with "succeeds when the CODEOWNERS file is larger than 1 MB"
  • Update the directory-path test to mock a rejected promise (GitHub returns 422 for directory paths with the raw header)
  • Remove the now-unused b64() helper

…up to 100 MB

Add `accept: 'application/vnd.github.raw'` header to the `octokit.rest.repos.getContent`
call so that the GitHub API returns file contents directly as a string instead of a
base64-encoded object. This bypasses the ~1 MB API cap and supports files up to 100 MB,
matching the 3 MB limit GitHub supports for CODEOWNERS files.

Simplify the response-handling code accordingly (no base64 decoding needed) and update
all tests to mock the raw string response format.
Copilot AI changed the title [WIP] Fix request for raw file contents to handle large CODEOWNERS files fix: use raw accept header in getContent to support CODEOWNERS files > 1 MB Jun 20, 2026
Copilot AI requested a review from aebrahim June 20, 2026 19:20
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