1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const inquirer_1 = require("inquirer");
|
4 | const validator_1 = require("validator");
|
5 | async function disambiguatePipeline(pipelineIDOrName, command) {
|
6 | const headers = { Accept: 'application/vnd.heroku+json; version=3.pipelines' };
|
7 | if (validator_1.isUUID(pipelineIDOrName)) {
|
8 | const { body: pipeline } = await command.heroku.get(`/pipelines/${pipelineIDOrName}`, { headers });
|
9 | return pipeline;
|
10 | }
|
11 | const { body: pipelines } = await command.heroku.get(`/pipelines?eq[name]=${pipelineIDOrName}`, { headers });
|
12 | let choices;
|
13 | let questions;
|
14 | switch (pipelines.length) {
|
15 | case 0:
|
16 | command.error('Pipeline not found');
|
17 | break;
|
18 | case 1:
|
19 | return pipelines[0];
|
20 | default:
|
21 | choices = pipelines.map(function (x) {
|
22 | return { name: new Date(x.created_at), value: x };
|
23 | });
|
24 | questions = [{
|
25 | type: 'list',
|
26 | name: 'pipeline',
|
27 | message: `Which ${pipelineIDOrName} pipeline?`,
|
28 | choices,
|
29 | }];
|
30 | return inquirer_1.prompt(questions);
|
31 | }
|
32 | }
|
33 | exports.disambiguatePipeline = disambiguatePipeline;
|
34 | async function getPipeline(flags, command) {
|
35 | let pipeline;
|
36 | if ((!flags.pipeline) && (!flags.app)) {
|
37 | command.error('Required flag: --pipeline PIPELINE or --app APP');
|
38 | }
|
39 | if (flags && flags.pipeline) {
|
40 | pipeline = await disambiguatePipeline(flags.pipeline, command);
|
41 | if (pipeline.pipeline) {
|
42 | pipeline = pipeline.pipeline;
|
43 | }
|
44 | }
|
45 | else {
|
46 | const { body: coupling } = await command.heroku.get(`/apps/${flags.app}/pipeline-couplings`);
|
47 | if ((coupling) && (coupling.pipeline)) {
|
48 | pipeline = coupling.pipeline;
|
49 | }
|
50 | else {
|
51 | command.error(`No pipeline found with application ${flags.app}`);
|
52 | }
|
53 | }
|
54 | return pipeline;
|
55 | }
|
56 | exports.getPipeline = getPipeline;
|