Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 22 additions & 1 deletion bin/ncu-ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ const args = yargs(hideBin(process.argv))
.option('limit', {
default: 99,
describe: 'Maximum number of CIs to get data from'
})
.option('since <date>', {
type: 'string',
describe: 'Time since when the CI results should be queried'
}).check(argv => {
try {
// eslint-disable-next-line no-new
new Date(argv.since);
} catch {
throw new Error('--since <date> should be string that can ' +
'be parsed by new Date()');
}
return true;
});
},
handler
Expand Down Expand Up @@ -421,7 +434,12 @@ class WalkCommand extends CICommand {

async initialize() {
const ciType = commandToType[this.argv.type];
const builds = await listBuilds(this.cli, this.request, ciType);
const since = this.argv.since ? new Date(this.argv.since) : undefined;
const builds = await listBuilds(this.cli, this.request, ciType, since);
if (builds.count === 0) {
this.cli.log('No applicable builds found.');
return;
}
this.queue.push({ type: 'health', ciType, builds });
for (const build of builds.failed.slice(0, this.argv.limit)) {
this.queue.push(build);
Expand All @@ -430,6 +448,9 @@ class WalkCommand extends CICommand {

async aggregate() {
const { argv, cli } = this;
if (this.queue.length === 0) {
return;
}
const aggregator = new FailureAggregator(cli, this.json);
this.json = aggregator.aggregate();
cli.log('');
Expand Down
9 changes: 6 additions & 3 deletions lib/ci/ci_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@ function filterBuild(builds, type) {
.map(build => parseJobFromURL(build.url));
}

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

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

const result = await request.json(url);
const builds = result.builds;
let builds = result.builds;
if (since) {
builds = builds.filter(build => build.timestamp > since);
}
const failed = filterBuild(builds, statusType.FAILURE);
const aborted = filterBuild(builds, statusType.ABORTED);
const pending = filterBuild(builds, null);
Expand Down