gr2m / gr2m/octokit-plugin-create-pull-request

Unable to update files that are larger than 1MB

Open
#139 1 comment 0 reactions 0 assignees View on GitHub
pull request welcome
Dominant language
TypeScript
Stars
116
Forks
31
PR merge metrics
No merged PRs in 30d

Description

When a file is larger than 1MB, the `content` field is an empty string when you try to update an existing file:

```js
// updates file based on current content
"path/to/file4.txt": ({ exists, encoding, content, size }) => {
// do not create the file if it does not exist
if (!exists) return null;

// content === '', encoding === 'none', size === 1240000
},
```

There are [some details in the docs](https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#get-repository-content) about the `GET /repos/{owner}/{repo}/contents/{path}` endpoint that is used in [createTree](https://github.com/gr2m/octokit-plugin-create-pull-request/blob/52cf4105a3d6110f821494f465050b0faf410518/src/create-tree.ts#L53-L61) that explain what is going wrong here:

> If the requested file's size is:
> - 1 MB or smaller: All features of this endpoint are supported.
> - Between 1-100 MB: Only the raw or object custom media types are supported. Both will work as normal, except that when using the object media type, the content field will be an empty string and the encoding field will be "none". To get the contents of these larger files, use the raw media type.
> - Greater than 100 MB: This endpoint is not supported.

It seems like what's happening is that the request is defaulting to use `Accept: application/vnd.github.object+json` header. But when the file is larger than 1MB, it should recognize this by reading the `size` property, and then calling the endpoint again with `Accept: application/vnd.github.raw+json` to get the full contents.

My current workaround is to do this extra request in my own code to get the file contents, but I feel like this could be handled by this library internally

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.