| 59e6667 | | | 1 | import { spinner, log } from "@clack/prompts"; |
| 69d1a72 | | | 2 | import { hubRequest } from "../api.js"; |
| 69d1a72 | | | 3 | import { getRepoSlug } from "../config.js"; |
| 69d1a72 | | | 4 | |
| 69d1a72 | | | 5 | export async function ciCancel(args: string[]) { |
| 69d1a72 | | | 6 | const slug = await getRepoSlug(args); |
| 69d1a72 | | | 7 | |
| 69d1a72 | | | 8 | const runId = args.find((a) => !a.startsWith("--") && /^\d+$/.test(a)); |
| 69d1a72 | | | 9 | if (!runId) { |
| 59e6667 | | | 10 | log.error("Usage: grove ci cancel <run-id> [--repo <owner/repo>]"); |
| 69d1a72 | | | 11 | process.exit(1); |
| 69d1a72 | | | 12 | } |
| 69d1a72 | | | 13 | |
| 59e6667 | | | 14 | const s = spinner(); |
| 59e6667 | | | 15 | s.start(`Cancelling run #${runId}`); |
| 69d1a72 | | | 16 | const { run } = await hubRequest<{ run: { id: number; status: string } }>( |
| 69d1a72 | | | 17 | `/api/repos/${slug}/canopy/runs/${runId}/cancel`, |
| 69d1a72 | | | 18 | { method: "POST" } |
| 69d1a72 | | | 19 | ); |
| 59e6667 | | | 20 | s.stop(`Cancelled run #${run.id} (${run.status})`); |
| 69d1a72 | | | 21 | } |