Skip to content

Commit

Permalink
address comments and fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AshCripps authored and AshCripps committed May 29, 2020
1 parent 51080ea commit fcb5eef
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 72 deletions.
8 changes: 4 additions & 4 deletions bin/ncu-ci
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
} = require('../lib/ci/ci_type_parser');

const {
PRBuild, BenchmarkRun, CommitBuild, HealthBuild, DailyBuild, Job,
PRBuild, BenchmarkRun, CommitBuild, HealthBuild, DailyBuild,
listBuilds, FailureAggregator, jobCache
} = require('../lib/ci/ci_result_parser');
const clipboardy = require('clipboardy');
Expand Down Expand Up @@ -212,11 +212,12 @@ class CICommand {
case BENCHMARK:
build = new BenchmarkRun(cli, request, job.jobid);
break;
case DAILY_MASTER:
case DAILY_MASTER: {
const daily = new DailyBuild(cli, request, job.jobid);
const data = await daily.getBuildData();
build = new CommitBuild(cli, request, data.subBuilds[0].buildNumber);
break;
}
default:
throw new Error(`Unknown job type ${job.type}`);
}
Expand Down Expand Up @@ -358,7 +359,7 @@ class URLCommand extends CICommand {
}
}

class DailyCommand extends CICommand { //EDIT THIS
class DailyCommand extends CICommand {
constructor(cli, request, argv) {
super(cli, request, argv);
if (argv.cache) {
Expand All @@ -367,7 +368,6 @@ class DailyCommand extends CICommand { //EDIT THIS
}

async initialize() {
//const ciType = commandToType[this.argv.type];
const ciType = DAILY_MASTER;
const builds = await listBuilds(this.cli, this.request, ciType);
this.queue.push({ type: 'health', ciType, builds });
Expand Down
133 changes: 66 additions & 67 deletions lib/ci/ci_result_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class TestBuild extends Job {
displayBuilds() {
const { cli, failures, builds } = this;
for (const failure of failures) {
if (failure != undefined){
if (failure !== undefined) {
this.displayFailure(failure);
}
}
Expand Down Expand Up @@ -329,17 +329,16 @@ class TestBuild extends Job {
const { failures } = this;
let output = `Failures in job ${this.jobUrl}\n\n`;
for (const failure of failures) {
if (failure != undefined){
output += `#### [${getNodeName(failure.url)}](${failure.url})`;
if (!failure.reason.includes('\n') && failure.reason.length < 20) {
const builtOn = failure.builtOn ? `On ${failure.builtOn}: ` : '';
output += `\n\n${builtOn}${failure.reason}\n`;
} else {
output += '\n\n';
const builtOn = failure.builtOn ? ` on ${failure.builtOn}:` : '';
output += fold(`See failures${builtOn}`, failure.reason) + '\n\n';
}
}
if (failure === undefined) continue;
output += `#### [${getNodeName(failure.url)}](${failure.url})`;
if (!failure.reason.includes('\n') && failure.reason.length < 20) {
const builtOn = failure.builtOn ? `On ${failure.builtOn}: ` : '';
output += `\n\n${builtOn}${failure.reason}\n`;
} else {
output += '\n\n';
const builtOn = failure.builtOn ? ` on ${failure.builtOn}:` : '';
output += fold(`See failures${builtOn}`, failure.reason) + '\n\n';
}
}
return output;
}
Expand All @@ -354,26 +353,28 @@ class TestBuild extends Job {
}

function getHighlight(f) {
if (f.reason != undefined){
return f.reason.split('\n')[f.highlight]
.replace(/not ok \d+ /, '')
.replace(
/JNLP4-connect connection from \S+/, 'JNLP4-connect connection from ...'
)
.replace(/FATAL: Could not checkout \w+/, 'FATAL: Could not checkout ...')
.replace(
/error: pathspec .+ did not match any file\(s\) known to git/,
'error: pathspec ... did not match any file(s) known to git')
.replace(
/failed: no workspace for .+/,
'failed: no workspace for ...'
)
.replace(
/fatal: loose object \w+ \(stored in .git\/objects\/.+\) is corrupt/,
'fatal: loose object ... (stored in .git/objects/...) is corrupt')
.replace(/hudson\.plugins\.git\.GitException: /, '')
.replace(/java\.io\.IOException: /, '');
} else return f.reason = "failure not found";
if (!f.reason) {
f.reason = 'failure not found';
return f.reason;
}
return f.reason.split('\n')[f.highlight]
.replace(/not ok \d+ /, '')
.replace(
/JNLP4-connect connection from \S+/, 'JNLP4-connect connection from ...'
)
.replace(/FATAL: Could not checkout \w+/, 'FATAL: Could not checkout ...')
.replace(
/error: pathspec .+ did not match any file\(s\) known to git/,
'error: pathspec ... did not match any file(s) known to git')
.replace(
/failed: no workspace for .+/,
'failed: no workspace for ...'
)
.replace(
/fatal: loose object \w+ \(stored in .git\/objects\/.+\) is corrupt/,
'fatal: loose object ... (stored in .git/objects/...) is corrupt')
.replace(/hudson\.plugins\.git\.GitException: /, '')
.replace(/java\.io\.IOException: /, '');
}

function markdownRow(...args) {
Expand Down Expand Up @@ -839,7 +840,7 @@ class FannedBuild extends Job {
const { jobName, buildNumber } = failedPhase;
const build = new NormalBuild(cli, request, jobName, buildNumber);
let failures = await build.getResults();
if (failures != undefined){
if (failures !== undefined) {
failures = flatten(failures);
}

Expand Down Expand Up @@ -910,52 +911,50 @@ class NormalBuild extends Job {
}

const { result, runs, builtOn } = data;
//console.log(data);
this.builtOn = builtOn;

if (result !== FAILURE) {
this.failures = [];
return this.failures;
}

if (runs != undefined){
if (!runs) return [];

if (!runs.length) {
this.failures = [
new BuildFailure(
{ url: this.jobUrl, builtOn }, 'Failed to trigger runs'
)
];
return this.failures;
}
if (!runs.length) {
this.failures = [
new BuildFailure(
{ url: this.jobUrl, builtOn }, 'Failed to trigger runs'
)
];
return this.failures;
}

const failed = runs.filter(run => run.result === FAILURE);
const failed = runs.filter(run => run.result === FAILURE);

if (!failed.length) {
return this.parseConsoleText();
}
if (!failed.length) {
return this.parseConsoleText();
}

const tests = failed.map(({ url }) => new TestRun(cli, request, url));

// Skip runs that are not actually triggered by this job
await Promise.all(tests.map(run => run.getData()));
const causes = tests.map(run => run.cause);
const actualRuns = tests.filter((_, index) => {
const upstream = causes[index].upstreamBuild;
if (!upstream) {
return true;
} else {
return this.jobUrl.includes(upstream + '');
}
});
const tests = failed.map(({ url }) => new TestRun(cli, request, url));

const failures = await Promise.all(
actualRuns.map(run => run.getResults())
);
this.failures = flatten(failures);
return this.failures;
}
}
// Skip runs that are not actually triggered by this job
await Promise.all(tests.map(run => run.getData()));
const causes = tests.map(run => run.cause);
const actualRuns = tests.filter((_, index) => {
const upstream = causes[index].upstreamBuild;
if (!upstream) {
return true;
} else {
return this.jobUrl.includes(upstream + '');
}
});

const failures = await Promise.all(
actualRuns.map(run => run.getResults())
);
this.failures = flatten(failures);
return this.failures;
}
}

class TestRun extends Job {
Expand Down
2 changes: 1 addition & 1 deletion lib/ci/ci_type_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const CI_TYPES = new Map([
name: 'Node Daily Master',
jobName: 'node-daily-master',
pattern: /job\/node-daily-master\/(\d+)/,
type: JOB_CI
type: JOB_CI
}]
]);

Expand Down

0 comments on commit fcb5eef

Please sign in to comment.