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