Skip to content

Commit

Permalink
fix(files): trim changelog content (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera authored Jan 14, 2023
1 parent 7106ec7 commit 24313ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/__tests__/__snapshots__/files.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`Files should create, and update CHANGELOG.md version with a comparison urls: urls and paths, no release commit 1`] = `
"# Changelog
All notable changes to this project will be documented in this file.
## 1.0.0 (2022-10-01)
### Features
Expand All @@ -23,6 +24,7 @@ All notable changes to this project will be documented in this file.
exports[`Files should create, and update CHANGELOG.md version with a comparison urls: urls and paths, release commit 1`] = `
"# Changelog
All notable changes to this project will be documented in this file.
## [1.0.0](https://localhost/lorem/ipsum/comparmock/REALFIRST2345d421231231312312345dca11235...LASTg45b597123453031234555b6d25574ccacee) (2022-10-01)
### Features
Expand All @@ -43,6 +45,7 @@ All notable changes to this project will be documented in this file.
exports[`Files should create, and update CHANGELOG.md version with a comparison urls: urls and paths, release commit, no markdown links 1`] = `
"# Changelog
All notable changes to this project will be documented in this file.
## 1.0.0 (2022-10-01)
### Features
Expand All @@ -63,6 +66,7 @@ All notable changes to this project will be documented in this file.
exports[`Files should create, and update a basic CHANGELOG.md: changelog 1`] = `
"# Changelog
All notable changes to this project will be documented in this file.
## ¯\\_(ツ)_/¯ (2022-10-01)
### Features
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`Commit Changelog should parse commits to produce a CHANGELOG.md with an
{
"changelog": "# Changelog
All notable changes to this project will be documented in this file.
## <semverClean>["15.0.0"]</semverClean> (2022-10-01)
",
Expand All @@ -20,6 +21,7 @@ exports[`Commit Changelog should parse commits to produce a CHANGELOG.md: Commit
{
"changelog": "# Changelog
All notable changes to this project will be documented in this file.
## <semverClean>["<semverInc>[\\"0.0.100\\",\\"patch\\"]</semverInc>"]</semverClean> (2022-10-01)
",
Expand Down
6 changes: 3 additions & 3 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const updateChangelog = (

if (existsSync(changelogPath)) {
const [tempHeader, ...tempBody] = readFileSync(changelogPath, 'utf-8').split('##');
header = tempHeader;
body = (tempBody.length && `## ${tempBody.join('##')}`) || body;
header = tempHeader.trim();
body = (tempBody.length && `## ${tempBody.join('##').trim()}`) || body;
} else if (!isDryRun) {
writeFileSync(changelogPath, '');
}
Expand All @@ -67,7 +67,7 @@ const updateChangelog = (
}

const updatedBody = `## ${version} (${systemTimestamp})\n${displayCommits}`;
const output = `${header}\n${updatedBody}\n${body}`;
const output = `${header}\n\n${updatedBody}\n${body}`;

if (isDryRun) {
console.info(`\n${updatedBody}`);
Expand Down

0 comments on commit 24313ac

Please sign in to comment.