Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ncu-ci: replace --markdown with --copy
  • Loading branch information
joyeecheung committed Jun 1, 2018
commit ee5b43bd3719b39121e174ab0aa27aa0dead4f73
27 changes: 15 additions & 12 deletions bin/ncu-ci
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const {
PRBuild, BenchmarkRun, CommitBuild, jobCache, parseJobFromURL, constants
} = require('../lib/ci');
const clipboardy = require('clipboardy');

const {
PR, COMMIT, BENCHMARK
Expand Down Expand Up @@ -70,17 +71,16 @@ const argv = yargs
handler
})
.demandCommand(1, 'must provide a valid command')
.option('markdown', {
alias: 'm',
type: 'string',
describe: 'file to write results in markdown'
.option('copy', {
default: false,
describe: 'Write the results as markdown to clipboard'
})
.help()
.argv;

async function getResults(cli, request, job) {
let build;
const { type, jobid, markdown } = job;
const { type, jobid } = job;
if (type === PR) {
build = new PRBuild(cli, request, jobid);
await build.getResults();
Expand All @@ -94,12 +94,6 @@ async function getResults(cli, request, job) {
yargs.showHelp();
return;
}

build.display();

if (markdown) {
build.appendToMarkdown(markdown);
}
return build;
}

Expand Down Expand Up @@ -135,7 +129,16 @@ async function main(command, argv) {
}

for (let job of queue) {
await getResults(cli, request, job);
const build = await getResults(cli, request, job);
build.display();

if (argv.copy) {
clipboardy.writeSync(build.formatAsMarkdown());
}

cli.separator('');
cli.log(`Written markdown to clipboard`);
return build;
}
}

Expand Down
24 changes: 9 additions & 15 deletions lib/ci.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const Cache = require('./cache');
const { appendFile } = require('./file');

const qs = require('querystring');
const chalk = require('chalk');
Expand Down Expand Up @@ -402,9 +401,9 @@ class CommitBuild extends Job {
}
}

appendToMarkdown(file) {
const { failures, cli } = this;
let output = this.jobUrl + '\n\n';
formatAsMarkdown() {
const { failures } = this;
let output = `Failures in job ${this.jobUrl} \n\n`;
for (const failure of failures) {
output += `#### [${getNodeName(failure.url)}](${failure.url})`;
if (!failure.reason.includes('\n') && failure.reason.length < 20) {
Expand All @@ -414,9 +413,7 @@ class CommitBuild extends Job {
output += fold('See failures', failure.reason) + '\n\n';
}
}
appendFile(file, output);
cli.separator('', SEP_LENGTH);
cli.log(`Written markdown to ${file}`);
return output;
}
}

Expand Down Expand Up @@ -452,8 +449,8 @@ class PRBuild extends Job {
this.commitBuild.display();
}

appendToMarkdown(file) {
this.commitBuild.appendToMarkdown(file);
formatAsMarkdown() {
return this.commitBuild.formatAsMarkdown();
}
}

Expand Down Expand Up @@ -722,14 +719,11 @@ class BenchmarkRun extends Job {
cli.log(significantResults);
}

appendToMarkdown(file) {
const { cli, results, significantResults } = this;
formatAsMarkdown() {
const { results, significantResults } = this;
const output = (fold('Benchmark results', results) + '\n\n' +
fold('Significant impact', significantResults) + '\n');

appendFile(file, output);
cli.separator('', SEP_LENGTH);
cli.log(`Written markdown to ${file}`);
return output;
}
}

Expand Down
40 changes: 40 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"dependencies": {
"chalk": "^2.3.1",
"cheerio": "^1.0.0-rc.2",
"clipboardy": "^1.2.3",
"core-validate-commit": "^3.5.0",
"execa": "^0.10.0",
"figures": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/jenkins/normal-failure/expected.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
https://ci.nodejs.org/job/node-test-commit/17507/
Failures in job https://ci.nodejs.org/job/node-test-commit/17507/

#### [ppcle-ubuntu1404](https://ci.nodejs.org/job/node-test-commit-plinux/nodes=ppcle-ubuntu1404/16673/console)

Expand Down
19 changes: 5 additions & 14 deletions test/unit/ci.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ describe('Jenkins', () => {
);
assert.deepStrictEqual(prBuild.commitBuild.failures, expectedJson);

const actualPath = path.join(tmpdir.path, 'actual.md');
const expectedPath = path.join(fixturesDir, 'expected.md');

commitBuild.appendToMarkdown(actualPath);
const markdown = commitBuild.formatAsMarkdown();
const expected = fs.readFileSync(expectedPath, 'utf8');
const actual = fs.readFileSync(actualPath, 'utf8');
assert.strictEqual(actual, expected);
assert.strictEqual(markdown, expected);
});

it('should get benchmark run', async() => {
Expand All @@ -112,17 +110,10 @@ describe('Jenkins', () => {
const run = new BenchmarkRun(cli, request, 150);
await run.getResults();

const actualPath = path.join(tmpdir.path, 'actual.md');
const expectedPath = path.join(fixturesDir, 'expected.md');

run.appendToMarkdown(actualPath);
let expected = fs.readFileSync(expectedPath, 'utf8');
let actual = fs.readFileSync(actualPath, 'utf8');
assert.strictEqual(actual, expected);

run.appendToMarkdown(actualPath);
expected += expected;
actual = fs.readFileSync(actualPath, 'utf8');
assert.strictEqual(actual, expected);
const markdown = run.formatAsMarkdown();
const expected = fs.readFileSync(expectedPath, 'utf8');
assert.strictEqual(markdown, expected);
});
});