Skip to content

Commit

Permalink
Check that markdown header starts with version instead of is the vers…
Browse files Browse the repository at this point in the history
…ion (#54)
  • Loading branch information
jondricek authored Jan 1, 2025
1 parent 7ae8848 commit dde0019
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 6 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50332,7 +50332,12 @@ function extractChangeItems({ version }) {

visit(tree, 'heading', (node, index, parent) => {
const [text] = node.children;
if (text?.type === 'text' && text.value === version && parent && index !== undefined) {
if (
text?.type === 'text' &&
text.value.startsWith(version) &&
parent &&
index !== undefined
) {
const nextSibling = parent.children[index + 1];
if (nextSibling?.type === 'list') {
list = nextSibling;
Expand Down
14 changes: 14 additions & 0 deletions src/__tests__/changelogToGithubRelease.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { changelogToGithubRelease } from '../changelogToGithubRelease.js';
const changelog = `
# Changelog
## 1.1.0 - 2024-12-31
- ddd [#123](https://github.com/foo/bar/pull/123) ([@user](https://github.com/user)).
- eee.
## 1.0.0
- aaa [#123](https://github.com/foo/bar/pull/123) ([@user](https://github.com/user)).
- bbb.
Expand All @@ -14,6 +18,16 @@ const changelog = `
- ccc.
`;

test('rewrite change items for version with date in heading', async () => {
const result = await changelogToGithubRelease(changelog, '1.1.0');
assert.equal(
result,
`* ddd #123 (@user).
* eee.
`,
);
});

test('rewrite change items matching specified version', async () => {
const result = await changelogToGithubRelease(changelog, '1.0.0');
assert.equal(
Expand Down
7 changes: 6 additions & 1 deletion src/changelogToGithubRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ function extractChangeItems({ version }) {

visit(tree, 'heading', (node, index, parent) => {
const [text] = node.children;
if (text?.type === 'text' && text.value === version && parent && index !== undefined) {
if (
text?.type === 'text' &&
text.value.startsWith(version) &&
parent &&
index !== undefined
) {
const nextSibling = parent.children[index + 1];
if (nextSibling?.type === 'list') {
list = nextSibling;
Expand Down

0 comments on commit dde0019

Please sign in to comment.