Skip to content

Commit

Permalink
fix: changelog formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed May 21, 2024
1 parent a87a3d9 commit 1473a87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
24 changes: 18 additions & 6 deletions ci/format-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ try {
}

function getAst(markdownString) {
const tree = unified()
.use(remarkParse)
.parse(markdownString);
const tree = unified().use(remarkParse).parse(markdownString);
return tree;
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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" ||
Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit 1473a87

Please sign in to comment.