diff --git a/lib/ci/failure_aggregator.js b/lib/ci/failure_aggregator.js index 5cec214a..eaa429f2 100644 --- a/lib/ci/failure_aggregator.js +++ b/lib/ci/failure_aggregator.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import chalk from 'chalk'; import { getMachineUrl, parsePRFromURL } from '../links.js'; @@ -15,6 +14,11 @@ import { const { FAILURE_TYPES_NAME } = CIFailureParser; +function uniqBy(array, key) { + const seen = new Set(); + return array.filter((item) => !seen.has(item[key]) && seen.add(item[key])); +} + export class FailureAggregator { constructor(cli, data) { this.cli = cli; @@ -24,26 +28,19 @@ export class FailureAggregator { } aggregate() { - const failures = this.failures; - const groupedByReason = _.chain(failures) - .groupBy(getHighlight) - .toPairs() - .sortBy(0) - .value(); + const groupedByReason = Object.groupBy(this.failures, getHighlight); const data = []; - for (const item of groupedByReason) { - const [reason, failures] = item; + for (const reason of Object.keys(groupedByReason).sort()) { + const failures = groupedByReason[reason]; // Uncomment this and redirect stderr away to see matched highlights // console.log('HIGHLIGHT', reason); // If multiple sub builds of one PR are failed by the same reason, // we'll only take one of those builds, as that might be a genuine failure - const prs = _.chain(failures) - .uniqBy('source') - .sortBy((f) => parseJobFromURL(f.upstream).jobid) - .map((item) => ({ source: item.source, upstream: item.upstream })) - .value(); - const machines = _.uniqBy( + const prs = uniqBy(failures, 'source') + .map(({ source, upstream }) => ({ source, upstream, _id: parseJobFromURL(upstream).jobid })) + .sort((a, b) => a._id - b._id); + const machines = uniqBy( failures.map(f => ({ hostname: f.builtOn, url: f.url })), 'hostname'); data.push({ @@ -51,10 +48,9 @@ export class FailureAggregator { }); } - const groupedByType = _.groupBy(data, 'type'); - for (const type of Object.keys(groupedByType)) { - groupedByType[type] = - _.sortBy(groupedByType[type], r => 0 - (r.prs.length)); + const groupedByType = Object.groupBy(data, ({ type }) => type); + for (const group of Object.value(groupedByType)) { + group.sort((a, b) => b.prs.length - a.prs.length); } this.aggregates = groupedByType; return groupedByType; diff --git a/package-lock.json b/package-lock.json index c6e75218..49b18152 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,6 @@ "git-secure-tag", "js-yaml", "listr2", - "lodash", "ora", "replace-in-file", "semver", @@ -47,7 +46,6 @@ "git-secure-tag": "^2.3.1", "js-yaml": "^5.2.1", "listr2": "^9.0.5", - "lodash": "^4.17.21", "ora": "^9.0.0", "replace-in-file": "^8.3.0", "semver": "^7.7.1", diff --git a/package.json b/package.json index fe6c1185..740c36cb 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "git-secure-tag": "^2.3.1", "js-yaml": "^5.2.1", "listr2": "^9.0.5", - "lodash": "^4.17.21", "ora": "^9.0.0", "replace-in-file": "^8.3.0", "semver": "^7.7.1",