UNPKG

1.46 kBJavaScriptView Raw
1const cli = require('heroku-cli-util')
2const co = require('co')
3const api = require('../../lib/heroku-api')
4const git = require('../../lib/git')
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 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
35module.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, using git archive, to Heroku and runs the tests',
42 run: cli.command(co.wrap(run))
43}