diff --git a/src/changelog.ts b/src/changelog.ts index d5fb934..55651f7 100644 --- a/src/changelog.ts +++ b/src/changelog.ts @@ -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[]; +}