Skip to content

Commit

Permalink
ci: processing changelog 2 [no ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakutoc committed Dec 4, 2024
1 parent 4fde73a commit 4115e5f
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions .github/actions/processing-release-changelog/groupByHeadings.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
export function groupByHeadings(tree) {
const groups = new Map();
let currentHeading = null;
const h2List = new Set();

let currentGroup = null;
let currentNodes = [];

// Группируем узлы по заголовкам
for (const node of tree.children) {
if (node.type === 'heading' && node.depth === 2) {
currentHeading = node.children[0].value;
// При первом появлении заголовка создаем массив с ним
groups.set(currentHeading, [node]);
} else if (currentHeading) {
// Добавляем узлы к текущей группе
groups.get(currentHeading).push(node);
// Сохраняем предыдущую группу
if (currentGroup) {
const data = [...(groups.get(currentGroup) || []), ...currentNodes];

groups.set(currentGroup, data);
}

const headingValue = node.children[0].value;

currentGroup = headingValue;

// Сохраняем заголовок только если он встречается впервые
currentNodes = !h2List.has(headingValue) ? [node] : [];
h2List.add(headingValue);
} else if (currentGroup) {
currentNodes.push(node);
}
}

// Сохраняем последнюю группу
if (currentGroup && currentNodes.length) {
const data = [...(groups.get(currentGroup) || []), ...currentNodes];

groups.set(currentGroup, data);
}

return {
...tree,
children: [...groups.values()].flat(),
Expand Down

0 comments on commit 4115e5f

Please sign in to comment.