Skip to content

Commit

Permalink
Make handling of lowercased label in the Unreleased link definition m…
Browse files Browse the repository at this point in the history
…ore robust (#17)

- Find existing definition with case-insensitive search
- Keep the original casing by reusing the found pattern
  • Loading branch information
tamaracha authored Mar 20, 2022
1 parent 66b4119 commit 85db46d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ class KeepAChangelog extends Plugin {
// Add or update the Unreleased link
const unreleasedUrl = `${repositoryUrl}/compare/${tagName}...${this.head}`;
const unreleasedLink = `[Unreleased]: ${unreleasedUrl}`;
if (updatedChangelog.includes('[Unreleased]:')) {
updatedChangelog = updatedChangelog.replace(new RegExp('\\[Unreleased\\]\\:.*' + this.head), unreleasedLink);
const hasUnreleasedLink = /^\[(Unreleased)\]\: .*$/im
if (hasUnreleasedLink.test(updatedChangelog)) {
updatedChangelog = updatedChangelog.replace(hasUnreleasedLink, '[$1]: ' + unreleasedUrl);
} else {
updatedChangelog = `${updatedChangelog}${this.EOL}${this.EOL}${unreleasedLink}`;
}
Expand Down

0 comments on commit 85db46d

Please sign in to comment.