Skip to content

Commit

Permalink
Merge pull request #1 from heroku/add-acm-to-app
Browse files Browse the repository at this point in the history
Add ACM to apps:info output
  • Loading branch information
Ransom Briggs authored and jdx committed Jun 19, 2018
1 parent a2b5ba9 commit 438eba1
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
19 changes: 15 additions & 4 deletions packages/heroku-apps/commands/apps/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ function * run (context, heroku) {
const countBy = require('lodash.countby')

function getInfo (app) {
return {
let promises = {
addons: heroku.get(`/apps/${app}/addons`),
app: heroku.get(context.flags.extended ? `/apps/${app}?extended=true` : `/apps/${app}`),
app: heroku.request({
path: `/apps/${app}`,
headers: {'Accept': 'application/vnd.heroku+json; version=3.cedar-acm'}
}),
dynos: heroku.get(`/apps/${app}/dynos`).catch(() => []),
collaborators: heroku.get(`/apps/${app}/collaborators`).catch(() => []),
pipeline: heroku.get(`/apps/${app}/pipeline-couplings`).catch(() => null)
}

if (context.flags.extended) {
promises.appExtended = heroku.get(`/apps/${app}?extended=true`)
}

return promises
}

let app = context.args.app || context.app
Expand All @@ -41,6 +50,7 @@ function * run (context, heroku) {
if (info.app.space) data['Space'] = info.app.space.name
if (info.pipeline) data['Pipeline'] = `${info.pipeline.pipeline.name} - ${info.pipeline.stage}`

data['ACM'] = info.app.acm
data['Git URL'] = info.app.git_url
data['Web URL'] = info.app.web_url
data['Repo Size'] = filesize(info.app.repo_size, {round: 0})
Expand All @@ -54,15 +64,16 @@ function * run (context, heroku) {
cli.styledObject(data)

if (context.flags.extended) {
console.log('\n\n--- Extended Information ---\n\n')
cli.debug(info.app.extended)
cli.log('\n\n--- Extended Information ---\n\n')
cli.log(util.inspect(info.appExtended.extended))
}
}

function shell () {
function print (k, v) {
cli.log(`${S(k).underscore()}=${v}`)
}
print('acm', info.app.acm)
print('addons', addons)
print('collaborators', collaborators)

Expand Down
71 changes: 67 additions & 4 deletions packages/heroku-apps/test/commands/apps/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ let app = {
space: {name: 'myspace'}
}

let appExtended = Object.assign({}, app, {
extended: {
foo: 'bar'
}
})

let appAcm = Object.assign({}, app, {
acm: true
})

let addons = [
{plan: {name: 'papertrail'}},
{plan: {name: 'heroku-redis'}}
Expand All @@ -34,14 +44,18 @@ describe('apps:info', () => {
beforeEach(() => cli.mockConsole())

it('shows app info', () => {
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').reply(200, app)
.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({app: 'myapp', args: {}, flags: {}})
.then(() => expect(cli.stderr).to.equal(''))
.then(() => expect(cli.stdout).to.equal(`=== myapp
ACM: true
Addons: heroku-redis
papertrail
Collaborators: foo2@foo.com
Expand All @@ -56,19 +70,62 @@ Space: myspace
Stack: cedar-14
Web URL: https://myapp.herokuapp.com
`))
.then(() => appApi.done())
.then(() => api.done())
})

it('shows extended app info', () => {
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?extended=true').reply(200, appExtended)
.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({app: 'myapp', args: {}, flags: {extended: true}})
.then(() => expect(cli.stderr).to.equal(''))
.then(() => expect(cli.stdout).to.equal(`=== myapp
ACM: true
Addons: heroku-redis
papertrail
Collaborators: foo2@foo.com
Database Size: 1000 B
Dynos: web: 1
Git URL: https://git.heroku.com/myapp
Owner: foo@foo.com
Region: eu
Repo Size: 1000 B
Slug Size: 1000 B
Space: myspace
Stack: cedar-14
Web URL: https://myapp.herokuapp.com
--- Extended Information ---
{ foo: 'bar' }
`))
.then(() => appApi.done())
.then(() => api.done())
})

it('shows app info via arg', () => {
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').reply(200, app)
.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
ACM: true
Addons: heroku-redis
papertrail
Collaborators: foo2@foo.com
Expand All @@ -83,19 +140,24 @@ 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'}
}).get('/apps/myapp').reply(200, appAcm)

let api = nock('https://api.heroku.com:443')
.get('/apps/myapp').reply(200, app)
.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(`addons=heroku-redis,papertrail
.then(() => expect(cli.stdout).to.equal(`acm=true
addons=heroku-redis,papertrail
collaborators=foo2@foo.com
database_size=1000 B
git_url=https://git.heroku.com/myapp
Expand All @@ -107,6 +169,7 @@ region=eu
dynos={ web: 1 }
stack=cedar-14
`))
.then(() => appApi.done())
.then(() => api.done())
})
})

0 comments on commit 438eba1

Please sign in to comment.