| 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | package web |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "fmt" |
| 8 | "log/slog" |
| 9 | "path/filepath" |
| 10 | |
| 11 | "github.com/jackc/pgx/v5/pgxpool" |
| 12 | |
| 13 | "github.com/tenseleyFlow/shithub/internal/auth/runnerjwt" |
| 14 | "github.com/tenseleyFlow/shithub/internal/infra/config" |
| 15 | "github.com/tenseleyFlow/shithub/internal/infra/storage" |
| 16 | githttph "github.com/tenseleyFlow/shithub/internal/web/handlers/githttp" |
| 17 | ) |
| 18 | |
| 19 | // buildGitHTTPHandlers wires the smart-HTTP route handlers. The bare |
| 20 | // repos live at cfg.Storage.ReposRoot; we refuse to boot the git-HTTP |
| 21 | // surface without it. |
| 22 | func buildGitHTTPHandlers( |
| 23 | cfg config.Config, |
| 24 | pool *pgxpool.Pool, |
| 25 | runnerJWT *runnerjwt.Signer, |
| 26 | logger *slog.Logger, |
| 27 | ) (*githttph.Handlers, error) { |
| 28 | if cfg.Storage.ReposRoot == "" { |
| 29 | return nil, errors.New("git-http: cfg.Storage.ReposRoot is empty") |
| 30 | } |
| 31 | root, err := filepath.Abs(cfg.Storage.ReposRoot) |
| 32 | if err != nil { |
| 33 | return nil, fmt.Errorf("git-http: resolve repos_root: %w", err) |
| 34 | } |
| 35 | rfs, err := storage.NewRepoFS(root) |
| 36 | if err != nil { |
| 37 | return nil, fmt.Errorf("git-http: NewRepoFS: %w", err) |
| 38 | } |
| 39 | return githttph.New(githttph.Deps{ |
| 40 | Logger: logger, |
| 41 | Pool: pool, |
| 42 | RepoFS: rfs, |
| 43 | RunnerJWT: runnerJWT, |
| 44 | }) |
| 45 | } |
| 46 |