UNPKG

1.56 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')
7const Utils = require('../../lib/utils')
8
9function* run (context, heroku) {
10 const pipeline = yield Utils.getPipeline(context, heroku)
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 wantsApp: true,
39 needsAuth: true,
40 description: 'run tests against current directory',
41 flags: [
42 {
43 name: 'pipeline',
44 char: 'p',
45 hasValue: true,
46 description: 'pipeline'
47 }
48 ],
49 help: 'uploads the contents of the current directory to Heroku and runs the tests',
50 run: cli.command(co.wrap(run))
51}