mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-27 18:12:00 +00:00
I wanted to move auto labeling into its own workflow, but realized that it and changelog generation were coupled. So I'm detaching that first, and then will work on auto labeling later. Includes general code for a changelog parser so that I can reuse it by that point. GitHub actions are great for downstreams, as setting up a PHP server for the webhook is not trivial, compared to Existing and getting it for free. They are also much more straightforward to test and update than the webhook. I was able to verify this was working trivially with an empty repository. Tested and working: Mothblocks/ss13-workflow-testing@0a2de4d
81 lines
1.7 KiB
JavaScript
81 lines
1.7 KiB
JavaScript
import * as changelogConfig from "./changelogConfig.js";
|
|
|
|
const REGEX_CHANGELOG_LINE = /^(\w+): (.+)$/;
|
|
|
|
const CHANGELOG_KEYS_TO_ENTRY = {};
|
|
for (const [types, entry] of changelogConfig.CHANGELOG_ENTRIES) {
|
|
const entryWithChangelogKey = {
|
|
...entry,
|
|
changelogKey: types[0],
|
|
};
|
|
|
|
for (const type of types) {
|
|
CHANGELOG_KEYS_TO_ENTRY[type] = entryWithChangelogKey;
|
|
}
|
|
}
|
|
|
|
function parseChangelogBody(lines, openTag) {
|
|
const [changelogOpening] = lines.splice(0, 1);
|
|
|
|
const author =
|
|
changelogOpening.substring(openTag.length).trim() || undefined;
|
|
|
|
const changelog = {
|
|
author,
|
|
changes: [],
|
|
};
|
|
|
|
for (const line of lines) {
|
|
if (line.trim().length === 0) {
|
|
continue;
|
|
}
|
|
|
|
for (const closeTag of changelogConfig.CHANGELOG_CLOSE_TAGS) {
|
|
if (line.startsWith(closeTag)) {
|
|
return changelog;
|
|
}
|
|
}
|
|
|
|
const match = line.match(REGEX_CHANGELOG_LINE);
|
|
if (match) {
|
|
const [_, type, description] = match;
|
|
|
|
const entry = CHANGELOG_KEYS_TO_ENTRY[type];
|
|
|
|
if (entry.placeholders.includes(description)) {
|
|
continue;
|
|
}
|
|
|
|
if (entry) {
|
|
changelog.changes.push({
|
|
type: entry,
|
|
description,
|
|
});
|
|
}
|
|
} else {
|
|
const lastChange = changelog.changes[changelog.changes.length - 1];
|
|
if (lastChange) {
|
|
lastChange.description += `\n${line}`;
|
|
}
|
|
}
|
|
}
|
|
|
|
return changelog;
|
|
}
|
|
|
|
export function parseChangelog(text) {
|
|
const lines = text.split("\n").map((line) => line.trim());
|
|
|
|
for (let index = 0; index < lines.length; index++) {
|
|
const line = lines[index];
|
|
|
|
for (const openTag of changelogConfig.CHANGELOG_OPEN_TAGS) {
|
|
if (line.startsWith(openTag)) {
|
|
return parseChangelogBody(lines.slice(index), openTag);
|
|
}
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
}
|