Skip to content

Commit

Permalink
fix: remove duplicate changelog entries
Browse files Browse the repository at this point in the history
  • Loading branch information
fgardt committed Dec 7, 2024
1 parent 9ebc1b4 commit d5a1222
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { join } = require('node:path');

const { getMiscError } = require('./get-error');


function getChangelogPath(config, context) {
return join(context.cwd, "./changelog.txt");
}
Expand All @@ -17,6 +16,14 @@ async function readChangelogFile(config, context) {
}

async function writeChangelogFile(config, context, changelog) {
// removing duplicate entries with a fun magic regex
const dup_filter = /^(\s{4}-\s.*$(?:\n\s{6}.*$)*)((?:\n\s{4}-\s.*$(?:\n\s{6}.*$)*)*)\n\1/gm;
let tmp;
while (tmp !== changelog) {
tmp = changelog;
changelog = changelog.replace(dup_filter, "$1$2");
}

try {
await writeFile(getChangelogPath(config, context), changelog);
} catch (error) {
Expand Down Expand Up @@ -58,4 +65,4 @@ module.exports = {
readChangelogFile,
writeChangelogFile,
updateChangelog
};
};

0 comments on commit d5a1222

Please sign in to comment.