Skip to content

Commit 873b22e

Browse files
joyeecheungpriyank-p
authored andcommitted
ncu-ci: add --markdown option
1 parent fc5520d commit 873b22e

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

bin/ncu-ci

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const {
1515
listBuilds, FailureAggregator, jobCache
1616
} = require('../lib/ci/ci_result_parser');
1717
const clipboardy = require('clipboardy');
18-
const { writeJson } = require('../lib/file');
18+
const { writeJson, writeFile } = require('../lib/file');
1919

2020
const { runPromise } = require('../lib/run');
2121
const auth = require('../lib/auth');
@@ -119,6 +119,10 @@ const argv = yargs
119119
type: 'string',
120120
describe: 'Write the results as json to the path'
121121
})
122+
.option('markdown', {
123+
type: 'string',
124+
describe: 'Write the results as markdown to the path'
125+
})
122126
.help()
123127
.argv;
124128

@@ -142,8 +146,8 @@ async function getResults(cli, request, job) {
142146
}
143147

144148
async function runQueue(queue, cli, request, argv) {
145-
let dataToCopy = '';
146-
let dataToJson = [];
149+
let json = [];
150+
let markdown = '';
147151

148152
for (let i = 0; i < queue.length; ++i) {
149153
const job = queue[i];
@@ -158,16 +162,15 @@ async function runQueue(queue, cli, request, argv) {
158162
const build = await getResults(cli, request, job);
159163
build.display();
160164

161-
if (argv.copy) {
162-
dataToCopy += build.formatAsMarkdown();
165+
json = json.concat(build.formatAsJson());
166+
if ((argv.copy || argv.markdown) && !argv.stats) {
167+
markdown += build.formatAsMarkdown();
163168
}
164-
165-
dataToJson = dataToJson.concat(build.formatAsJson());
166169
}
167170

168171
return {
169-
json: dataToJson,
170-
copy: dataToCopy
172+
json,
173+
markdown
171174
};
172175
}
173176

@@ -262,17 +265,24 @@ async function main(command, argv) {
262265
cli.separator('Stats');
263266
cli.log('');
264267
aggregator.display();
265-
if (argv.copy) {
266-
data.copy = aggregator.formatAsMarkdown();
268+
269+
if (argv.markdown || argv.copy) {
270+
data.markdown = aggregator.formatAsMarkdown();
267271
}
268272
}
269273

270274
if (argv.copy) {
271-
clipboardy.writeSync(data.copy);
275+
clipboardy.writeSync(data.markdown);
272276
cli.separator('');
273277
cli.log(`Written markdown to clipboard`);
274278
}
275279

280+
if (argv.markdown) {
281+
writeFile(argv.markdown, data.markdown);
282+
cli.separator('');
283+
cli.log(`Written markdown to ${argv.markdown}`);
284+
}
285+
276286
if (argv.json) {
277287
writeJson(argv.json, data.json);
278288
cli.separator('');

docs/ncu-ci.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ ncu-ci <command>
1515
Commands:
1616
ncu-ci rate <type> Calculate the green rate of a CI job in the last 100
1717
runs
18-
ncu-ci walk <type> Walk the CI and store the failures
18+
ncu-ci walk <type> Walk the CI and display the failures
1919
ncu-ci url <url> Automatically detect CI type and show results
2020
ncu-ci pr <jobid> Show results of a node-test-pull-request CI job
2121
ncu-ci commit <jobid> Show results of a node-test-commit CI job
2222
ncu-ci benchmark <jobid> Show results of a benchmark-node-micro-benchmarks CI
2323
job
2424
2525
Options:
26-
--version Show version number [boolean]
27-
--copy Write the results as markdown to clipboard [default: false]
28-
--json Write the results as json to the path [string]
29-
--help Show help [boolean]
26+
--version Show version number [boolean]
27+
--copy Write the results as markdown to clipboard [default: false]
28+
--json Write the results as json to the path [string]
29+
--markdown Write the results as markdown to the path [string]
30+
--help Show help [boolean]
3031
```
3132

3233
## Example
@@ -44,6 +45,20 @@ Get the results of job #12345 of `node-test-pull-request`:
4445
ncu-ci pr 12345
4546
```
4647

48+
49+
Walk the CI for the latest 100 runs of `node-test-pull-request`,
50+
aggregate the failures, then write the results into a Markdown file,
51+
and cache the responses from Jenkins so that the next time the command
52+
is run, it picks up cached data written on disk for jobs whose results
53+
are known.
54+
55+
Note: results are cached in `${ncu_intallation_path}/.ncu/cache`, you
56+
may want to clean it up from time to time.
57+
58+
```
59+
ncu-ci walk pr --stats --cache --markdown results.md
60+
```
61+
4762
Walk the CI for the latest 100 runs of `node-test-pull-request`, write the
4863
failures into a JSON file
4964

0 commit comments

Comments
 (0)