canopy: selective trigger with --pipeline flag, fix cancel for containers

Anton Kaminsky21d ago191af2a306deparent 57c315f
3 files changed+10-5
api/src/routes/canopy.ts
@@ -237,7 +237,7 @@
237237 return reply.code(503).send({ error: "Canopy not enabled" });
238238 }
239239 const { owner, repo } = request.params;
240 const { ref } = (request.body as any) ?? {};
240 const { ref, pipeline } = (request.body as any) ?? {};
241241 const branch = ref || "main";
242242 const bridgeUrl =
243243 process.env.GROVE_BRIDGE_URL ?? "http://localhost:3100";
@@ -255,7 +255,7 @@
255255 branch,
256256 oldCommitId: "",
257257 newCommitId: commit_id,
258 });
258 }, pipeline);
259259 } catch {
260260 return reply.code(500).send({ error: "Failed to queue pipeline runs" });
261261 }
262262
api/src/services/canopy-runner.ts
@@ -124,7 +124,7 @@
124124 return Number(result.lastInsertRowid);
125125 }
126126
127 async onPush(event: PushEvent): Promise<void> {
127 async onPush(event: PushEvent, pipelineFilter?: string): Promise<void> {
128128 const repoId = this.ensureRepo(event.repo);
129129 if (!repoId) return;
130130
@@ -145,6 +145,7 @@
145145
146146 const matched = configs
147147 .filter(({ file, config }) => this.matchesTrigger(config, file, event.branch, changedFiles))
148 .filter(({ config }) => !pipelineFilter || config.name === pipelineFilter)
148149 .sort((a, b) => (a.config.order ?? 0) - (b.config.order ?? 0));
149150 if (matched.length === 0) return;
150151
151152
cli/src/commands/ci-trigger.ts
@@ -8,14 +8,18 @@
88 const refIdx = args.indexOf("--ref");
99 const ref = refIdx !== -1 ? args[refIdx + 1] : undefined;
1010
11 const pipelineIdx = args.indexOf("--pipeline");
12 const pipeline = pipelineIdx !== -1 ? args[pipelineIdx + 1] : undefined;
13
1114 const s = spinner();
1215 s.start("Triggering pipelines");
1316 const result = await hubRequest<{ triggered: boolean; branch: string; commit_id: string }>(
1417 `/api/repos/${slug}/canopy/trigger`,
1518 {
1619 method: "POST",
17 body: JSON.stringify({ ref }),
20 body: JSON.stringify({ ref, pipeline }),
1821 }
1922 );
20 s.stop(`Triggered pipelines on ${result.branch} (${result.commit_id.slice(0, 12)})`);
23 const label = pipeline ? `"${pipeline}"` : "pipelines";
24 s.stop(`Triggered ${label} on ${result.branch} (${result.commit_id.slice(0, 12)})`);
2125}
2226