UNPKG

1.95 kBJavaScriptView Raw
1'use strict'
2const cli = require('heroku-cli-util')
3const co = require('co')
4const api = require('../../lib/heroku-api')
5const source = require('../../lib/source')
6const TestRun = require('../../lib/test-run')
7
8function* run (context, heroku) {
9 const coupling = yield api.pipelineCoupling(heroku, context.app)
10 const pipeline = coupling.pipeline
11
12 let sourceTestRun
13
14 if (context.args.number) {
15 sourceTestRun = yield cli.action(`Fetching test run #${context.args.number}`, co(function* () {
16 return yield api.testRun(heroku, pipeline.id, context.args.number)
17 }))
18 } else {
19 sourceTestRun = yield cli.action(`Fetching latest test run`, co(function* () {
20 return yield api.latestTestRun(heroku, pipeline.id)
21 }))
22 cli.log(`Rerunning test run #${sourceTestRun.number}...`)
23 }
24
25 const sourceBlobUrl = yield cli.action('Preparing source', co(function* () {
26 return yield source.createSourceBlob(sourceTestRun.commit_sha, context, heroku)
27 }))
28
29 const pipelineRepository = yield api.pipelineRepository(heroku, pipeline.id)
30 const organization = pipelineRepository.organization &&
31 pipelineRepository.organization.name
32
33 const testRun = yield cli.action('Starting test run', co(function* () {
34 return yield api.createTestRun(heroku, {
35 commit_branch: sourceTestRun.commit_branch,
36 commit_message: sourceTestRun.commit_message,
37 commit_sha: sourceTestRun.commit_sha,
38 pipeline: pipeline.id,
39 organization,
40 source_blob_url: sourceBlobUrl
41 })
42 }))
43
44 return yield TestRun.displayAndExit(pipeline, testRun.number, { heroku })
45}
46
47module.exports = {
48 topic: 'ci',
49 command: 'rerun',
50 needsApp: true,
51 needsAuth: true,
52 description: 'rerun tests against current directory',
53 help: 'uploads the contents of the current directory, using git archive, to Heroku and runs the tests',
54 args: [{ name: 'number', optional: true }],
55 run: cli.command(co.wrap(run))
56}