Skip to content

Change GitHub API#479

Open
benmerckx wants to merge 4 commits intomainfrom
gh-api
Open

Change GitHub API#479
benmerckx wants to merge 4 commits intomainfrom
gh-api

Conversation

@benmerckx
Copy link
Copy Markdown
Member

Handle blob uploads separately so we run into memory and bandwidth limits less fast than before

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/alinea@479

commit: af7a971

This comment was marked as resolved.

benmerckx and others added 3 commits March 16, 2026 10:23
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

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 refactors the backend’s GitHub integration to reduce memory/bandwidth pressure during uploads by separating blob creation from tree/commit creation (REST Git endpoints + streaming), and introduces a new “git smart protocol” implementation (upload-pack / receive-pack) that is now wired in for write/getBlobs while keeping history APIs on the existing implementation.

Changes:

  • Switch GithubApi.write to REST Git data endpoints (blobs/trees/commits/refs) and stream large blob uploads in chunks with configurable concurrency and size limits.
  • Add a new GitSmartApi with protocol helpers (pkt-line, sideband parsing), pack (de)serialization, and commit object serialization.
  • Update backend wiring to compose implementations so write/getBlobs go through the smart implementation while revisions/revisionData remain on the existing GitHub implementation; add extensive tests.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/backend/api/GithubApi.ts Implements REST-based commit writes and streamed/chunked blob uploads with concurrency/limits.
src/backend/api/GithubApi.test.ts Adds coverage for REST write flow, streaming blob uploads, size limits, and race handling.
src/backend/api/GitSmartApi.ts Implements smart-protocol based write (receive-pack) and getBlobs (upload-pack).
src/backend/api/GitSmartApi.test.ts Adds end-to-end style protocol mocks to validate receive-pack/upload-pack behavior.
src/backend/api/gitSmart/GitSmartProtocol.ts Adds pkt-line encoding/decoding, advertisement parsing, and request builders.
src/backend/api/gitSmart/GitSmartProtocol.test.ts Adds unit tests for protocol parsing and request formatting.
src/backend/api/gitSmart/GitSmartPack.ts Adds pack creation and parsing (including delta handling).
src/backend/api/gitSmart/GitSmartPack.test.ts Adds pack roundtrip and ref-delta parsing tests.
src/backend/api/gitSmart/GitSmartObjects.ts Adds commit object serialization + hashing helpers.
src/backend/api/gitSmart/GitSmartObjects.test.ts Adds deterministic serialization/hash tests for commit objects.
src/backend/api/CreateBackend.ts Wires both GithubApi + GitSmartApi into the composed backend remote.
src/backend/api/CreateBackend.test.ts Verifies routing behavior of the composed remote implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

input.capabilities.has('side-band-64k') ? 'side-band-64k' : undefined,
input.capabilities.has('ofs-delta') ? 'ofs-delta' : undefined
].filter(Boolean)
const command = `${input.oldSha} ${input.newSha} ${input.ref}\0${requestedCaps.join(' ')}\n`
const unique = Array.from(new Set(shas))
const adv = await this.#advertise('git-upload-pack')
if (!adv.capabilities.has('allow-reachable-sha1-in-want')) {
yield* super.getBlobs(unique)
await end
return {
data: concatUint8Arrays(chunks),
bytesConsumed: inflater.bytesWritten
Comment on lines +28 to +36
const entries = await Promise.all(
objects.map(async object => {
const type = packTypeCode(object.type)
return concatUint8Arrays([
encodePackObjectHeader(type, object.data.length),
await deflate(object.data)
])
})
)
const requestedCaps = [
capabilities.has('side-band-64k') ? 'side-band-64k' : undefined,
capabilities.has('ofs-delta') ? 'ofs-delta' : undefined,
'no-progress'
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