perf(changelog): improve generation time by ~2800 times (#23)

This commit is contained in:
2024-05-04 23:01:10 +03:00
parent 6df1021561
commit 0cac22a7e0

View File

@@ -51,63 +51,34 @@ const command = new Command("changelog")
for (const commit of commits) { for (const commit of commits) {
const tag = const tag =
sort((await simpleGit().tags([`--contains=${commit.hash}`])).all)[0]! || (commit.refs.match(/tag: (\S+)(?:,|$)/)?.[1] ?? lastTag) || unreleased;
unreleased;
const currentCommitStack = parsedCommitStacks.find( let currentCommitStackIndex = parsedCommitStacks.findIndex(
(commitStack) => commitStack.version === tag, (commitStack) => commitStack.version === tag,
) || { );
version: tag || unreleased,
breaking: [],
features: [],
fixes: [],
miscellaneous: [],
};
if (lastTag !== tag) { if (currentCommitStackIndex === -1) {
parsedCommitStacks = [currentCommitStack, ...parsedCommitStacks]; parsedCommitStacks.push({
version: tag || unreleased,
breaking: [],
features: [],
fixes: [],
miscellaneous: [],
});
currentCommitStackIndex = parsedCommitStacks.findIndex(
(commitStack) => commitStack.version === tag,
);
} }
if (commit.message.includes("!:")) { if (commit.message.includes("!:")) {
parsedCommitStacks = [ parsedCommitStacks[currentCommitStackIndex].breaking.push(commit);
{
...currentCommitStack,
breaking: [...currentCommitStack.breaking, commit],
},
...parsedCommitStacks.filter(
(commitStack) => commitStack.version !== tag,
),
];
} else if (commit.message.startsWith("feat")) { } else if (commit.message.startsWith("feat")) {
parsedCommitStacks = [ parsedCommitStacks[currentCommitStackIndex].features.push(commit);
{
...currentCommitStack,
features: [...currentCommitStack.features, commit],
},
...parsedCommitStacks.filter(
(commitStack) => commitStack.version !== tag,
),
];
} else if (commit.message.startsWith("fix")) { } else if (commit.message.startsWith("fix")) {
parsedCommitStacks = [ parsedCommitStacks[currentCommitStackIndex].fixes.push(commit);
{
...currentCommitStack,
fixes: [...currentCommitStack.fixes, commit],
},
...parsedCommitStacks.filter(
(commitStack) => commitStack.version !== tag,
),
];
} else { } else {
parsedCommitStacks = [ parsedCommitStacks[currentCommitStackIndex].miscellaneous.push(commit);
{
...currentCommitStack,
miscellaneous: [...currentCommitStack.miscellaneous, commit],
},
...parsedCommitStacks.filter(
(commitStack) => commitStack.version !== tag,
),
];
} }
lastTag = tag; lastTag = tag;