Skip to content

Commit 27ed889

Browse files
Refactor: Clean up and improve changelog generation script
This commit refactors the `generate-changelog.js` script for improved clarity, functionality, and code style. Key changes include: * **Filter Nightly Tags**: The script now filters out tags containing "nightly" to prevent them from being included in the official changelog. * **Code Cleanup**: Simplified comments, removed unnecessary logging (`log(...)` calls), and improved code formatting for better readability. * **Variable Renaming**: Renamed `previousTagInSlice` to a more direct name within its scope for clarity.
1 parent c5bf6f0 commit 27ed889

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

generate-changelog.js

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function log(...args) {
2525

2626
// Commit parsing rules
2727
const commitParsers = [
28-
// Skip some "noise" commits
28+
// Skip noise
2929
{ message: /^chore\(release\): prepare for/i, skip: true },
3030
{ message: /^chore\(deps.*\)/i, skip: true },
3131
{ message: /^chore\(change.*\)/i, skip: true },
@@ -34,52 +34,58 @@ const commitParsers = [
3434
{ message: /^fixes/i, skip: true },
3535
{ message: /^build/i, skip: true },
3636

37-
// Enhancements (new features, improvements, UX, performance)
37+
// Enhancements
3838
{ message: /^feat|^perf|^style|^ui|^ux/i, group: "### :sparkles: Enhancements:" },
3939

40-
// Bug fixes & hotfixes
40+
// Bug fixes
4141
{ message: /^fix|^bug|^hotfix|^emergency/i, group: "### :bug: Bug Fixes:" },
4242

43-
// Code quality (refactors, cleanup without changing behavior)
43+
// Code quality
4444
{ message: /^refactor/i, group: "### :wrench: Code Quality:" },
4545

4646
// Documentation
4747
{ message: /^doc/i, group: "### :books: Documentation:" },
4848

49-
// Localization & internationalization
49+
// Localization
5050
{ message: /^(lang|i18n)/i, group: "### :globe_with_meridians: Localization:" },
5151

5252
// Security
5353
{ message: /^security/i, group: "### :lock: Security:" },
5454

55-
// Feature removal / drops
55+
// Feature removal
5656
{ message: /^drop|^remove|^deprecated/i, group: "### :x: Feature Removals:" },
5757

5858
// Reverts
5959
{ message: /^revert/i, group: "### :rewind: Reverts:" },
6060

61-
// Build-related
61+
// Build
6262
{ message: /^build/i, group: "### :building_construction: Build:" },
6363

64-
// Dependencies-related
64+
// Dependencies
6565
{ message: /^dependency|^deps/i, group: "### :package: Dependencies:" },
6666

67-
// Meta: configuration, CI/CD, versioning, releases
68-
{ message: /^config|^configuration|^ci|^pipeline|^release|^version|^versioning/i, group: "### :gear: Meta:" },
67+
// Meta
68+
{
69+
message: /^config|^configuration|^ci|^pipeline|^release|^version|^versioning/i,
70+
group: "### :gear: Meta:",
71+
},
6972

7073
// Tests
7174
{ message: /^test/i, group: "### :test_tube: Tests:" },
7275

73-
// Infrastructure & Ops
76+
// Infrastructure
7477
{ message: /^infra|^infrastructure|^ops/i, group: "### :office: Infrastructure & Ops:" },
7578

76-
// Chore & cleanup
77-
{ message: /^chore|^housekeeping|^cleanup|^clean\(up\)/i, group: "### :broom: Maintenance & Cleanup:" },
79+
// Maintenance
80+
{
81+
message: /^chore|^housekeeping|^cleanup|^clean\(up\)/i,
82+
group: "### :broom: Maintenance & Cleanup:",
83+
},
7884
];
7985

8086
const GROUP_ORDER = commitParsers.filter((p) => !p.skip).map((p) => p.group);
8187

82-
// Helper functions
88+
// Helpers
8389
function run(cmd) {
8490
log("Running:", cmd);
8591
return execSync(cmd, { encoding: "utf8" }).trim();
@@ -108,17 +114,20 @@ function cleanMessage(message) {
108114
}
109115

110116
function linkPR(message) {
111-
return message.replace(/\(#(\d+)\)/g, (_, num) => `([#${num}](${REPO_URL}/pull/${num}))`);
117+
return message.replace(/\(#(\d+)\)/g, (_, num) => {
118+
return `([#${num}](${REPO_URL}/pull/${num}))`;
119+
});
112120
}
113121

114-
// Get GitHub release title for a tag
122+
// GitHub release title
115123
function getReleaseTitle(tag) {
116124
const options = {
117125
hostname: "api.github.com",
118126
path: `/repos/CodeWorksCreativeHub/mLauncher/releases/tags/${tag}`,
119127
method: "GET",
120128
headers: { "User-Agent": "Node.js" },
121129
};
130+
122131
return new Promise((resolve) => {
123132
const req = https.request(options, (res) => {
124133
let data = "";
@@ -132,22 +141,28 @@ function getReleaseTitle(tag) {
132141
}
133142
});
134143
});
144+
135145
req.on("error", () => resolve(tag));
136146
req.end();
137147
});
138148
}
139149

140-
// Main async function
150+
// Main
141151
async function generateChangelog() {
142-
const allTags = run("git tag --sort=-creatordate").split("\n");
152+
// 🔥 Ignore nightly tags here
153+
const allTags = run("git tag --sort=-creatordate")
154+
.split("\n")
155+
.filter((tag) => !/nightly/i.test(tag));
156+
143157
const tags = allTags.slice(0, TAGS_TO_INCLUDE);
144158
log("Tags to include:", tags);
145159

146160
let changelog = HEADER;
147161

148-
// Coming Soon / Unreleased
162+
// Unreleased
149163
const latestTag = tags[0] || "unreleased";
150164
const rawUnreleased = run(`git log ${latestTag}..HEAD --pretty=format:"%h|%s"`).split("\n");
165+
151166
const unreleasedCommits = rawUnreleased
152167
.map((line) => {
153168
const [hash, ...msgParts] = line.split("|");
@@ -159,38 +174,37 @@ async function generateChangelog() {
159174
.filter(Boolean);
160175

161176
if (unreleasedCommits.length > 0) {
162-
log("Unreleased commits found:", unreleasedCommits.length);
163-
changelog += `## [${latestTag} → Unreleased](https://github.com/CodeWorksCreativeHub/mLauncher/tree/main) - In Development\n\n`;
177+
changelog += `## [${latestTag} → Unreleased](${REPO_URL}/tree/main) - In Development\n\n`;
178+
164179
const groups = {};
165180
for (const c of unreleasedCommits) {
166181
groups[c.group] = groups[c.group] || [];
167182
groups[c.group].push(`* ${linkPR(cleanMessage(c.message))} ([${c.hash}](${REPO_URL}/commit/${c.hash}))`);
168183
}
184+
169185
for (const group of GROUP_ORDER) {
170186
if (groups[group]) {
171-
log(`Unreleased group: ${group}, commits: ${groups[group].length}`);
172187
changelog += `${group}\n\n${groups[group].join("\n")}\n\n`;
173188
}
174189
}
175190
}
176191

177-
// Generate changelog for each tag
192+
// Tagged releases
178193
for (let i = 0; i < tags.length; i++) {
179194
const currentTag = tags[i];
180-
const releaseTitle = await getReleaseTitle(currentTag); // GitHub release title
181-
log(`Processing tag: ${currentTag} (${releaseTitle})`);
195+
const releaseTitle = await getReleaseTitle(currentTag);
182196

183197
let range;
184198
if (i === tags.length - 1) {
185199
const oldestTagIndex = allTags.indexOf(currentTag);
186200
const parentTag = allTags[oldestTagIndex - 1];
187201
range = parentTag ? `${parentTag}..${currentTag}` : currentTag;
188202
} else {
189-
const previousTagInSlice = tags[i + 1];
190-
range = `${previousTagInSlice}..${currentTag}`;
203+
range = `${tags[i + 1]}..${currentTag}`;
191204
}
192205

193206
const rawCommits = run(`git log ${range} --pretty=format:"%h|%s"`).split("\n");
207+
194208
const commits = rawCommits
195209
.map((line) => {
196210
const [hash, ...msgParts] = line.split("|");
@@ -226,5 +240,4 @@ async function generateChangelog() {
226240
console.log(`✅ Generated ${OUTPUT_FILE}`);
227241
}
228242

229-
// Run
230243
generateChangelog();

0 commit comments

Comments
 (0)