Skip to content

Commit ee5b43b

Browse files
committed
ncu-ci: replace --markdown with --copy
1 parent 9c45921 commit ee5b43b

File tree

6 files changed

+71
-42
lines changed

6 files changed

+71
-42
lines changed

bin/ncu-ci

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const {
66
PRBuild, BenchmarkRun, CommitBuild, jobCache, parseJobFromURL, constants
77
} = require('../lib/ci');
8+
const clipboardy = require('clipboardy');
89

910
const {
1011
PR, COMMIT, BENCHMARK
@@ -70,17 +71,16 @@ const argv = yargs
7071
handler
7172
})
7273
.demandCommand(1, 'must provide a valid command')
73-
.option('markdown', {
74-
alias: 'm',
75-
type: 'string',
76-
describe: 'file to write results in markdown'
74+
.option('copy', {
75+
default: false,
76+
describe: 'Write the results as markdown to clipboard'
7777
})
7878
.help()
7979
.argv;
8080

8181
async function getResults(cli, request, job) {
8282
let build;
83-
const { type, jobid, markdown } = job;
83+
const { type, jobid } = job;
8484
if (type === PR) {
8585
build = new PRBuild(cli, request, jobid);
8686
await build.getResults();
@@ -94,12 +94,6 @@ async function getResults(cli, request, job) {
9494
yargs.showHelp();
9595
return;
9696
}
97-
98-
build.display();
99-
100-
if (markdown) {
101-
build.appendToMarkdown(markdown);
102-
}
10397
return build;
10498
}
10599

@@ -135,7 +129,16 @@ async function main(command, argv) {
135129
}
136130

137131
for (let job of queue) {
138-
await getResults(cli, request, job);
132+
const build = await getResults(cli, request, job);
133+
build.display();
134+
135+
if (argv.copy) {
136+
clipboardy.writeSync(build.formatAsMarkdown());
137+
}
138+
139+
cli.separator('');
140+
cli.log(`Written markdown to clipboard`);
141+
return build;
139142
}
140143
}
141144

lib/ci.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const Cache = require('./cache');
4-
const { appendFile } = require('./file');
54

65
const qs = require('querystring');
76
const chalk = require('chalk');
@@ -402,9 +401,9 @@ class CommitBuild extends Job {
402401
}
403402
}
404403

405-
appendToMarkdown(file) {
406-
const { failures, cli } = this;
407-
let output = this.jobUrl + '\n\n';
404+
formatAsMarkdown() {
405+
const { failures } = this;
406+
let output = `Failures in job ${this.jobUrl} \n\n`;
408407
for (const failure of failures) {
409408
output += `#### [${getNodeName(failure.url)}](${failure.url})`;
410409
if (!failure.reason.includes('\n') && failure.reason.length < 20) {
@@ -414,9 +413,7 @@ class CommitBuild extends Job {
414413
output += fold('See failures', failure.reason) + '\n\n';
415414
}
416415
}
417-
appendFile(file, output);
418-
cli.separator('', SEP_LENGTH);
419-
cli.log(`Written markdown to ${file}`);
416+
return output;
420417
}
421418
}
422419

@@ -452,8 +449,8 @@ class PRBuild extends Job {
452449
this.commitBuild.display();
453450
}
454451

455-
appendToMarkdown(file) {
456-
this.commitBuild.appendToMarkdown(file);
452+
formatAsMarkdown() {
453+
return this.commitBuild.formatAsMarkdown();
457454
}
458455
}
459456

@@ -722,14 +719,11 @@ class BenchmarkRun extends Job {
722719
cli.log(significantResults);
723720
}
724721

725-
appendToMarkdown(file) {
726-
const { cli, results, significantResults } = this;
722+
formatAsMarkdown() {
723+
const { results, significantResults } = this;
727724
const output = (fold('Benchmark results', results) + '\n\n' +
728725
fold('Significant impact', significantResults) + '\n');
729-
730-
appendFile(file, output);
731-
cli.separator('', SEP_LENGTH);
732-
cli.log(`Written markdown to ${file}`);
726+
return output;
733727
}
734728
}
735729

package-lock.json

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"dependencies": {
3434
"chalk": "^2.3.1",
3535
"cheerio": "^1.0.0-rc.2",
36+
"clipboardy": "^1.2.3",
3637
"core-validate-commit": "^3.5.0",
3738
"execa": "^0.10.0",
3839
"figures": "^2.0.0",

test/fixtures/jenkins/normal-failure/expected.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
https://ci.nodejs.org/job/node-test-commit/17507/
1+
Failures in job https://ci.nodejs.org/job/node-test-commit/17507/
22

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

test/unit/ci.test.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,11 @@ describe('Jenkins', () => {
8888
);
8989
assert.deepStrictEqual(prBuild.commitBuild.failures, expectedJson);
9090

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

94-
commitBuild.appendToMarkdown(actualPath);
93+
const markdown = commitBuild.formatAsMarkdown();
9594
const expected = fs.readFileSync(expectedPath, 'utf8');
96-
const actual = fs.readFileSync(actualPath, 'utf8');
97-
assert.strictEqual(actual, expected);
95+
assert.strictEqual(markdown, expected);
9896
});
9997

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

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

118-
run.appendToMarkdown(actualPath);
119-
let expected = fs.readFileSync(expectedPath, 'utf8');
120-
let actual = fs.readFileSync(actualPath, 'utf8');
121-
assert.strictEqual(actual, expected);
122-
123-
run.appendToMarkdown(actualPath);
124-
expected += expected;
125-
actual = fs.readFileSync(actualPath, 'utf8');
126-
assert.strictEqual(actual, expected);
115+
const markdown = run.formatAsMarkdown();
116+
const expected = fs.readFileSync(expectedPath, 'utf8');
117+
assert.strictEqual(markdown, expected);
127118
});
128119
});

0 commit comments

Comments
 (0)