Merge pull request #33 from heroku/add-pipeline-flag-support
Add pipeline flag support to all ci commands
This commit is contained in:
Коммит
90b86b53e8
|
@ -2,10 +2,11 @@ const cli = require('heroku-cli-util')
|
|||
const co = require('co')
|
||||
const shellescape = require('shell-escape')
|
||||
const api = require('../../lib/heroku-api')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
function* run (context, heroku) {
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
const config = yield api.configVars(heroku, coupling.pipeline.id)
|
||||
const pipeline = yield Utils.getPipeline(context, heroku)
|
||||
const config = yield api.configVars(heroku, pipeline.id)
|
||||
const value = config[context.args.key]
|
||||
|
||||
if (context.flags.shell) {
|
||||
|
@ -18,7 +19,7 @@ function* run (context, heroku) {
|
|||
module.exports = {
|
||||
topic: 'ci',
|
||||
command: 'config:get',
|
||||
needsApp: true,
|
||||
wantsApp: true,
|
||||
needsAuth: true,
|
||||
description: 'get a CI config var',
|
||||
help: `Examples:
|
||||
|
@ -28,10 +29,18 @@ test
|
|||
args: [{
|
||||
name: 'key'
|
||||
}],
|
||||
flags: [{
|
||||
name: 'shell',
|
||||
char: 's',
|
||||
description: 'output config var in shell format'
|
||||
}],
|
||||
flags: [
|
||||
{
|
||||
name: 'shell',
|
||||
char: 's',
|
||||
description: 'output config var in shell format'
|
||||
},
|
||||
{
|
||||
name: 'pipeline',
|
||||
char: 'p',
|
||||
hasValue: true,
|
||||
description: 'pipeline'
|
||||
}
|
||||
],
|
||||
run: cli.command(co.wrap(run))
|
||||
}
|
||||
|
|
|
@ -2,10 +2,11 @@ const cli = require('heroku-cli-util')
|
|||
const co = require('co')
|
||||
const shellescape = require('shell-escape')
|
||||
const api = require('../../lib/heroku-api')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
function* run (context, heroku) {
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
const config = yield api.configVars(heroku, coupling.pipeline.id)
|
||||
const pipeline = yield Utils.getPipeline(context, heroku)
|
||||
const config = yield api.configVars(heroku, pipeline.id)
|
||||
|
||||
if (context.flags.shell) {
|
||||
Object.keys(config).forEach((key) => {
|
||||
|
@ -14,7 +15,7 @@ function* run (context, heroku) {
|
|||
} else if (context.flags.json) {
|
||||
cli.styledJSON(config)
|
||||
} else {
|
||||
cli.styledHeader(`${coupling.pipeline.name} test config vars`)
|
||||
cli.styledHeader(`${pipeline.name} test config vars`)
|
||||
cli.styledObject(Object.keys(config).reduce((memo, key) => {
|
||||
memo[cli.color.green(key)] = config[key]
|
||||
return memo
|
||||
|
@ -25,12 +26,25 @@ function* run (context, heroku) {
|
|||
module.exports = {
|
||||
topic: 'ci',
|
||||
command: 'config',
|
||||
needsApp: true,
|
||||
wantsApp: true,
|
||||
needsAuth: true,
|
||||
description: 'display CI config vars',
|
||||
flags: [
|
||||
{name: 'shell', char: 's', description: 'output config vars in shell format'},
|
||||
{name: 'json', description: 'output config vars in json format'}
|
||||
{
|
||||
name: 'shell',
|
||||
char: 's',
|
||||
description: 'output config vars in shell format'
|
||||
},
|
||||
{
|
||||
name: 'json',
|
||||
description: 'output config vars in json format'
|
||||
},
|
||||
{
|
||||
name: 'pipeline',
|
||||
char: 'p',
|
||||
hasValue: true,
|
||||
description: 'pipeline'
|
||||
}
|
||||
],
|
||||
run: cli.command(co.wrap(run))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const cli = require('heroku-cli-util')
|
||||
const co = require('co')
|
||||
const api = require('../../lib/heroku-api')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
function validateArgs (args) {
|
||||
if (args.length === 0) {
|
||||
|
@ -26,11 +27,11 @@ function* run (context, heroku) {
|
|||
return memo
|
||||
}, {})
|
||||
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
const pipeline = yield Utils.getPipeline(context, heroku)
|
||||
|
||||
yield cli.action(
|
||||
`Setting ${Object.keys(vars).join(', ')}`,
|
||||
api.setConfigVars(heroku, coupling.pipeline.id, vars)
|
||||
api.setConfigVars(heroku, pipeline.id, vars)
|
||||
)
|
||||
|
||||
cli.styledObject(Object.keys(vars).reduce((memo, key) => {
|
||||
|
@ -42,10 +43,18 @@ function* run (context, heroku) {
|
|||
module.exports = {
|
||||
topic: 'ci',
|
||||
command: 'config:set',
|
||||
needsApp: true,
|
||||
wantsApp: true,
|
||||
needsAuth: true,
|
||||
variableArgs: true,
|
||||
description: 'set CI config vars',
|
||||
flags: [
|
||||
{
|
||||
name: 'pipeline',
|
||||
char: 'p',
|
||||
hasValue: true,
|
||||
description: 'pipeline'
|
||||
}
|
||||
],
|
||||
help: `Examples:
|
||||
$ heroku ci:config:set RAILS_ENV=test
|
||||
Setting test config vars... done
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const cli = require('heroku-cli-util')
|
||||
const co = require('co')
|
||||
const api = require('../../lib/heroku-api')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
function validateArgs (args) {
|
||||
if (args.length === 0) {
|
||||
|
@ -16,21 +17,29 @@ function* run (context, heroku) {
|
|||
return memo
|
||||
}, {})
|
||||
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
const pipeline = yield Utils.getPipeline(context, heroku)
|
||||
|
||||
yield cli.action(
|
||||
`Unsetting ${Object.keys(vars).join(', ')}`,
|
||||
api.setConfigVars(heroku, coupling.pipeline.id, vars)
|
||||
api.setConfigVars(heroku, pipeline.id, vars)
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
topic: 'ci',
|
||||
command: 'config:unset',
|
||||
needsApp: true,
|
||||
wantsApp: true,
|
||||
needsAuth: true,
|
||||
variableArgs: true,
|
||||
description: 'unset CI config vars',
|
||||
flags: [
|
||||
{
|
||||
name: 'pipeline',
|
||||
char: 'p',
|
||||
hasValue: true,
|
||||
description: 'pipeline'
|
||||
}
|
||||
],
|
||||
help: `Examples:
|
||||
$ heroku ci:config:uset RAILS_ENV
|
||||
Unsetting RAILS_ENV... done
|
||||
|
|
|
@ -5,14 +5,15 @@ const api = require('../../lib/heroku-api')
|
|||
const git = require('../../lib/git')
|
||||
const source = require('../../lib/source')
|
||||
const TestRun = require('../../lib/test-run')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
// Default command. Run setup, source profile.d scripts and open a bash session
|
||||
const SETUP_COMMAND = 'ci setup && eval $(ci env)'
|
||||
const COMMAND = `${SETUP_COMMAND} && bash`
|
||||
|
||||
function* run (context, heroku) {
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
const pipeline = coupling.pipeline
|
||||
const pipeline = Utils.getPipeline(context, heroku)
|
||||
|
||||
const pipelineRepository = yield api.pipelineRepository(heroku, pipeline.id)
|
||||
const organization = pipelineRepository.organization &&
|
||||
pipelineRepository.organization.name
|
||||
|
@ -83,7 +84,7 @@ function* run (context, heroku) {
|
|||
module.exports = {
|
||||
topic: 'ci',
|
||||
command: 'debug',
|
||||
needsApp: true,
|
||||
wantsApp: true,
|
||||
needsAuth: true,
|
||||
description: 'opens an interactive test debugging session with the contents of the current directory',
|
||||
help: `$ heroku ci:debug
|
||||
|
@ -104,6 +105,12 @@ Running setup and attaching to test dyno...
|
|||
char: 's',
|
||||
hasValue: true,
|
||||
description: 'dyno size'
|
||||
},
|
||||
{
|
||||
name: 'pipeline',
|
||||
char: 'p',
|
||||
hasValue: true,
|
||||
description: 'pipeline'
|
||||
}
|
||||
],
|
||||
run: cli.command(co.wrap(run))
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
const cli = require('heroku-cli-util')
|
||||
const co = require('co')
|
||||
const api = require('../../lib/heroku-api')
|
||||
const RenderTestRuns = require('../../lib/render-test-runs')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
function* run (context, heroku) {
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
|
||||
return yield RenderTestRuns.render(coupling.pipeline, { heroku, watch: context.flags.watch })
|
||||
const pipeline = yield Utils.getPipeline(context, heroku)
|
||||
return yield RenderTestRuns.render(pipeline, { heroku, watch: context.flags.watch })
|
||||
}
|
||||
|
||||
const cmd = {
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
const cli = require('heroku-cli-util')
|
||||
const co = require('co')
|
||||
const api = require('../../lib/heroku-api')
|
||||
const TestRun = require('../../lib/test-run')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
function* run (context, heroku) {
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
return yield TestRun.displayAndExit(coupling.pipeline, context.args.number, { heroku })
|
||||
const pipeline = yield Utils.getPipeline(context, heroku)
|
||||
return yield TestRun.displayAndExit(pipeline, context.args.number, { heroku })
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
topic: 'ci',
|
||||
command: 'info',
|
||||
needsApp: true,
|
||||
wantsApp: true,
|
||||
needsAuth: true,
|
||||
args: [
|
||||
{
|
||||
|
@ -19,6 +19,14 @@ module.exports = {
|
|||
description: 'the test run number to show'
|
||||
}
|
||||
],
|
||||
flags: [
|
||||
{
|
||||
name: 'pipeline',
|
||||
char: 'p',
|
||||
hasValue: true,
|
||||
description: 'pipeline'
|
||||
}
|
||||
],
|
||||
description: 'test run information',
|
||||
help: 'show the status of a specific test run',
|
||||
run: cli.command(co.wrap(run))
|
||||
|
|
|
@ -2,12 +2,11 @@ const cli = require('heroku-cli-util')
|
|||
const co = require('co')
|
||||
const api = require('../../lib/heroku-api')
|
||||
const TestRun = require('../../lib/test-run')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
function* run (context, heroku) {
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
const pipeline = coupling.pipeline
|
||||
const pipelineID = pipeline.id
|
||||
const lastRun = yield api.latestTestRun(heroku, pipelineID)
|
||||
const pipeline = yield Utils.getPipeline(context, heroku)
|
||||
const lastRun = yield api.latestTestRun(heroku, pipeline.id)
|
||||
|
||||
if (!lastRun) {
|
||||
return cli.error('No Heroku CI runs found for this pipeline.')
|
||||
|
@ -19,9 +18,17 @@ function* run (context, heroku) {
|
|||
module.exports = {
|
||||
topic: 'ci',
|
||||
command: 'last',
|
||||
needsApp: true,
|
||||
wantsApp: true,
|
||||
needsAuth: true,
|
||||
description: 'get the results of the last run',
|
||||
flags: [
|
||||
{
|
||||
name: 'pipeline',
|
||||
char: 'p',
|
||||
hasValue: true,
|
||||
description: 'pipeline'
|
||||
}
|
||||
],
|
||||
help: 'looks for the most recent run and returns the output of that run',
|
||||
run: cli.command(co.wrap(run))
|
||||
}
|
||||
|
|
|
@ -1,20 +1,26 @@
|
|||
const cli = require('heroku-cli-util')
|
||||
const co = require('co')
|
||||
const api = require('../../lib/heroku-api')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
function* run (context, heroku) {
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
const couplingPipelineID = coupling.pipeline.id
|
||||
|
||||
yield cli.open(`https://dashboard.heroku.com/pipelines/${couplingPipelineID}/tests`)
|
||||
const pipeline = yield Utils.getPipeline(context, heroku)
|
||||
yield cli.open(`https://dashboard.heroku.com/pipelines/${pipeline.id}/tests`)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
topic: 'ci',
|
||||
command: 'open',
|
||||
needsApp: true,
|
||||
wantsApp: true,
|
||||
needsAuth: true,
|
||||
description: 'open the Dashboard version of Heroku CI',
|
||||
flags: [
|
||||
{
|
||||
name: 'pipeline',
|
||||
char: 'p',
|
||||
hasValue: true,
|
||||
description: 'pipeline'
|
||||
}
|
||||
],
|
||||
help: 'opens a browser to view the Dashboard version of Heroku CI',
|
||||
run: cli.command(co.wrap(run))
|
||||
}
|
||||
|
|
|
@ -4,11 +4,10 @@ const co = require('co')
|
|||
const api = require('../../lib/heroku-api')
|
||||
const source = require('../../lib/source')
|
||||
const TestRun = require('../../lib/test-run')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
function* run (context, heroku) {
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
const pipeline = coupling.pipeline
|
||||
|
||||
const pipeline = yield Utils.getPipeline(context, heroku)
|
||||
let sourceTestRun
|
||||
|
||||
if (context.args.number) {
|
||||
|
@ -47,10 +46,18 @@ function* run (context, heroku) {
|
|||
module.exports = {
|
||||
topic: 'ci',
|
||||
command: 'rerun',
|
||||
needsApp: true,
|
||||
wantsApp: true,
|
||||
needsAuth: true,
|
||||
description: 'rerun tests against current directory',
|
||||
help: 'uploads the contents of the current directory, using git archive, to Heroku and runs the tests',
|
||||
args: [{ name: 'number', optional: true }],
|
||||
flags: [
|
||||
{
|
||||
name: 'pipeline',
|
||||
char: 'p',
|
||||
hasValue: true,
|
||||
description: 'pipeline'
|
||||
}
|
||||
],
|
||||
run: cli.command(co.wrap(run))
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ const api = require('../../lib/heroku-api')
|
|||
const git = require('../../lib/git')
|
||||
const source = require('../../lib/source')
|
||||
const TestRun = require('../../lib/test-run')
|
||||
const Utils = require('../../lib/utils')
|
||||
|
||||
function* run (context, heroku) {
|
||||
const coupling = yield api.pipelineCoupling(heroku, context.app)
|
||||
const pipeline = coupling.pipeline
|
||||
const pipeline = yield Utils.getPipeline(context, heroku)
|
||||
|
||||
const commit = yield git.readCommit('HEAD')
|
||||
const sourceBlobUrl = yield cli.action('Preparing source', co(function* () {
|
||||
|
@ -35,9 +35,17 @@ function* run (context, heroku) {
|
|||
module.exports = {
|
||||
topic: 'ci',
|
||||
command: 'run',
|
||||
needsApp: true,
|
||||
wantsApp: true,
|
||||
needsAuth: true,
|
||||
description: 'run tests against current directory',
|
||||
flags: [
|
||||
{
|
||||
name: 'pipeline',
|
||||
char: 'p',
|
||||
hasValue: true,
|
||||
description: 'pipeline'
|
||||
}
|
||||
],
|
||||
help: 'uploads the contents of the current directory to Heroku and runs the tests',
|
||||
run: cli.command(co.wrap(run))
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
const api = require('./heroku-api')
|
||||
const cli = require('heroku-cli-util')
|
||||
const disambiguatePipeline = require('heroku-pipelines').disambiguatePipeline
|
||||
|
||||
function * getPipeline (context, client) {
|
||||
let pipeline = context.flags.pipeline
|
||||
|
||||
let pipelineOrApp = pipeline || context.app
|
||||
if (!pipelineOrApp) cli.exit(1, 'Required flag: --pipeline PIPELINE or --app APP')
|
||||
|
||||
if (pipeline) {
|
||||
pipeline = yield disambiguatePipeline(client, pipeline)
|
||||
} else {
|
||||
const coupling = yield api.pipelineCoupling(client, context.app)
|
||||
pipeline = coupling.pipeline
|
||||
}
|
||||
|
||||
return pipeline
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getPipeline
|
||||
}
|
|
@ -41,7 +41,8 @@
|
|||
"co-wait": "0.0.0",
|
||||
"github-url-to-object": "^2.2.6",
|
||||
"got": "^6.6.3",
|
||||
"heroku-cli-util": "^6.0.15",
|
||||
"heroku-cli-util": "^6.1.17",
|
||||
"heroku-pipelines": "^2.0.1",
|
||||
"heroku-run": "^3.4.3",
|
||||
"lodash.flatten": "^4.4.0",
|
||||
"shell-escape": "^0.2.0",
|
||||
|
|
|
@ -4,32 +4,26 @@ const nock = require('nock')
|
|||
const expect = require('chai').expect
|
||||
const cli = require('heroku-cli-util')
|
||||
const cmd = require('../../../commands/ci/config-get')
|
||||
const Factory = require('../../lib/factory')
|
||||
|
||||
describe('heroku ci:config:get', function () {
|
||||
let app, coupling, key, value
|
||||
let key, pipeline, value
|
||||
|
||||
beforeEach(function () {
|
||||
cli.mockConsole()
|
||||
app = '123-app'
|
||||
key = 'FOO'
|
||||
value = 'bar'
|
||||
|
||||
coupling = {
|
||||
pipeline: {
|
||||
id: '123-abc',
|
||||
name: 'test-pipeline'
|
||||
}
|
||||
}
|
||||
pipeline = Factory.pipeline
|
||||
})
|
||||
|
||||
it('displays the config value', function* () {
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/stage/test/config-vars`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
.get(`/pipelines/${pipeline.id}/stage/test/config-vars`)
|
||||
.reply(200, { [key]: value })
|
||||
|
||||
yield cmd.run({ app, args: { key }, flags: {} })
|
||||
yield cmd.run({ args: { key }, flags: { pipeline: pipeline.id } })
|
||||
|
||||
expect(cli.stdout).to.equal(`${value}\n`)
|
||||
api.done()
|
||||
|
@ -37,12 +31,12 @@ describe('heroku ci:config:get', function () {
|
|||
|
||||
it('displays config formatted for shell', function* () {
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/stage/test/config-vars`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
.get(`/pipelines/${pipeline.id}/stage/test/config-vars`)
|
||||
.reply(200, { [key]: value })
|
||||
|
||||
yield cmd.run({ app, args: { key }, flags: { shell: true } })
|
||||
yield cmd.run({ args: { key }, flags: { shell: true, pipeline: pipeline.id } })
|
||||
|
||||
expect(cli.stdout).to.equal(`${key}=${value}\n`)
|
||||
api.done()
|
||||
|
|
|
@ -4,32 +4,26 @@ const nock = require('nock')
|
|||
const expect = require('chai').expect
|
||||
const cli = require('heroku-cli-util')
|
||||
const cmd = require('../../../commands/ci/config-index')
|
||||
const Factory = require('../../lib/factory')
|
||||
|
||||
describe('heroku ci:config', function () {
|
||||
let app, coupling, key, value
|
||||
let key, pipeline, value
|
||||
|
||||
beforeEach(function () {
|
||||
cli.mockConsole()
|
||||
app = '123-app'
|
||||
key = 'FOO'
|
||||
value = 'bar'
|
||||
|
||||
coupling = {
|
||||
pipeline: {
|
||||
id: '123-abc',
|
||||
name: 'test-pipeline'
|
||||
}
|
||||
}
|
||||
pipeline = Factory.pipeline
|
||||
})
|
||||
|
||||
it('displays config', function* () {
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/stage/test/config-vars`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
.get(`/pipelines/${pipeline.id}/stage/test/config-vars`)
|
||||
.reply(200, { [key]: value })
|
||||
|
||||
yield cmd.run({ app, flags: {} })
|
||||
yield cmd.run({ flags: { pipeline: pipeline.id } })
|
||||
|
||||
expect(cli.stdout).to.include(`${key}: ${value}`)
|
||||
api.done()
|
||||
|
@ -37,12 +31,12 @@ describe('heroku ci:config', function () {
|
|||
|
||||
it('displays config formatted for shell', function* () {
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/stage/test/config-vars`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
.get(`/pipelines/${pipeline.id}/stage/test/config-vars`)
|
||||
.reply(200, { [key]: value })
|
||||
|
||||
yield cmd.run({ app, flags: { shell: true } })
|
||||
yield cmd.run({ flags: { shell: true, pipeline: pipeline.id } })
|
||||
|
||||
expect(cli.stdout).to.include(`${key}=${value}`)
|
||||
api.done()
|
||||
|
@ -50,12 +44,12 @@ describe('heroku ci:config', function () {
|
|||
|
||||
it('displays config formatted as JSON', function* () {
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/stage/test/config-vars`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
.get(`/pipelines/${pipeline.id}/stage/test/config-vars`)
|
||||
.reply(200, { [key]: value })
|
||||
|
||||
yield cmd.run({ app, flags: { json: true } })
|
||||
yield cmd.run({ flags: { json: true, pipeline: pipeline.id } })
|
||||
|
||||
expect(cli.stdout).to.include('{\n "FOO": "bar"\n}')
|
||||
api.done()
|
||||
|
|
|
@ -4,32 +4,26 @@ const nock = require('nock')
|
|||
const expect = require('chai').expect
|
||||
const cli = require('heroku-cli-util')
|
||||
const cmd = require('../../../commands/ci/config-set')
|
||||
const Factory = require('../../lib/factory')
|
||||
|
||||
describe('heroku ci:config:set', function () {
|
||||
let app, coupling, key, value
|
||||
let key, pipeline, value
|
||||
|
||||
beforeEach(function () {
|
||||
cli.mockConsole()
|
||||
app = '123-app'
|
||||
key = 'FOO'
|
||||
value = 'bar'
|
||||
|
||||
coupling = {
|
||||
pipeline: {
|
||||
id: '123-abc',
|
||||
name: 'test-pipeline'
|
||||
}
|
||||
}
|
||||
pipeline = Factory.pipeline
|
||||
})
|
||||
|
||||
it('sets new config', function* () {
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.patch(`/pipelines/${coupling.pipeline.id}/stage/test/config-vars`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
.patch(`/pipelines/${pipeline.id}/stage/test/config-vars`)
|
||||
.reply(200, { [key]: value })
|
||||
|
||||
yield cmd.run({ app, args: [ `${key}=${value}` ] })
|
||||
yield cmd.run({ args: [ `${key}=${value}` ], flags: { pipeline: pipeline.id } })
|
||||
|
||||
expect(cli.stdout).to.include(key)
|
||||
expect(cli.stdout).to.include(value)
|
||||
|
|
|
@ -3,32 +3,25 @@
|
|||
const nock = require('nock')
|
||||
const cli = require('heroku-cli-util')
|
||||
const cmd = require('../../../commands/ci/config-unset')
|
||||
const Factory = require('../../lib/factory')
|
||||
|
||||
describe('heroku ci:config:unset', function () {
|
||||
let app, coupling, key
|
||||
let pipeline, key
|
||||
|
||||
beforeEach(function () {
|
||||
cli.mockConsole()
|
||||
app = '123-app'
|
||||
key = 'FOO'
|
||||
|
||||
coupling = {
|
||||
pipeline: {
|
||||
id: '123-abc',
|
||||
name: 'test-pipeline'
|
||||
}
|
||||
}
|
||||
pipeline = Factory.pipeline
|
||||
})
|
||||
|
||||
it('unsets config', function* () {
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.patch(`/pipelines/${coupling.pipeline.id}/stage/test/config-vars`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
.patch(`/pipelines/${pipeline.id}/stage/test/config-vars`)
|
||||
.reply(200, { [key]: null })
|
||||
|
||||
yield cmd.run({ app, args: [ key ] })
|
||||
|
||||
yield cmd.run({ args: [ key ], flags: { pipeline: pipeline.id } })
|
||||
api.done()
|
||||
})
|
||||
})
|
||||
|
|
|
@ -5,38 +5,34 @@ const expect = require('chai').expect
|
|||
const cli = require('heroku-cli-util')
|
||||
const cmd = require('../../../commands/ci')[0]
|
||||
const stdMocks = require('std-mocks')
|
||||
const Factory = require('../../lib/factory')
|
||||
|
||||
describe('heroku ci', function () {
|
||||
let app, coupling, runs
|
||||
let pipeline, runs
|
||||
|
||||
beforeEach(function () {
|
||||
cli.mockConsole()
|
||||
app = '123-app'
|
||||
|
||||
coupling = {
|
||||
pipeline: {
|
||||
id: '123-abc',
|
||||
name: 'test-pipeline'
|
||||
}
|
||||
}
|
||||
runs = [{
|
||||
number: 123,
|
||||
commit_branch: 'foo',
|
||||
commit_sha: '1234567',
|
||||
status: 'running'
|
||||
}]
|
||||
|
||||
pipeline = Factory.pipeline
|
||||
})
|
||||
|
||||
it('displays recent runs', function* () {
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/test-runs`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
.get(`/pipelines/${pipeline.id}/test-runs`)
|
||||
.reply(200, runs)
|
||||
|
||||
stdMocks.use()
|
||||
|
||||
yield cmd.run({ app, flags: {} })
|
||||
yield cmd.run({ flags: { pipeline: pipeline.id } })
|
||||
|
||||
stdMocks.restore()
|
||||
const { stdout } = stdMocks.flush()
|
||||
|
|
|
@ -5,27 +5,23 @@ const expect = require('chai').expect
|
|||
const cli = require('heroku-cli-util')
|
||||
const sinon = require('sinon')
|
||||
const cmd = require('../../../commands/ci/last')
|
||||
const Factory = require('../../lib/factory')
|
||||
|
||||
describe('heroku ci:last', function () {
|
||||
let app, coupling, testRun, testNode, setupOutput, testOutput
|
||||
let testRun, testNode, setupOutput, pipeline, testOutput
|
||||
|
||||
beforeEach(function () {
|
||||
cli.mockConsole()
|
||||
sinon.stub(process, 'exit')
|
||||
|
||||
app = '123-app'
|
||||
|
||||
coupling = {
|
||||
pipeline: {
|
||||
id: '123-abc',
|
||||
name: '123-abc'
|
||||
}
|
||||
}
|
||||
setupOutput = ''
|
||||
testOutput = ''
|
||||
pipeline = Factory.pipeline
|
||||
|
||||
testRun = {
|
||||
id: '123-abc',
|
||||
number: 123,
|
||||
pipeline: coupling.pipeline,
|
||||
pipeline: pipeline,
|
||||
status: 'succeeded',
|
||||
commit_sha: '123abc456def',
|
||||
commit_branch: 'master'
|
||||
|
@ -37,22 +33,19 @@ describe('heroku ci:last', function () {
|
|||
test_run: { id: testRun.id },
|
||||
exit_code: 1
|
||||
}
|
||||
|
||||
setupOutput = ''
|
||||
testOutput = ''
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
process.exit.restore()
|
||||
})
|
||||
|
||||
it('when pipeline has runs, displays the results of the latest run', function* () {
|
||||
it('with runs, displays the results of the latest run', function* () {
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/test-runs`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
.get(`/pipelines/${pipeline.id}/test-runs`)
|
||||
.reply(200, [testRun])
|
||||
.get(`/pipelines/${coupling.pipeline.id}/test-runs/${testRun.number}`)
|
||||
.get(`/pipelines/${pipeline.id}/test-runs/${testRun.number}`)
|
||||
.reply(200, testRun)
|
||||
.get(`/test-runs/${testRun.id}/test-nodes`)
|
||||
.reply(200, [testNode])
|
||||
|
@ -65,21 +58,21 @@ describe('heroku ci:last', function () {
|
|||
.get('/tests')
|
||||
.reply(200, testOutput)
|
||||
|
||||
yield cmd.run({ app })
|
||||
yield cmd.run({ flags: { pipeline: pipeline.id } })
|
||||
expect(cli.stdout).to.contain(`✓ #${testRun.number}`)
|
||||
|
||||
api.done()
|
||||
streamAPI.done()
|
||||
})
|
||||
|
||||
it('when pipeline does not have any runs, reports that there are no runs', function* () {
|
||||
it('without any runs, reports that there are no runs', function* () {
|
||||
let api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/test-runs`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
.get(`/pipelines/${pipeline.id}/test-runs`)
|
||||
.reply(200, [])
|
||||
|
||||
yield cmd.run({ app })
|
||||
yield cmd.run({ flags: { pipeline: pipeline.id } })
|
||||
expect(cli.stderr).to.contain('No Heroku CI runs found')
|
||||
api.done()
|
||||
})
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
const Factory = {
|
||||
pipeline: {
|
||||
id: '123e4567-e89b-12d3-a456-426655440000',
|
||||
name: 'test-pipeline'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Factory
|
|
@ -0,0 +1,40 @@
|
|||
/* eslint-env mocha */
|
||||
|
||||
const nock = require('nock')
|
||||
const expect = require('chai').expect
|
||||
const Heroku = require('heroku-client')
|
||||
const Utils = require('../../lib/utils')
|
||||
const Factory = require('./factory')
|
||||
|
||||
describe('Utils', function () {
|
||||
afterEach(() => nock.cleanAll())
|
||||
|
||||
describe('#getPipeline', function () {
|
||||
it('disambiguates when passing a pipeline', function* () {
|
||||
const pipeline = Factory.pipeline
|
||||
const context = { flags: { pipeline: pipeline.id } }
|
||||
const api = nock(`https://api.heroku.com`)
|
||||
.get(`/pipelines/${pipeline.id}`)
|
||||
.reply(200, pipeline)
|
||||
|
||||
const response = yield Utils.getPipeline(context, new Heroku())
|
||||
expect(response).to.deep.eq(Factory.pipeline)
|
||||
api.done()
|
||||
})
|
||||
|
||||
it('uses pipeline-couplings when passing an application', function* () {
|
||||
const app = '123-app'
|
||||
|
||||
const coupling = { pipeline: Factory.pipeline }
|
||||
const context = { app, flags: {} }
|
||||
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
|
||||
const response = yield Utils.getPipeline(context, new Heroku())
|
||||
expect(response).to.deep.eq(Factory.pipeline)
|
||||
api.done()
|
||||
})
|
||||
})
|
||||
})
|
Загрузка…
Ссылка в новой задаче