UNPKG

981 BJavaScriptView Raw
1const api = require('./heroku-api')
2const cli = require('heroku-cli-util')
3const disambiguatePipeline = require('heroku-pipelines').disambiguatePipeline
4
5function * getPipeline (context, client) {
6 let pipeline = context.flags.pipeline
7
8 let pipelineOrApp = pipeline || context.app
9 if (!pipelineOrApp) cli.exit(1, 'Required flag: --pipeline PIPELINE or --app APP')
10
11 if (pipeline) {
12 pipeline = yield disambiguatePipeline(client, pipeline)
13 } else {
14 const coupling = yield api.pipelineCoupling(client, context.app)
15 pipeline = coupling.pipeline
16 }
17
18 return pipeline
19}
20
21// Deep get in an object, returning undefined if the path is invalid
22// e.g. get([{ foo: { bar: 'baz' } } ], 0, 'foo', 'bar') => 'baz'
23//
24function dig (obj, ...path) {
25 const key = path.shift()
26 if (key == null || obj == null) {
27 return
28 }
29 const val = obj[key]
30 if (typeof val === 'object') {
31 return dig(val, ...path)
32 }
33 return val
34}
35
36module.exports = {
37 getPipeline,
38 dig
39}