1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const command_1 = require("@heroku-cli/command");
|
4 | const cli_ux_1 = require("cli-ux");
|
5 | const pipelines_1 = require("../../utils/pipelines");
|
6 | const test_run_1 = require("../../utils/test-run");
|
7 | const source_1 = require("../../utils/source");
|
8 | class CiReRun extends command_1.Command {
|
9 | async run() {
|
10 | const { flags, args } = this.parse(CiReRun);
|
11 | const pipeline = await pipelines_1.getPipeline(flags, this);
|
12 | let sourceTestRun;
|
13 | if (args.number) {
|
14 | const testRunResponse = await this.heroku.get(`/pipelines/${pipeline.id}/test-runs/${args.number}`);
|
15 | sourceTestRun = testRunResponse.body;
|
16 | }
|
17 | else {
|
18 | const { body: testRuns } = await this.heroku.get(`/pipelines/${pipeline.id}/test-runs`, { headers: { Range: 'number ..; order=desc,max=1' } });
|
19 | sourceTestRun = testRuns[0];
|
20 | }
|
21 | this.log(`Rerunning test run #${sourceTestRun.number}...`);
|
22 | cli_ux_1.default.action.start('Preparing source');
|
23 | const sourceBlobUrl = await source_1.createSourceBlob(sourceTestRun.commit_sha, this);
|
24 | cli_ux_1.default.action.stop();
|
25 | const { body: pipelineRepository } = await this.heroku.get(`https://kolkrabbi.heroku.com/pipelines/${pipeline.id}/repository`);
|
26 | cli_ux_1.default.action.start('Starting test run');
|
27 | const organization = pipelineRepository.organization && pipelineRepository.organization.name;
|
28 | const { body: testRun } = await this.heroku.post('/test-runs', { body: {
|
29 | commit_branch: sourceTestRun.commit_branch,
|
30 | commit_message: sourceTestRun.commit_message,
|
31 | commit_sha: sourceTestRun.commit_sha,
|
32 | pipeline: pipeline.id,
|
33 | organization,
|
34 | source_blob_url: sourceBlobUrl
|
35 | }
|
36 | });
|
37 | cli_ux_1.default.action.stop();
|
38 | await test_run_1.displayAndExit(pipeline, testRun.number, this);
|
39 | }
|
40 | }
|
41 | CiReRun.description = 'rerun tests against current directory';
|
42 | CiReRun.examples = [
|
43 | `$ heroku ci:rerun 985 --app murmuring-headland-14719
|
44 | `,
|
45 | ];
|
46 | CiReRun.flags = {
|
47 | app: command_1.flags.app({ required: false }),
|
48 | pipeline: command_1.flags.pipeline({ required: false })
|
49 | };
|
50 | CiReRun.args = [{ name: 'number', required: false }];
|
51 | exports.default = CiReRun;
|