1 | const cli = require('heroku-cli-util')
|
2 | const co = require('co')
|
3 | const api = require('../../lib/heroku-api')
|
4 | const git = require('../../lib/git')
|
5 | const source = require('../../lib/source')
|
6 | const TestRun = require('../../lib/test-run')
|
7 |
|
8 | function* run (context, heroku) {
|
9 | const coupling = yield api.pipelineCoupling(heroku, context.app)
|
10 | const pipeline = coupling.pipeline
|
11 |
|
12 | const commit = yield git.readCommit('HEAD')
|
13 | const sourceBlobUrl = yield cli.action('Preparing source', co(function* () {
|
14 | return yield source.createSourceBlob(commit.ref, context, heroku)
|
15 | }))
|
16 |
|
17 | const pipelineRepository = yield api.pipelineRepository(heroku, pipeline.id)
|
18 | const organization = pipelineRepository.organization &&
|
19 | pipelineRepository.organization.name
|
20 |
|
21 | const testRun = yield cli.action('Starting test run', co(function* () {
|
22 | return yield api.createTestRun(heroku, {
|
23 | commit_branch: commit.branch,
|
24 | commit_message: commit.message,
|
25 | commit_sha: commit.ref,
|
26 | pipeline: pipeline.id,
|
27 | organization,
|
28 | source_blob_url: sourceBlobUrl
|
29 | })
|
30 | }))
|
31 |
|
32 | return yield TestRun.displayAndExit(pipeline, testRun.number, { heroku })
|
33 | }
|
34 |
|
35 | module.exports = {
|
36 | topic: 'ci',
|
37 | command: 'run',
|
38 | needsApp: true,
|
39 | needsAuth: true,
|
40 | description: 'run tests against current directory',
|
41 | help: 'uploads the contents of the current directory to Heroku and runs the tests',
|
42 | run: cli.command(co.wrap(run))
|
43 | }
|