| 59e6667 | | | 1 | import { spinner } from "@clack/prompts"; |
| 69d1a72 | | | 2 | import { hubRequest } from "../api.js"; |
| 69d1a72 | | | 3 | import { getRepoSlug } from "../config.js"; |
| 69d1a72 | | | 4 | |
| 69d1a72 | | | 5 | export async function ciTrigger(args: string[]) { |
| 69d1a72 | | | 6 | const slug = await getRepoSlug(args); |
| 69d1a72 | | | 7 | |
| 69d1a72 | | | 8 | const refIdx = args.indexOf("--ref"); |
| 69d1a72 | | | 9 | const ref = refIdx !== -1 ? args[refIdx + 1] : undefined; |
| 69d1a72 | | | 10 | |
| 191af2a | | | 11 | const pipelineIdx = args.indexOf("--pipeline"); |
| 191af2a | | | 12 | const pipeline = pipelineIdx !== -1 ? args[pipelineIdx + 1] : undefined; |
| 191af2a | | | 13 | |
| 59e6667 | | | 14 | const s = spinner(); |
| 59e6667 | | | 15 | s.start("Triggering pipelines"); |
| 69d1a72 | | | 16 | const result = await hubRequest<{ triggered: boolean; branch: string; commit_id: string }>( |
| 69d1a72 | | | 17 | `/api/repos/${slug}/canopy/trigger`, |
| 69d1a72 | | | 18 | { |
| 69d1a72 | | | 19 | method: "POST", |
| 191af2a | | | 20 | body: JSON.stringify({ ref, pipeline }), |
| 69d1a72 | | | 21 | } |
| 69d1a72 | | | 22 | ); |
| 191af2a | | | 23 | const label = pipeline ? `"${pipeline}"` : "pipelines"; |
| 191af2a | | | 24 | s.stop(`Triggered ${label} on ${result.branch} (${result.commit_id.slice(0, 12)})`); |
| 69d1a72 | | | 25 | } |