Skip to content

Commit e01ca12

Browse files
joyeecheungtargos
andauthored
feat: add --since option to ncu-ci (#649)
* feat: add --since option to ncu-ci Co-authored-by: Michaël Zasso <[email protected]>
1 parent 36e9f0f commit e01ca12

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

bin/ncu-ci.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ const args = yargs(hideBin(process.argv))
8686
.option('limit', {
8787
default: 99,
8888
describe: 'Maximum number of CIs to get data from'
89+
})
90+
.option('since <date>', {
91+
type: 'string',
92+
describe: 'Time since when the CI results should be queried'
93+
}).check(argv => {
94+
try {
95+
// eslint-disable-next-line no-new
96+
new Date(argv.since);
97+
} catch {
98+
throw new Error('--since <date> should be string that can ' +
99+
'be parsed by new Date()');
100+
}
101+
return true;
89102
});
90103
},
91104
handler
@@ -421,7 +434,12 @@ class WalkCommand extends CICommand {
421434

422435
async initialize() {
423436
const ciType = commandToType[this.argv.type];
424-
const builds = await listBuilds(this.cli, this.request, ciType);
437+
const since = this.argv.since ? new Date(this.argv.since) : undefined;
438+
const builds = await listBuilds(this.cli, this.request, ciType, since);
439+
if (builds.count === 0) {
440+
this.cli.log('No applicable builds found.');
441+
return;
442+
}
425443
this.queue.push({ type: 'health', ciType, builds });
426444
for (const build of builds.failed.slice(0, this.argv.limit)) {
427445
this.queue.push(build);
@@ -430,6 +448,9 @@ class WalkCommand extends CICommand {
430448

431449
async aggregate() {
432450
const { argv, cli } = this;
451+
if (this.queue.length === 0) {
452+
return;
453+
}
433454
const aggregator = new FailureAggregator(cli, this.json);
434455
this.json = aggregator.aggregate();
435456
cli.log('');

lib/ci/ci_utils.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@ function filterBuild(builds, type) {
5050
.map(build => parseJobFromURL(build.url));
5151
}
5252

53-
export async function listBuilds(cli, request, type) {
53+
export async function listBuilds(cli, request, type, since) {
5454
// assert(type === COMMIT || type === PR)
5555
const { jobName } = CI_TYPES.get(type);
56-
const tree = 'builds[url,result]';
56+
const tree = 'builds[url,result,timestamp]';
5757
const url = `https://${CI_DOMAIN}/job/${jobName}/api/json?tree=${qs.escape(tree)}`;
5858

5959
cli.startSpinner(`Querying ${url}`);
6060

6161
const result = await request.json(url);
62-
const builds = result.builds;
62+
let builds = result.builds;
63+
if (since) {
64+
builds = builds.filter(build => build.timestamp > since);
65+
}
6366
const failed = filterBuild(builds, statusType.FAILURE);
6467
const aborted = filterBuild(builds, statusType.ABORTED);
6568
const pending = filterBuild(builds, null);

0 commit comments

Comments
 (0)