feat: optimize createTree to reduce REST API usage (#19)#21
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces GitHub REST API usage when creating commits by inlining UTF-8 text file contents directly in the git.createTree request (server-side blob creation), while still using git.createBlob for detected binary files and chaining createTree calls in chunks for large change sets.
Changes:
- Added
TREE_ENTRY_CHUNK_SIZE,isBinaryFile, andgetFileMode, and refactoredcreateTreeto inlinecontentfor text entries while falling back tocreateBlobfor binary entries. - Added/updated Jest unit tests and FS mocks to cover inline trees, binary/mixed commits, and chunking behavior.
- Updated docs (
README.md,CHANGELOG.md) and regenerateddist/artifacts.
Reviewed changes
Copilot reviewed 5 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/commit.ts | Implements inline-tree optimization, binary detection, and chained tree creation. |
| src/tests/unit/commit.test.ts | Adds unit coverage for inline content, binary fallback, mixed entries, and chunking. |
| src/tests/setup.ts | Extends fs mock to support isBinaryFile reads. |
| dist/src/commit.js | Built JS output for the updated commit logic. |
| dist/src/commit.js.map | Sourcemap for built commit logic. |
| dist/src/commit.d.ts | Built type declarations exposing new helpers/constants. |
| dist/src/commit.d.ts.map | Sourcemap for built type declarations. |
| dist/src/tests/unit/commit.test.js | Built JS output for updated tests. |
| dist/src/tests/unit/commit.test.js.map | Sourcemap for built tests. |
| dist/src/tests/setup.js | Built JS output for updated test setup. |
| dist/src/tests/setup.js.map | Sourcemap for updated test setup. |
| dist/index.js | Bundled action output containing the updated implementation/exports. |
| README.md | Documents rate-limit friendliness and new module exports; updates usage pin. |
| CHANGELOG.md | Documents the new behavior and newly exported helpers under [Unreleased]. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 14 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…euse buffer on UTF-8 failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request optimizes multi-file commits by using the GitHub
createTreeAPI's inlinecontentfield for text files so blobs are created server-side, instead of issuing onecreateBlobrequest per file. Binary files (NUL byte in the first 8 KiB) still usecreateBlobwith base64 encoding. Large change sets are split into chainedcreateTreecalls (100 entries per request) to stay within payload limits.This reduces REST traffic for large commits (for example, on the order of five calls plus ref/commit steps for many text files, instead of one blob per file) and is easier on GitHub App secondary rate limits. Commits remain API-created and verified the same way as before; authentication is unchanged.
Related Issue(s)
Closes #19
Type of Change
Changes Made
isBinaryFile,getFileMode, and exportedTREE_ENTRY_CHUNK_SIZE; refactoredcreateTreeto use inlinecontentfor text,createBlobfor binary, and chunked tree creation when there are more than 100 entries.TextDecoder({ fatal: true })withcreateBlobfallback to avoid silent data corruption.isBinaryFile: usesbytesReadand scans onlybuf.subarray(0, bytesRead)to avoid false positives from zero-filled buffer tails.commit.test.tsfor inline trees, binary/mixed paths, chunking, emptyfilePathshandling, and new helpers; clarified fs mock comment for binary detection.[Unreleased]inCHANGELOG.md(Added / Changed / Fixed). UpdatedREADME.md(features, module exports, exampleusespin to@mainwith note that inline optimization is unreleased until next tag).dist/vianpm run buildandnpm run bundle.Testing
npm test)Manual Testing Details
Not run against the live GitHub API in this environment; behavior is covered by unit tests with mocked Octokit.
Checklist
[Unreleased]sectionAdditional Notes
bugfix/19-createtree-api-rate-limittofeature/19-createtree-api-rate-limit; issue Optimize createTree to reduce GitHub REST API usage #19 was recategorized as an enhancement with an updated title.@main, dist).