Skip to content

Commit

Permalink
Add some error handling and remove some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AshCripps authored and AshCripps committed May 29, 2020
1 parent e4eaa1c commit 96fd884
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 189 deletions.
12 changes: 1 addition & 11 deletions bin/ncu-ci
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,13 @@ class CICommand {
build = new BenchmarkRun(cli, request, job.jobid);
break;
case DAILY_MASTER:
// console.log("CLI __________________________ CLI");
// console.log(cli);
// const subjob = new Job(cli, request, job.link, null);
// console.log(subjob);
const daily = new DailyBuild(cli, request, job.jobid);
const data = await daily.getBuildData();
// console.log("DATA ----------------------- DATA");
// console.log(data);
// console.log("REQUEST ----------------------- REQUEST");
// console.log(request);
// console.log("JOB >>>>>>>>>>>>>>>>>>>>>>>>>>>> JOB");
// console.log(job);
build = new CommitBuild(cli, request, data.subBuilds[0].buildNumber);
break;
default:
throw new Error(`Unknown job type ${job.type}`);
}
}

await build.getResults();
build.display();
Expand Down
224 changes: 46 additions & 178 deletions lib/ci/ci_result_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,17 @@ class TestBuild extends Job {
const { failures } = this;
let output = `Failures in job ${this.jobUrl}\n\n`;
for (const failure of failures) {
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){
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 @@ -352,24 +354,26 @@ class TestBuild extends Job {
}

function getHighlight(f) {
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: /, '');
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";
}

function markdownRow(...args) {
Expand Down Expand Up @@ -591,7 +595,6 @@ class CommitBuild extends TestBuild {
const builds = this.builds = {
failed: [], aborted: [], pending: [], unstable: []
};
//console.log("AM I HERE 1");
return { result: SUCCESS, builds };
}

Expand All @@ -602,7 +605,6 @@ class CommitBuild extends TestBuild {

// build: { buildNumber, jobName, result, url }
const builds = this.builds = { failed, aborted, pending, unstable };
//console.log("AM I HERE 2");
return { result, builds };
}

Expand All @@ -617,8 +619,6 @@ class CommitBuild extends TestBuild {
this.failures = [
new NCUFailure({ url: this.apiUrl }, err.message)
];
//console.log("AM I HERE 3-1");
//console.log(err);
return this.failures;
}
}
Expand All @@ -627,7 +627,6 @@ class CommitBuild extends TestBuild {
if (data.result === FAILURE && !data.subBuilds.length) {
const failure = new BuildFailure(this, 'Failed to trigger sub builds');
this.failures = [failure];
//console.log("AM I HERE 3-2");
return {
result: data.result,
builds: { failed: [], aborted: [], pending: [], unstable: [] },
Expand All @@ -638,13 +637,11 @@ class CommitBuild extends TestBuild {
const { result, builds } = this.getBuilds(data);

if (result !== FAILURE) {
//console.log("AM I HERE 41");
return { result, builds, failures: [] };
}

if (!builds.failed.length) {
const failures = await this.parseConsoleText();
//console.log("AM I HERE 4");
return { result, builds, failures };
}

Expand All @@ -653,24 +650,19 @@ class CommitBuild extends TestBuild {
if (jobName.includes('fanned')) {
const cause = this.getCause(data.actions);
const isResumed = cause && cause._class.includes('ResumeCause');
//console.log("AM I HERE 5");
return new FannedBuild(cli, request, jobName, buildNumber, isResumed)
.getResults();
} else if (jobName.includes('linter')) {
//console.log("AM I HERE 6");
return new LinterBuild(cli, request, jobName, buildNumber).getResults();
} else if (jobName.includes('freestyle')) {
//console.log("AM I HERE 7");
return new TestRun(cli, request, url).getResults();
}
//console.log("AM I HERE 8");
return new NormalBuild(cli, request, jobName, buildNumber).getResults();
});
const rawFailures = await Promise.all(promises);

const failures = this.failures = flatten(rawFailures);
cli.stopSpinner('Data downloaded');
//console.log("AM I HERE 9");
return { result, failures, builds };
}
}
Expand Down Expand Up @@ -757,145 +749,19 @@ class DailyBuild extends TestBuild {

this.commitBuild = null;
}
}

// getBuilds({ result, subBuilds }) {
// if (result === SUCCESS) {
// const builds = this.builds = {
// failed: [], aborted: [], pending: [], unstable: []
// };
// return { result: SUCCESS, builds };
// }

// const failed = subBuilds.filter(build => build.result === FAILURE);
// const aborted = subBuilds.filter(build => build.result === ABORTED);
// const pending = subBuilds.filter(build => build.result === null);
// const unstable = subBuilds.filter(build => build.result === UNSTABLE);

// // build: { buildNumber, jobName, result, url }
// const builds = this.builds = { failed, aborted, pending, unstable };
// for (build in builds){
// console.log(build);
// }
// return { result, builds };
// }

// // Get the failures and their reasons of this build
// async getResults() {
// const { cli, request } = this;

// let data;
// try {
// data = await this.getBuildData();
// } catch (err) {
// this.failures = [
// new NCUFailure({ url: this.apiUrl }, err.message)
// ];
// return this.failures;
// }
// const {
// result, subBuilds, changeSet, actions, timestamp
// } = data;
// // console.log("result");
// // console.log(result);
// // console.log("subBuilds");
// // console.log(subBuilds);
// // console.log("changeSet");
// // console.log(changeSet);
// // console.log("actions");
// // console.log(actions);
// // console.log("timestamp");
// // console.log(timestamp);
// this.setDailyBuildData(data);


// //for each subbuild is a commitbuild?
// subBuilds.forEach( build => {
// const commitBuild = new CommitBuild(this.cli, this.request, build.buildNumber);
// //console.log(this.cli + " " + this.request + " " + build.buildNumber);
// //console.log(commitBuild.getResults());
// commitBuild.getResults();
// commitBuild.displayBuilds();
// });

// // No sub build at all
// // const commitBuild = subBuilds[0];
// // if (commitBuild == null) {
// // const failure = new BuildFailure(
// // this, 'Failed to trigger node-daily-master'
// // );
// // Object.assign(failure, {
// // source: this.sourceURL,
// // upstream: this.jobUrl,
// // builtOn: this.builtOn
// // });
// // this.failures = [failure];
// // console.log("FAILURE HERE: " + failure);
// // return { result, builds: {}, failures: this.failures };
// // }

// // // Get result from the sub build
// // // assert.strictEqual(commitBuild.jobName, 'node-test-commit');
// // const allBuilds = commitBuild.build.subBuilds;
// // // TODO: fetch result, builtOn, timestamp in the commit build's own data
// // // ..or maybe they do not worth an additional API call?
// // // Note that we have to pass the actions down to detect resume builds.
// // const buildData = {
// // result, subBuilds: allBuilds, changeSet, actions, timestamp
// // };
// // const commitBuildId = commitBuild.buildNumber;
// // this.commitBuild = new NormalBuild(cli, request, commitBuildId);
// // const { builds, failures } = await this.commitBuild.getResults(buildData);

// // // Set up aliases for display
// // this.builds = builds;
// // this.failures = failures;
// // return { result, builds, failures };

// // const { builds } = this.getBuilds(data);

// // if (result !== FAILURE) {
// // return { result, builds, failures: [] };
// // }

// // if (!builds.failed.length) {
// // const failures = await this.parseConsoleText();
// // return { result, builds, failures };
// // }

// // cli.startSpinner(`Querying failures of ${this.path}`);
// // const promises = builds.failed.map(({ jobName, buildNumber, url }) => {
// // if (jobName.includes('fanned')) {
// // const cause = this.getCause(data.actions);
// // const isResumed = cause && cause._class.includes('ResumeCause');
// // return new FannedBuild(cli, request, jobName, buildNumber, isResumed)
// // .getResults();
// // } else if (jobName.includes('linter')) {
// // return new LinterBuild(cli, request, jobName, buildNumber).getResults();
// // } else if (jobName.includes('freestyle')) {
// // return new TestRun(cli, request, url).getResults();
// // }
// // return new NormalBuild(cli, request, jobName, buildNumber).getResults();
// // });
// // const rawFailures = await Promise.all(promises);

// // const failures = this.failures = flatten(rawFailures);
// // cli.stopSpinner('Data downloaded');
// // return { result, failures, builds };
// }

// formatAsMarkdown() {
// if (!this.commitBuild) {
// let result = 'Failed to trigger node-daily-master';
// if (this.builtOn) {
// result += ` on ${this.builtOn}`;
// }
// result += `\n\nURL: ${this.jobUrl}`;
// return result;
// }
// return super.formatAsMarkdown();
// }
// }
formatAsMarkdown() {
if (!this.commitBuild) {
let result = 'Failed to trigger node-daily-master';
if (this.builtOn) {
result += ` on ${this.builtOn}`;
}
result += `\n\nURL: ${this.jobUrl}`;
return result;
}
return super.formatAsMarkdown();
}
}

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

if (this.isResumed) {
// XXX: if it's a resumed build, we replace the build/git failures
Expand Down

0 comments on commit 96fd884

Please sign in to comment.