From fbb68c1de00cae64f07e2324c3fcb097ca6016a4 Mon Sep 17 00:00:00 2001 From: Stanley Stuart Date: Fri, 22 Jan 2021 08:57:14 -0800 Subject: [PATCH] fix(apps-v5): get pipeline stage from `pipeline_coupling` [775c679dd069342074cfbb96fea887e72db1c4f7][1] removed the `pipeline` object from the `info` object used to render the display in `apps:info` to fix a deprecation warning. Unfortunately, it seems like this introduced a regression as code that was referencing `info.pipeline` was not updated to use `info.pipeline_coupling`, resulting in runtime exceptions due to trying to access a property off of `undefined`. Work Item: [W-8780887][2] [1]: https://github.com/heroku/cli/commit/775c679dd069342074cfbb96fea887e72db1c4f7 [2]: https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07B00000094UCiIAM/view --- packages/apps-v5/src/commands/apps/info.js | 4 +- packages/apps-v5/test/commands/apps/info.js | 66 +++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/packages/apps-v5/src/commands/apps/info.js b/packages/apps-v5/src/commands/apps/info.js index ba09fb69d0..ad62288e30 100644 --- a/packages/apps-v5/src/commands/apps/info.js +++ b/packages/apps-v5/src/commands/apps/info.js @@ -58,7 +58,7 @@ function * run (context, heroku) { if (info.app.create_status !== 'complete') data['Create Status'] = info.app.create_status if (info.app.space) data['Space'] = info.app.space.name if (info.app.space && info.app.internal_routing) data['Internal Routing'] = info.app.internal_routing - if (info.pipeline_coupling) data['Pipeline'] = `${info.pipeline_coupling.pipeline.name} - ${info.pipeline.stage}` + if (info.pipeline_coupling) data['Pipeline'] = `${info.pipeline_coupling.pipeline.name} - ${info.pipeline_coupling.stage}` data['Auto Cert Mgmt'] = info.app.acm data['Git URL'] = info.app.git_url @@ -100,7 +100,7 @@ function * run (context, heroku) { if (info.app.cron_next_run) print('cron_next_run', cli.formatDate(new Date(info.app.cron_next_run))) if (info.app.database_size) print('database_size', filesize(info.app.database_size, { round: 0 })) if (info.app.create_status !== 'complete') print('create_status', info.app.create_status) - if (info.pipeline_coupling) print('pipeline', `${info.pipeline_coupling.pipeline.name}:${info.pipeline.stage}`) + if (info.pipeline_coupling) print('pipeline', `${info.pipeline_coupling.pipeline.name}:${info.pipeline_coupling.stage}`) print('git_url', info.app.git_url) print('web_url', info.app.web_url) diff --git a/packages/apps-v5/test/commands/apps/info.js b/packages/apps-v5/test/commands/apps/info.js index f1de64b976..bc232833c8 100644 --- a/packages/apps-v5/test/commands/apps/info.js +++ b/packages/apps-v5/test/commands/apps/info.js @@ -193,6 +193,42 @@ Web URL: https://myapp.herokuapp.com .then(() => expect(context.app).to.equal('myapp')) }) + it('shows app info via arg when the app is in a pipeline', () => { + let appApi = nock('https://api.heroku.com', { + reqheaders: { 'Accept': 'application/vnd.heroku+json; version=3.cedar-acm' } + }).get('/apps/myapp').reply(200, appAcm) + + let api = nock('https://api.heroku.com:443') + .get('/apps/myapp/pipeline-couplings').reply(200, { app: { id: appAcm.id }, pipeline: { name: 'my-pipeline' }, stage: 'production' }) + .get('/apps/myapp/addons').reply(200, addons) + .get('/apps/myapp/collaborators').reply(200, collaborators) + .get('/apps/myapp/dynos').reply(200, [{ type: 'web', size: 'Standard-1X', quantity: 2 }]) + let context = { args: { app: 'myapp' }, flags: {} } + return cmd.run(context) + .then(() => expect(cli.stderr).to.equal('')) + .then(() => expect(cli.stdout).to.equal(`=== myapp +Addons: heroku-redis + papertrail +Auto Cert Mgmt: true +Collaborators: foo2@foo.com +Database Size: 1000 B +Dynos: web: 1 +Git URL: https://git.heroku.com/myapp +Internal Routing: true +Owner: foo@foo.com +Pipeline: my-pipeline - production +Region: eu +Repo Size: 1000 B +Slug Size: 1000 B +Space: myspace +Stack: cedar-14 +Web URL: https://myapp.herokuapp.com +`)) + .then(() => appApi.done()) + .then(() => api.done()) + .then(() => expect(context.app).to.equal('myapp')) + }) + it('shows app info in shell format', () => { let appApi = nock('https://api.heroku.com', { reqheaders: { 'Accept': 'application/vnd.heroku+json; version=3.cedar-acm' } @@ -221,6 +257,36 @@ stack=cedar-14 .then(() => api.done()) }) + it('shows app info in shell format when the app is in pipeline', () => { + let appApi = nock('https://api.heroku.com', { + reqheaders: { 'Accept': 'application/vnd.heroku+json; version=3.cedar-acm' } + }).get('/apps/myapp').reply(200, appAcm) + + let api = nock('https://api.heroku.com:443') + .get('/apps/myapp/pipeline-couplings').reply(200, { app: { id: appAcm.id }, pipeline: { name: 'my-pipeline' }, stage: 'production' }) + .get('/apps/myapp/addons').reply(200, addons) + .get('/apps/myapp/collaborators').reply(200, collaborators) + .get('/apps/myapp/dynos').reply(200, [{ type: 'web', size: 'Standard-1X', quantity: 2 }]) + return cmd.run({ args: { app: 'myapp' }, flags: { shell: true } }) + .then(() => expect(cli.stderr).to.equal('')) + .then(() => expect(cli.stdout).to.equal(`auto_cert_mgmt=true +addons=heroku-redis,papertrail +collaborators=foo2@foo.com +database_size=1000 B +pipeline=my-pipeline:production +git_url=https://git.heroku.com/myapp +web_url=https://myapp.herokuapp.com +repo_size=1000 B +slug_size=1000 B +owner=foo@foo.com +region=eu +dynos={ web: 1 } +stack=cedar-14 +`)) + .then(() => appApi.done()) + .then(() => api.done()) + }) + it('shows extended app info in json format', () => { let appApi = nock('https://api.heroku.com', { reqheaders: { 'Accept': 'application/vnd.heroku+json; version=3.cedar-acm' }