diff --git a/.release-it.json b/.release-it.json index 321837e49..4931c43f8 100644 --- a/.release-it.json +++ b/.release-it.json @@ -9,7 +9,8 @@ }, "git": { "commitMessage": "chore: release v${version}", - "requireCleanWorkingDir": true + "requireCleanWorkingDir": true, + "changelog": "node bin/buildChangelog.mjs" }, "github": { "release": true @@ -17,30 +18,5 @@ "npm": { "publish": false, "ignoreVersion": true - }, - "plugins": { - "@release-it/conventional-changelog": { - "preset": { - "name": "conventionalcommits", - "types": [ - { - "type": "feat", - "section": "Features" - }, - { - "type": "impr", - "section": "Improvements" - }, - { - "type": "fix", - "section": "Fixes" - }, - {} - ] - }, - "writerOpts": { - "headerPartial": "Thank you to all the contributors!" - } - } } } diff --git a/bin/buildChangelog.mjs b/bin/buildChangelog.mjs new file mode 100644 index 000000000..542590fa4 --- /dev/null +++ b/bin/buildChangelog.mjs @@ -0,0 +1,109 @@ +import conventionalChangelog from "conventional-changelog"; +import { exec } from "child_process"; + +const stream = conventionalChangelog( + { + preset: { + name: "conventionalcommits", + types: [ + { type: "feat", section: "Features" }, + { type: "impr", section: "Improvements" }, + { type: "fix", section: "Fixes" }, + ], + }, + }, + undefined, + undefined, + undefined, + { + headerPartial: "", + } +); + +const header = + "Thank you to all the contributors who made this release possible!\n\n---"; +const footer = `\n### Other\n\nVarious style, documentation, refactoring, performance, or build improvements.`; + +let log = ""; +for await (const chunk of stream) { + log += chunk; +} + +log = log.replace(/^\*/gm, "-"); + +console.log(header + log + footer); + +//i might come back to the approach below at some point + +async function getLog() { + return new Promise((resolve, reject) => { + exec( + `git log --oneline $(git describe --tags --abbrev=0 @^)..@ --pretty="format:%H %h %s"`, + (err, stdout, stderr) => { + if (err) { + reject(err); + } + + resolve(stdout); + } + ); + }); +} + +function itemIsAddingQuotes(item) { + return ( + (item.scope?.includes("quote") || + item.scope?.includes("quotes") || + item.message?.includes("quote")) && + (item.message.includes("add") || + item.message.includes("added") || + item.message.includes("adding") || + item.message.includes("adds")) + ); +} + +async function main() { + let logString = await getLog(); + logString = logString.split("\n"); + + let log = []; + for (let line of logString) { + //split line based on the format: d2739e4f193137db4d86450f0d50b3489d75c106 d2739e4f1 style: adjusted testConfig and modesNotice. + //use regex to split + const [_, hash, shortHash, fullMessage] = line.split( + /(\w{40}) (\w{9}) (.*)/ + ); + + //split message using regex based on fix(language): spelling mistakes in Nepali wordlist and quotes (sapradhan) (#4528) + //scope is optional, username is optional, pr number is optional + const [__, type, scope, message, username, pr] = fullMessage.split( + /^([^\s()]+)(?:\(([^\s()]+)\))?:\s(.*?)(?:\(([^\s()]+)\))?(?:\s\((#\d+)\))?$/ + ); + + if (type && message) { + log.push({ + hash, + shortHash, + type, + scope, + message, + username, + pr, + }); + } else { + console.warn("skipping line due to invalid format: " + line); + } + } + + log = log.filter((item) => ["feat", "fix", "impr"].includes(item.type)); + + log = log.filter((item) => !itemIsAddingQuotes(item)); + + let quoteAddCommits = log.filter((item) => itemIsAddingQuotes(item)); + + console.log(quoteAddCommits); + + // console.log(log); +} + +// main(); diff --git a/package-lock.json b/package-lock.json index 064aab625..3d4cb740d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@typescript-eslint/eslint-plugin": "5.59.11", "@typescript-eslint/parser": "5.59.11", "concurrently": "7.2.1", + "conventional-changelog": "4.0.0", "eslint": "8.42.0", "eslint-plugin-json": "2.1.2", "eslint-plugin-require-path-exists": "1.1.9", diff --git a/package.json b/package.json index c924514b0..c8fad70d2 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "@typescript-eslint/eslint-plugin": "5.59.11", "@typescript-eslint/parser": "5.59.11", "concurrently": "7.2.1", + "conventional-changelog": "4.0.0", "eslint": "8.42.0", "eslint-plugin-json": "2.1.2", "eslint-plugin-require-path-exists": "1.1.9",