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