-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathfailure_aggregator.js
More file actions
152 lines (139 loc) · 4.87 KB
/
Copy pathfailure_aggregator.js
File metadata and controls
152 lines (139 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import _ from 'lodash';
import chalk from 'chalk';
import { getMachineUrl, parsePRFromURL } from '../links.js';
import CIFailureParser from './ci_failure_parser.js';
import {
parseJobFromURL,
CI_TYPES
} from './ci_type_parser.js';
import {
fold,
getHighlight,
markdownRow
} from './ci_utils.js';
const { FAILURE_TYPES_NAME } = CIFailureParser;
export class FailureAggregator {
constructor(cli, data) {
this.cli = cli;
this.health = data[0];
this.failures = data.slice(1);
this.aggregates = null;
}
aggregate() {
const failures = this.failures;
const groupedByReason = _.chain(failures)
.groupBy(getHighlight)
.toPairs()
.sortBy(0)
.value();
const data = [];
for (const item of groupedByReason) {
const [reason, failures] = item;
// 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 = _.uniq(failures.map(f => f.builtOn));
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));
}
this.aggregates = groupedByType;
return groupedByType;
}
formatAsMarkdown() {
let { aggregates } = this;
if (!aggregates) {
aggregates = this.aggregates = this.aggregate();
}
const last = parseJobFromURL(this.failures[0].upstream);
const first = parseJobFromURL(
this.failures[this.failures.length - 1].upstream
);
const jobName = CI_TYPES.get(first.type).jobName;
let output = 'Failures in ';
output += `[${jobName}/${first.jobid}](${first.link}) to `;
output += `[${jobName}/${last.jobid}](${last.link}) `;
output += 'that failed more than 2 PRs\n';
output += '(Generated with `ncu-ci ';
output += `${process.argv.slice(2).join(' ')}\`)\n\n`;
output += this.health.formatAsMarkdown() + '\n';
const todo = [];
for (const type of Object.keys(aggregates)) {
if (aggregates[type].length === 0) {
continue;
}
output += `\n### ${FAILURE_TYPES_NAME[type]}\n\n`;
for (const item of aggregates[type]) {
const { reason, type, prs, failures, machines } = item;
if (prs.length < 2) { continue; }
todo.push({ count: prs.length, reason });
output += markdownRow('Reason', `<code>${reason}</code>`);
output += markdownRow('-', ':-');
output += markdownRow('Type', type);
const source = prs.map(f => f.source);
output += markdownRow(
'Failed PR', `${source.length} (${source.join(', ')})`
);
output += markdownRow(
'Appeared', machines.map(getMachineUrl).join(', ')
);
if (prs.length > 1) {
output += markdownRow('First CI', `${prs[0].upstream}`);
}
output += markdownRow('Last CI', `${prs[prs.length - 1].upstream}`);
output += '\n';
const example = failures[0].reason;
output += fold(
`<a href="${failures[0].url}">Example</a>`,
(example.length > 1024 ? example.slice(0, 1024) + '...' : example)
);
output += '\n\n-------\n\n';
}
}
output += '### Progress\n\n';
output += todo.map(
({ count, reason }) => `- [ ] \`${reason}\` (${count})`).join('\n'
);
return output + '\n';
}
display() {
let { cli, aggregates } = this;
if (!aggregates) {
aggregates = this.aggregates = this.aggregate();
}
for (const type of Object.keys(aggregates)) {
cli.separator(type);
for (const item of aggregates[type]) {
const { reason, type, prs, failures, machines } = item;
cli.table('Reason', reason);
cli.table('Type', type);
const source = prs
.map(f => {
const parsed = parsePRFromURL(f.source);
return parsed ? `#${parsed.prid}` : f.source;
});
cli.table('Failed PR', `${source.length} (${source.join(', ')})`);
cli.table('Appeared', machines.join(', '));
if (prs.length > 1) {
cli.table('First CI', `${prs[0].upstream}`);
}
cli.table('Last CI', `${prs[prs.length - 1].upstream}`);
cli.log('\n' + chalk.bold('Example: ') + `${failures[0].url}\n`);
const example = failures[0].reason;
cli.log(example.length > 512 ? example.slice(0, 512) + '...' : example);
cli.separator();
}
}
}
}