Skip to content

Commit

Permalink
fix: correctly handle empty sections in the input
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Mar 4, 2024
1 parent 7ebb022 commit f1dd4e9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
6 changes: 4 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions dist/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/utils.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export function composeComment(message: string): string {
const lines = message.split('\n');
const composed = lines.map(line => {
try {
return JSON.parse(line);
} catch (e) {
return line;
}
});
const composed = lines
.map(line => {
try {
return JSON.parse(line);
} catch (e) {
return line;
}
})
.filter(section => section !== '');

return composed.join('\n\n---\n\n');
}
4 changes: 2 additions & 2 deletions test/unit/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe('Unit tests of general utilities', () => {
expect(
composeComment(
`${JSON.stringify('Hello, world!')}\n${JSON.stringify(
'Hello, universe!'
)}`
''
)}\n${JSON.stringify('Hello, universe!')}`
)
).toMatchInlineSnapshot(`
"Hello, world!
Expand Down

0 comments on commit f1dd4e9

Please sign in to comment.