Skip to content

Commit

Permalink
refactor(release-it): ♻️ refactor commit message formatting
Browse files Browse the repository at this point in the history
-   Update getTitleCasedScope function to convert commit scope to uppercase
-   Add missing subject field to note objects in addBangNotes and addNotableChanges functions
-   Remove null assignment to commit.body in addNotableChanges function
  • Loading branch information
navin-moorthy committed Jun 28, 2023
1 parent d57fb8e commit 542eb98
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions .release-it.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
commitPartial,
transform,
commitGroupsSort,
} = require("./release-it/writerOptions.cjs");
} = require("./release-it/conventionalChangelogWriterOptionsTransform.cjs");

module.exports = {
hooks: {
Expand All @@ -14,8 +14,8 @@ module.exports = {
},
git: {
requireBranch: "main",
// requireCleanWorkingDir: false,
requireCommits: true,
requireCleanWorkingDir: false,
commitMessage: "🚀 Release v${version}",
commitArgs: ["--no-verify", "-S"],
tagArgs: ["-s"],
Expand All @@ -34,6 +34,7 @@ module.exports = {
"@release-it/conventional-changelog": {
preset: { name: "conventionalcommits" },
infile: "CHANGELOG.md",
// ignoreRecommendedBump: true,
gitRawCommitsOpts: {
format:
"%B%n-hash-%n%H%n-shortHash-%n%h%n-gitTags-%n%d%n-committerDate-%n%ci%n-authorName-%n%an%n-authorEmail-%n%ae%n-gpgStatus-%n%G?%n-gpgSigner-%n%GS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function generateCommitUrl(context, commitHash) {
* @returns {string|null} The title-cased scope of the commit, or null if it does not exist.
*/
function getTitleCasedScope(commit) {
const scope = commit?.scope?.replaceAll(".", " ")?.replaceAll("-", " ");
const scope = commit?.scope?.toUpperCase();
return scope ? scope : null;
}

Expand All @@ -108,6 +108,7 @@ const addBangNotes = (commit, context) => {
text: null,
scope: getTitleCasedScope(commit),
body: commit?.body,
subject: commit?.subject,
header: noteText,
shortHash: commit.shortHash,
hashUrl: generateCommitUrl(context, commit.hash),
Expand All @@ -127,11 +128,10 @@ const addNotableChanges = (commit, context) => {
context.notableChanges.push({
scope: getTitleCasedScope(commit),
body: commit.body,
subject: commit?.subject,
shortHash: commit.shortHash,
hashUrl: generateCommitUrl(context, commit.hash),
});

commit.body = null;
}
};

Expand All @@ -144,6 +144,7 @@ const addOtherNotableChanges = (commit, context) => {
context.otherNotableChanges.push({
scope: getTitleCasedScope(commit),
body: commit.body,
subject: commit?.subject,
shortHash: commit.shortHash,
hashUrl: generateCommitUrl(context, commit.hash),
});
Expand Down
1 change: 1 addition & 0 deletions release-it/getCommitsSinceLastRelease.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFileSync, writeFileSync } from "node:fs";

import { Octokit } from "@octokit/core";
import dedent from "dedent";
import { config } from "dotenv";
Expand Down
6 changes: 3 additions & 3 deletions release-it/templates/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{{#each notes}}

{{#if scope}}#### `{{scope}}` {{/if}}
{{#if scope}}#### `{{scope}}`{{/if}}{{#if subject}}- {{subject}} {{/if}}

{{#if body}}
{{body}}
Expand All @@ -33,7 +33,7 @@ Introduced in: [`{{shortHash}}`]({{hashUrl}})

{{#each notableChanges}}

{{#if scope}}#### `{{scope}}` {{/if}}
{{#if scope}}#### `{{scope}}`{{/if}}{{#if subject}}- {{subject}} {{/if}}

{{#if body}}
{{body}}
Expand Down Expand Up @@ -70,7 +70,7 @@ Introduced in: [`{{shortHash}}`]({{hashUrl}})

{{#each otherNotableChanges}}

{{#if scope}}#### `{{scope}}` {{/if}}
{{#if scope}}#### `{{scope}}`{{/if}}{{#if subject}}- {{subject}} {{/if}}

{{#if body}}
{{body}}
Expand Down

0 comments on commit 542eb98

Please sign in to comment.