forked from salute-developers/plasma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
2,252 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: processing-release-changelog | ||
|
||
description: 'Transform release changelog with group by heading' | ||
|
||
inputs: | ||
data: | ||
description: "Raw data for processing" | ||
required: true | ||
|
||
outputs: | ||
changelog: | ||
description: "changelog after processing" | ||
|
||
runs: | ||
using: 'node20' | ||
main: 'index.js' |
56 changes: 56 additions & 0 deletions
56
.github/actions/processing-release-changelog/groupByHeadings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
export function groupByHeadings(tree) { | ||
const groups = new Map(); | ||
let nodes = [...tree.children]; | ||
|
||
let currentGroup = null; | ||
let currentNodes = []; | ||
let isFirstMainHeading = new Set(); // Для отслеживания первого вхождения заголовка | ||
|
||
for (let i = 0; i < nodes.length; i++) { | ||
const node = nodes[i]; | ||
|
||
if (node.type === 'heading' && node.depth === 2) { | ||
const headingValue = node.children[0].value; | ||
|
||
if (currentGroup) { | ||
if (!groups.has(currentGroup)) { | ||
groups.set(currentGroup, []); | ||
} | ||
|
||
groups.get(currentGroup).push(...currentNodes); | ||
} | ||
|
||
currentGroup = headingValue; | ||
// Добавляем заголовок в группу только если он встречается первый раз | ||
if (!isFirstMainHeading.has(headingValue)) { | ||
currentNodes = [node]; | ||
isFirstMainHeading.add(headingValue); | ||
} else { | ||
// Пропускаем повторный заголовок | ||
currentNodes = []; | ||
} | ||
} else { | ||
if (currentGroup) { | ||
currentNodes.push(node); | ||
} | ||
} | ||
} | ||
|
||
// Сохраняем последнюю группу | ||
if (currentGroup && currentNodes.length) { | ||
if (!groups.has(currentGroup)) { | ||
groups.set(currentGroup, []); | ||
} | ||
|
||
groups.get(currentGroup).push(...currentNodes); | ||
} | ||
|
||
// Создаем новое дерево | ||
const newChildren = []; | ||
|
||
for (const [_, nodes] of groups) { | ||
newChildren.push(...nodes); | ||
} | ||
|
||
return { ...tree, children: newChildren }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { unified } from 'unified'; | ||
import remarkParse from 'remark-parse'; | ||
import remarkStringify from 'remark-stringify'; | ||
|
||
import * as core from '@actions/core'; | ||
|
||
import { groupByHeadings } from './groupByHeadings.js'; | ||
|
||
async function run() { | ||
try { | ||
const data = core.getInput('data', { required: true }); | ||
|
||
const changelog = await unified() | ||
.use(remarkParse) | ||
.use(() => (tree) => { | ||
return groupByHeadings(tree); | ||
}) | ||
.use(remarkStringify) | ||
.process(data); | ||
|
||
core.setOutput('changelog', changelog); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
run(); |
Oops, something went wrong.