| 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | package fork |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "fmt" |
| 8 | |
| 9 | reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc" |
| 10 | usersdb "github.com/tenseleyFlow/shithub/internal/users/sqlc" |
| 11 | ) |
| 12 | |
| 13 | // ownerUsername resolves the username string for a repo owner. Only |
| 14 | // user-owned repos are supported today; org-owned repos surface |
| 15 | // when S31 lands. Returns an error rather than guessing when the |
| 16 | // repo isn't user-owned so the caller fails loudly during the |
| 17 | // transition rather than silently misroute. |
| 18 | func ownerUsername(ctx context.Context, deps Deps, repo reposdb.Repo) (string, error) { |
| 19 | if !repo.OwnerUserID.Valid { |
| 20 | return "", fmt.Errorf("fork: repo %d has no user owner (org-owned repos arrive in S31)", repo.ID) |
| 21 | } |
| 22 | u, err := usersdb.New().GetUserByID(ctx, deps.Pool, repo.OwnerUserID.Int64) |
| 23 | if err != nil { |
| 24 | return "", fmt.Errorf("fork: load owner: %w", err) |
| 25 | } |
| 26 | return u.Username, nil |
| 27 | } |
| 28 |