breaking: Combine similar commit messages into one log line

This commit is contained in:
Ardalan Amini committed 2020-10-18 02:00:13 +03:30
1 parent 2c08fe0cc9
commit 4635917ef5
1 file changed
+22 -7
+22 -7
View File
@@ -12,7 +12,7 @@ export async function generate(
);
const repoUrl = `https://github.com/${owner}/${repo}`;
const commits: Commits = {};
const commits: Logs = {};
paginator: for await (const { data } of octokit.paginate.iterator(
octokit.repos.listCommits,
@@ -44,11 +44,17 @@ export async function generate(
PR_REGEX,
(match, pull) => `[${match}](${repoUrl}/pull/${pull})`,
);
title = `${title} ([${sha.slice(0, 8)}](${repoUrl}/commit/${sha}))`;
commits[type] = commits[type] ?? {};
commits[type][category] = commits[type][category] ?? [];
commits[type][category].push(title);
const existingIndex = commits[type][category].findIndex(
(commit) => commit.title === title,
);
if (existingIndex === -1)
commits[type][category].push({ title, commits: [sha] });
else commits[type][category][existingIndex].commits.push(sha);
}
}
@@ -72,8 +78,12 @@ export async function generate(
const baseLine = defaultCategory ? "" : " ";
for (const title of categoryGroup) {
changelog.push(baseLine + "* " + title);
for (const { title, commits } of categoryGroup) {
changelog.push(
`${baseLine}* ${title} (${commits
.map((sha) => `[${sha.slice(0, 8)}](${repoUrl}/commit/${sha})`)
.join(",")})`,
);
}
}
@@ -109,8 +119,13 @@ const TYPES = {
test: "Tests",
};
interface Commits {
interface Logs {
[type: string]: {
[category: string]: string[];
[category: string]: Log[];
};
}
interface Log {
title: string;
commits: string[];
}