# GithubSyncAdapter

**Kind:** Class

**Source:** [`atloria-monorepo/apps/api/src/git-sync/github-sync.adapter.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/apps/api/src/git-sync/github-sync.adapter.ts#L55)

GithubSyncAdapter — the ONE place B1 talks to GitHub. Reads (refs, trees, blobs, compare)
and writes (blobs → tree → commit → fast-forward ref update) via the existing GitHub App
installation tokens, exactly like the freshness-PR GitHubWriteAdapter: hand-rolled REST
over axios (no octokit in the repo), commits onto the CUSTOMER branch tip via the Git Data
API — content, not history; NEVER a force update.

## Methods

| Method | Signature | Returns |
|---|---|---|
| `tokenFor` | `tokenFor(repoFullName: string)` | `Promise<string>` |
| `getBranchTip` | `getBranchTip(token: string, repoFullName: string, branch: string)` | `Promise<RemoteTip | null>` |
| `commitExists` | `commitExists(token: string, repoFullName: string, sha: string)` | `Promise<boolean>` |
| `compare` | `compare(token: string, repoFullName: string, base: string, head: string)` | `Promise<{ status: string; files: RemoteChangedFile[] } | null>` |
| `getTreeRecursive` | `getTreeRecursive(token: string, repoFullName: string, treeSha: string)` | `Promise<RemoteTreeEntry[]>` |
| `getFileAtRef` | `getFileAtRef(token: string, repoFullName: string, path: string, ref: string)` | `Promise<string | null>` |
| `createBlob` | `createBlob(token: string, repoFullName: string, content: string)` | `Promise<string>` |
| `createTree` | `createTree(token: string, repoFullName: string, baseTreeSha: string, entries: NewTreeEntry[])` | `Promise<string>` |
| `createCommit` | `createCommit(token: string, repoFullName: string, message: string, treeSha: string, parents: string[])` | `Promise<string>` |
| `updateRef` | `updateRef(token: string, repoFullName: string, branch: string, sha: string)` | `Promise<void>` |

## Where it refuses work

- `GithubSyncAdapter` stops the work with `SyncNotPermittedError` when `res.status === 403`, in 2 places.
- `GithubSyncAdapter` stops the work with `SyncNotPermittedError` when `!creds?.password`.
- `GithubSyncAdapter` stops the work with `Error` when `res.data?.truncated === true`.
- `GithubSyncAdapter` stops the work with `Error` when `res.status >= 400`.
- `GithubSyncAdapter` stops the work with an early return when `res.status === 404`, in 3 places.
- `GithubSyncAdapter` stops the work with an early return when `ref.status === 404`.

## Referenced By

- `GitSyncIngestService` (DEPENDS_ON)
- `GitSyncModule` (MODULE_PROVIDES)
- `GitSyncMirrorService` (DEPENDS_ON)
