Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix(Changelog): bug fixes with generating changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
ijsKoud committed Jun 22, 2023
1 parent 6532d26 commit 749a249
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions packages/release/src/lib/Changelog.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import type { Octokit } from "@ijsblokje/octokit";
import type { Commit, CommitType } from "./Commit.js";

export class Changelog {
/** The list of commits for this changelog */
public readonly commits: Commit[];

/** The octokit instance with an authenticated installation token */
public readonly octokit: Octokit;

public constructor(commits: Commit[], octokit: Octokit) {
public constructor(commits: Commit[]) {
this.commits = commits;
this.octokit = octokit;
}

/**
Expand All @@ -26,16 +21,21 @@ export class Changelog {
if (!parsed) continue;

const changelogMessage = parsed.scope ? `**${parsed.scope}**: ${parsed.message}` : parsed.message;
const message = parsed.breaking ? `${changelogMessage} **💥 breaking change**` : changelogMessage;
const commitSha = `(${commit.sha.name})[${commit.sha.url}]`;

categories[parsed.type] ??= [];
categories[parsed.type]!.push(`- ${changelogMessage} (${commitSha})`);
categories[parsed.type]!.push(`- ${message} (${commitSha})`);
}

const categoryKeys = Object.keys(categories) as CommitType[];
const categoryContent = categoryKeys.map((key) => `## ${key}\n${categories[key]!.join("\n")}`).join("\n\n");
const categoryContent = categoryKeys
.sort((a, b) => ChangelogPosition[a] - ChangelogPosition[b])
.map((key) => `## ${ChangelogScope[key]}\n${categories[key]!.join("\n")}`)
.join("\n\n");

return `# Release v${version} 🎉\n${additionalMessage}\n${categoryContent}`;
const message = Boolean(additionalMessage) ? `${additionalMessage}\n` : "";
return [`# Release v${version} 🎉`, message, categoryContent].join("\n");
}
}

Expand All @@ -53,3 +53,21 @@ export enum ChangelogScope {
test = "🧪 Tests",
types = "🚨 Typings"
}

export enum ChangelogPosition {
feat,
fix,
revert,

refactor,
perf,
types,

chore,
docs,
build,

style,
test,
ci
}

0 comments on commit 749a249

Please sign in to comment.