diff --git a/bin/ncu-ci b/bin/ncu-ci index 74875700..3e168c03 100755 --- a/bin/ncu-ci +++ b/bin/ncu-ci @@ -11,8 +11,8 @@ const { } = require('../lib/ci/ci_type_parser'); const { - PRBuild, BenchmarkRun, CommitBuild, listBuilds, FailureAggregator - // , jobCache + PRBuild, BenchmarkRun, CommitBuild, + listBuilds, FailureAggregator, jobCache } = require('../lib/ci/ci_result_parser'); const clipboardy = require('clipboardy'); const { writeJson } = require('../lib/file'); @@ -23,10 +23,6 @@ const Request = require('../lib/request'); const CLI = require('../lib/cli'); const yargs = require('yargs'); -// This is used for testing -// Default cache dir is ${ncu-source-dir}/.ncu/cache -// jobCache.enable(); - // eslint-disable-next-line no-unused-vars const argv = yargs .command({ @@ -54,6 +50,11 @@ const argv = yargs default: false, describe: 'Aggregate the results' }) + .option('cache', { + default: false, + describe: 'Cache the responses from Jenkins in .ncu/cache/ under' + + ' the node-core-utils installation directory' + }) .option('limit', { default: 99, describe: 'Maximum number of CIs to get data from' @@ -144,12 +145,14 @@ async function runQueue(queue, cli, request, argv) { let dataToCopy = ''; let dataToJson = []; - for (let job of queue) { + for (let i = 0; i < queue.length; ++i) { + const job = queue[i]; cli.separator(''); + const progress = `[${i + 1}/${queue.length}]`; if (job.link) { - cli.log(`Running ${job.link}`); + cli.log(`${progress} Running ${job.link}`); } else { - cli.log(`Running ${job.type}: ${job.jobid}`); + cli.log(`${progress} Running ${job.type}: ${job.jobid}`); } cli.separator(''); const build = await getResults(cli, request, job); @@ -211,6 +214,9 @@ async function main(command, argv) { const type = commandToType[argv.type]; const builds = await listBuilds(cli, request, type); if (command === 'walk') { + if (argv.cache) { + jobCache.enable(); + } for (const build of builds.failed.slice(0, argv.limit)) { queue.push(build); } diff --git a/lib/ci/ci_result_parser.js b/lib/ci/ci_result_parser.js index eb25c844..4521e9d9 100644 --- a/lib/ci/ci_result_parser.js +++ b/lib/ci/ci_result_parser.js @@ -177,6 +177,7 @@ class Job { } } +// TODO(joyeecheung): do not cache pending jobs const jobCache = new Cache(); jobCache.wrap(Job, { getConsoleText() { diff --git a/lib/ci/ci_type_parser.js b/lib/ci/ci_type_parser.js index a41543c0..61161280 100644 --- a/lib/ci/ci_type_parser.js +++ b/lib/ci/ci_type_parser.js @@ -86,7 +86,7 @@ const CI_TYPES = new Map([ [LITE_PR_PIPELINE, { name: 'Lite PR Pipeline', jobName: 'node-test-pull-request-lite-pipeline', - pattern: /job\/node-test-pull-request-lite-pipeline\/(\d+)\/pipeline/, + pattern: /node-test-pull-request-lite-pipeline\/(\d+)\/pipeline/, type: LITE_CI }], [LITE_COMMIT, { @@ -120,8 +120,7 @@ function parseJobFromURL(url) { } for (let [ type, info ] of CI_TYPES) { - const re = new RegExp(`job/${info.jobName}/(\\d+)`); - const match = url.match(re); + const match = url.match(info.pattern); if (match) { return { link: url, diff --git a/test/unit/ci_type_parser.test.js b/test/unit/ci_type_parser.test.js index 495056b8..e090c921 100644 --- a/test/unit/ci_type_parser.test.js +++ b/test/unit/ci_type_parser.test.js @@ -56,10 +56,23 @@ const expected = new Map([ jobid: 7213 }] ]); - describe('JobParser', () => { it('should parse CI results', () => { const results = new JobParser(commentsWithCI).parse(); assert.deepStrictEqual([...results.entries()], [...expected.entries()]); }); + + it('should parse pipeline links', () => { + const data = [{ + 'publishedAt': '2017-10-29T04:16:36.458Z', + 'bodyText': '@contributer build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/3009/pipeline/' + }]; + const results = new JobParser(data).parse(); + assert.deepStrictEqual([...results.entries()], [ + ['LITE_PR_PIPELINE', { + link: 'https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/3009/pipeline/', + date: '2017-10-29T04:16:36.458Z', + jobid: 3009 + }]]); + }); });