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