From 1473a87092c6c02e37378897eb0a4042da2f90c8 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 21 May 2024 15:32:22 -0700 Subject: [PATCH] fix: changelog formatting --- .github/workflows/release-please.yml | 2 +- ci/format-changelog.js | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 74aaafca0d..d810ad790e 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -54,7 +54,7 @@ jobs: - run: npm run build:files working-directory: ./documentation/app - - run: npm run format-changelog + - run: yarn && npm run format-changelog - name: Committing and push changes run: | diff --git a/ci/format-changelog.js b/ci/format-changelog.js index 7096b34a25..6e18e13f2d 100644 --- a/ci/format-changelog.js +++ b/ci/format-changelog.js @@ -48,9 +48,7 @@ try { } function getAst(markdownString) { - const tree = unified() - .use(remarkParse) - .parse(markdownString); + const tree = unified().use(remarkParse).parse(markdownString); return tree; } @@ -94,7 +92,8 @@ function format(ast, path) { ) { const link = item.children[0]; item.children = [item.children[1]]; - item.children[0].value = link.children[0].value + item.children[0].value; + item.children[0].value = + link.children[0].value + item.children[0].value; changed = true; } else if (item.children.length !== 1) { console.log( @@ -189,6 +188,19 @@ function format(ast, path) { // checks on all ### headings if (item.type === "heading" && item.depth === 3) { // check it only uses one of the fixed options for change types + if (item.children.length === 1 && item.children[0].type === "text") { + const val = item.children[0].value; + if (val.toLowerCase().endsWith("breaking changes")) { + item.children[0].value = "Changed"; + changed = true; + } else if (val.includes("Bug Fixes")) { + item.children[0].value = "Fixed"; + changed = true; + } else if (val.includes("Features")) { + item.children[0].value = "Added"; + changed = true; + } + } if ( item.children.length !== 1 || item.children[0].type !== "text" || @@ -226,10 +238,10 @@ function format(ast, path) { if (changed) { // ...work around convoluted API... - const wat = { data () {} }; + const wat = { data() {} }; remarkStringify.call(wat); const output = wat.compiler(ast); - writeFileSync(path, output, 'utf8'); + writeFileSync(path, `# Changelog\n\n${output}`, "utf8"); } return { correct: true, changed };