UNPKG

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