1 | const api = require('./heroku-api')
|
2 | const cli = require('heroku-cli-util')
|
3 | const disambiguatePipeline = require('@heroku-cli/plugin-pipelines').disambiguatePipeline
|
4 |
|
5 | function * 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 |
|
22 |
|
23 |
|
24 | function 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 |
|
36 | module.exports = {
|
37 | getPipeline,
|
38 | dig
|
39 | }
|