| 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | // Package fork owns S27's fork orchestration. The DB row for a fork |
| 4 | // is created synchronously in Create; the on-disk `git clone --bare |
| 5 | // --shared` runs out-of-band as a `repo:fork_clone` worker job so |
| 6 | // fork creation returns fast even for large source repos. |
| 7 | // |
| 8 | // Sync (fast-forward fork's default branch from upstream) is the |
| 9 | // other entrypoint here. Cross-fork PR support extends `internal/ |
| 10 | // pulls` and lives there; this package is just the fork lifecycle. |
| 11 | package fork |
| 12 | |
| 13 | import ( |
| 14 | "errors" |
| 15 | "log/slog" |
| 16 | |
| 17 | "github.com/jackc/pgx/v5/pgxpool" |
| 18 | |
| 19 | "github.com/tenseleyFlow/shithub/internal/auth/audit" |
| 20 | "github.com/tenseleyFlow/shithub/internal/infra/storage" |
| 21 | ) |
| 22 | |
| 23 | // Deps wires this package against the rest of the runtime. |
| 24 | type Deps struct { |
| 25 | Pool *pgxpool.Pool |
| 26 | RepoFS *storage.RepoFS |
| 27 | Audit *audit.Recorder |
| 28 | Logger *slog.Logger |
| 29 | } |
| 30 | |
| 31 | // Errors surfaced to handlers. |
| 32 | var ( |
| 33 | ErrNotLoggedIn = errors.New("fork: login required") |
| 34 | ErrSourceNotFound = errors.New("fork: source repo not found") |
| 35 | ErrSourceNotVisible = errors.New("fork: source repo not visible to actor") |
| 36 | ErrTargetNameTaken = errors.New("fork: target name already exists for owner") |
| 37 | ErrVisibilityFloor = errors.New("fork: target visibility cannot exceed source visibility") |
| 38 | ErrSelfForkSameName = errors.New("fork: forking into the same owner requires a different name") |
| 39 | ErrSourceArchived = errors.New("fork: source repo is archived") |
| 40 | ErrSourceDeleted = errors.New("fork: source repo is deleted") |
| 41 | ErrSyncDiverged = errors.New("fork: fork has diverged from upstream; sync via your client") |
| 42 | ErrSyncUpToDate = errors.New("fork: already up to date") |
| 43 | ErrSyncDefaultsMissing = errors.New("fork: source or fork default branch is empty") |
| 44 | ErrSyncRefRaced = errors.New("fork: ref changed concurrently; retry") |
| 45 | ErrForkNotInitialized = errors.New("fork: fork is still being prepared") |
| 46 | ) |
| 47 |