Skip to content

Commit c5233c6

Browse files
author
Guy Bedford
authored
ci: fix changelog formatting to handle perf improvements (#879)
1 parent e4ddf8a commit c5233c6

File tree

1 file changed

+58
-5
lines changed

1 file changed

+58
-5
lines changed

ci/format-changelog.js

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ function format(ast, path) {
7878
};
7979
}
8080

81+
let changedIdx = -1;
8182
for (let i = 0; i < content.length; i++) {
8283
// checks on all ## headings
8384
const item = content[i];
8485
if (item.type === "heading" && item.depth === 2) {
86+
changedIdx = -1;
8587
// check correct amount of text is at heading 2
8688
if (
8789
item.children.length === 2 &&
@@ -201,10 +203,58 @@ function format(ast, path) {
201203
changed = true;
202204
}
203205
}
204-
if (
205-
item.children.length !== 1 ||
206-
item.children[0].type !== "text" ||
207-
![
206+
207+
if (item.children.length !== 1 || item.children[0].type !== "text") {
208+
console.log(
209+
`${path}:${item.children[0].position.start.line}:${item.children[0].position.start.column}`
210+
);
211+
return {
212+
correct: false,
213+
reason: `Level 3 headings should only be text`,
214+
};
215+
}
216+
217+
if (item.children[0].value === 'Performance Improvements') {
218+
if (i + 1 < content.length && (content[i + 1].type !== 'list' || content[i + 2].type !== 'heading')) {
219+
console.log(
220+
`${path}:${item.children[0].position.start.line}:${item.children[0].position.start.column}`
221+
);
222+
return {
223+
correct: false,
224+
reason: `Performance improvements section must be a single list to fix it`,
225+
};
226+
}
227+
228+
if (changedIdx === -1) {
229+
for (let j = i + 1; j < content.length; j++) {
230+
const curItem = content[j];
231+
if (curItem.type === 'heading') {
232+
if (curItem.depth < 3)
233+
break;
234+
if (curItem.depth === 3 && curItem.children.length === 1 &&
235+
curItem.children[0].type === 'text' && curItem.children[0].value === 'Changed') {
236+
changedIdx = j;
237+
break;
238+
}
239+
}
240+
}
241+
}
242+
243+
if (changedIdx !== -1) {
244+
// Merge it into any already-seen changed section
245+
const toMerge = content[i + 1];
246+
content.splice(i, 2);
247+
content.splice(changedIdx + 1, 0, toMerge);
248+
changed = true;
249+
} else {
250+
// Otherwise rename to Changed
251+
item.children[0].value = 'Changed';
252+
changed = true;
253+
}
254+
continue;
255+
}
256+
257+
if (![
208258
"Added",
209259
"Changed",
210260
"Deprecated",
@@ -222,6 +272,9 @@ function format(ast, path) {
222272
};
223273
}
224274

275+
if (item.children[0].value === 'Changed')
276+
changedIdx = i;
277+
225278
// check that there is something other than a heading following it, which we have to presume describes the change
226279
if (!content[i + 1] || content[i + 1].type === "heading") {
227280
console.log(
@@ -230,7 +283,7 @@ function format(ast, path) {
230283
return {
231284
correct: false,
232285
reason:
233-
"Level 3 headings must be followed by something other than the next heading - you should use text to describe the change",
286+
"Level 3 headings must be followed by something other than a heading to describe the change",
234287
};
235288
}
236289
}

0 commit comments

Comments
 (0)