Skip to content

feat: optimize createTree to reduce REST API usage (#19)#21

Merged
c-vigo merged 17 commits intodevfrom
feature/19-createtree-api-rate-limit
Mar 24, 2026
Merged

feat: optimize createTree to reduce REST API usage (#19)#21
c-vigo merged 17 commits intodevfrom
feature/19-createtree-api-rate-limit

Conversation

@c-vigo
Copy link
Copy Markdown
Contributor

@c-vigo c-vigo commented Mar 24, 2026

Description

This pull request optimizes multi-file commits by using the GitHub createTree API's inline content field for text files so blobs are created server-side, instead of issuing one createBlob request per file. Binary files (NUL byte in the first 8 KiB) still use createBlob with base64 encoding. Large change sets are split into chained createTree calls (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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Test updates

Changes Made

  • Added isBinaryFile, getFileMode, and exported TREE_ENTRY_CHUNK_SIZE; refactored createTree to use inline content for text, createBlob for binary, and chunked tree creation when there are more than 100 entries.
  • Binary blob creation is sequential (not concurrent) to avoid secondary rate-limit bursts.
  • Non-UTF-8 text files: TextDecoder({ fatal: true }) with createBlob fallback to avoid silent data corruption.
  • isBinaryFile: uses bytesRead and scans only buf.subarray(0, bytesRead) to avoid false positives from zero-filled buffer tails.
  • Extended Jest setup and commit.test.ts for inline trees, binary/mixed paths, chunking, empty filePaths handling, and new helpers; clarified fs mock comment for binary detection.
  • Documented behavior under [Unreleased] in CHANGELOG.md (Added / Changed / Fixed). Updated README.md (features, module exports, example uses pin to @main with note that inline optimization is unreleased until next tag).
  • Regenerated dist/ via npm run build and npm run bundle.

Testing

  • Tests pass locally (npm test)
  • Manual testing performed (describe below)

Manual Testing Details

Not run against the live GitHub API in this environment; behavior is covered by unit tests with mocked Octokit.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (README.md, CONTRIBUTE.md, etc.)
  • I have updated the CHANGELOG.md in the [Unreleased] section
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

@c-vigo c-vigo self-assigned this Mar 24, 2026
@c-vigo c-vigo requested a review from Copilot March 24, 2026 10:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and getFileMode, and refactored createTree to inline content for text entries while falling back to createBlob for 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 regenerated dist/ 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.

Comment thread src/commit.ts Outdated
Comment thread src/commit.ts Outdated
Comment thread src/commit.ts
Comment thread src/commit.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread README.md Outdated
Comment thread src/__tests__/setup.ts Outdated
Comment thread src/commit.ts
@c-vigo c-vigo merged commit ae3d583 into dev Mar 24, 2026
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