Skip to content

Commit

Permalink
Add support reference-style links (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous authored Jan 1, 2025
1 parent 933fdb0 commit 6bfab97
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50351,10 +50351,12 @@ function extractChangeItems({ version }) {
throw new Error(`Not found version: ${version}`);
}

// Rewrite a link to a PR notation (#123) or a user mention (@username).
visit(list, 'link', (node, index, parent) => {
// Rewrite a link or reference to a PR notation (#123) or a user mention (@username).
visit(list, ['link', 'linkReference'], (node, index, parent) => {
if (index === undefined || parent === undefined) return CONTINUE;

if (!('children' in node)) return CONTINUE;

const [text] = node.children;
if (text?.type !== 'text') return CONTINUE;

Expand Down
25 changes: 13 additions & 12 deletions src/__tests__/changelogToGithubRelease.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { changelogToGithubRelease } from '../changelogToGithubRelease.js';
const changelog = `
# Changelog
## 1.2.0
- reference-style link [#456][] ([@user1]).
## 1.1.0 - 2024-12-31
- ddd [#123](https://github.com/foo/bar/pull/123) ([@user](https://github.com/user)).
- eee.
Expand All @@ -16,26 +19,24 @@ const changelog = `
## 0.1.0
- ccc.
[#456]: https://github.com/foo/bar/pull/456
[@user1]: https://github.com/user1
`;

test('rewrite change items including reference links', { only: true }, async () => {
const result = await changelogToGithubRelease(changelog, '1.2.0');
assert.equal(result, '* reference-style link #456 (@user1).\n');
});

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.
`,
);
assert.equal(result, '* ddd #123 (@user).\n* eee.\n');
});

test('rewrite change items matching specified version', async () => {
const result = await changelogToGithubRelease(changelog, '1.0.0');
assert.equal(
result,
`* aaa #123 (@user).
* bbb.
`,
);
assert.equal(result, '* aaa #123 (@user).\n* bbb.\n');
});

test('raise an error when a specified version is not found', async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/changelogToGithubRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ function extractChangeItems({ version }) {
throw new Error(`Not found version: ${version}`);
}

// Rewrite a link to a PR notation (#123) or a user mention (@username).
visit(list, 'link', (node, index, parent) => {
// Rewrite a link or reference to a PR notation (#123) or a user mention (@username).
visit(list, ['link', 'linkReference'], (node, index, parent) => {
if (index === undefined || parent === undefined) return CONTINUE;

if (!('children' in node)) return CONTINUE;

const [text] = node.children;
if (text?.type !== 'text') return CONTINUE;

Expand Down

0 comments on commit 6bfab97

Please sign in to comment.