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
34 changes: 15 additions & 19 deletions lib/ci/failure_aggregator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import chalk from 'chalk';

import { getMachineUrl, parsePRFromURL } from '../links.js';
Expand All @@ -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;
Expand All @@ -24,37 +28,29 @@ 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({
reason, type: failures[0].type, failures, prs, machines
});
}

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;
Expand Down
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading