| 59e6667 | | | 1 | import { spinner, log } from "@clack/prompts"; |
| e93a978 | | | 2 | import { hubRequest } from "../api.js"; |
| e93a978 | | | 3 | |
| e93a978 | | | 4 | interface Repo { |
| e93a978 | | | 5 | id: number; |
| e93a978 | | | 6 | owner_name: string; |
| e93a978 | | | 7 | name: string; |
| e93a978 | | | 8 | description: string | null; |
| e93a978 | | | 9 | default_branch: string; |
| e93a978 | | | 10 | } |
| e93a978 | | | 11 | |
| e93a978 | | | 12 | export async function repoCreate(args: string[]) { |
| e93a978 | | | 13 | const name = args.find((a) => !a.startsWith("--")); |
| e93a978 | | | 14 | if (!name) { |
| 59e6667 | | | 15 | log.error("Usage: grove repo create <name> [--description <desc>] [--branch <branch>]"); |
| e93a978 | | | 16 | process.exit(1); |
| e93a978 | | | 17 | } |
| e93a978 | | | 18 | |
| e93a978 | | | 19 | const descIdx = args.indexOf("--description"); |
| e93a978 | | | 20 | const description = descIdx !== -1 ? args[descIdx + 1] : undefined; |
| e93a978 | | | 21 | |
| e93a978 | | | 22 | const branchIdx = args.indexOf("--branch"); |
| e93a978 | | | 23 | const default_branch = branchIdx !== -1 ? args[branchIdx + 1] : undefined; |
| e93a978 | | | 24 | |
| 59129ad | | | 25 | const ownerIdx = args.indexOf("--owner"); |
| 59129ad | | | 26 | const owner = ownerIdx !== -1 ? args[ownerIdx + 1] : undefined; |
| 59129ad | | | 27 | |
| 0d9d723 | | | 28 | const is_private = args.includes("--private"); |
| 59129ad | | | 29 | const skip_seed = args.includes("--no-seed"); |
| 59129ad | | | 30 | |
| 59e6667 | | | 31 | const s = spinner(); |
| 59e6667 | | | 32 | s.start(`Creating repository '${name}'`); |
| e93a978 | | | 33 | const { repo } = await hubRequest<{ repo: Repo }>("/api/repos", { |
| e93a978 | | | 34 | method: "POST", |
| 0d9d723 | | | 35 | body: JSON.stringify({ name, description, default_branch, owner, is_private, skip_seed }), |
| e93a978 | | | 36 | }); |
| 59e6667 | | | 37 | s.stop(`Created repository: ${repo.owner_name}/${repo.name}`); |
| e93a978 | | | 38 | } |