mirror of
https://github.com/SethCohen/github-releases-to-discord
synced 2026-09-14 20:13:23 +00:00
feat: enhance reduceHeadings function to handle indented and closed markdown headings and add tests for new functionality. resolves #51
This commit is contained in:
@@ -7,3 +7,4 @@ release.json
|
|||||||
repository.json
|
repository.json
|
||||||
user.json
|
user.json
|
||||||
tests/sample-test-release-v2.json
|
tests/sample-test-release-v2.json
|
||||||
|
tests/sample-test-release-v3.json
|
||||||
|
|||||||
@@ -61,8 +61,21 @@ const removeGithubReferenceLinks = (text) => text
|
|||||||
* @returns {string} The text with reduced heading sizes.
|
* @returns {string} The text with reduced heading sizes.
|
||||||
*/
|
*/
|
||||||
const reduceHeadings = (text) => text
|
const reduceHeadings = (text) => text
|
||||||
.replace(/^###\s+(.+)$/gm, '**__$1__**') // Convert H3 to bold + underline
|
.split('\n')
|
||||||
.replace(/^##\s+(.+)$/gm, '**$1**'); // Convert H2 to bold
|
.map((line) => {
|
||||||
|
const h3 = line.match(/^\s*###\s+(.+?)\s*#*\s*$/);
|
||||||
|
if (h3) {
|
||||||
|
return `**__${h3[1].trim()}__**`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const h2 = line.match(/^\s*##\s+(.+?)\s*#*\s*$/);
|
||||||
|
if (h2) {
|
||||||
|
return `**${h2[1].trim()}**`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return line;
|
||||||
|
})
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts PR, issue, and changelog links to markdown format, ignoring existing markdown links.
|
* Converts PR, issue, and changelog links to markdown format, ignoring existing markdown links.
|
||||||
|
|||||||
@@ -70,6 +70,16 @@ describe('index.js utility functions', () => {
|
|||||||
expect(reduceHeadings('## Heading2')).toBe('**Heading2**');
|
expect(reduceHeadings('## Heading2')).toBe('**Heading2**');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('reduceHeadings reduces repeated section headings', () => {
|
||||||
|
const input = '### Bug Fixes\n- fix thing\n\n### Features\n- add thing';
|
||||||
|
expect(reduceHeadings(input)).toBe('**__Bug Fixes__**\n- fix thing\n\n**__Features__**\n- add thing');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('reduceHeadings handles indented and closed markdown headings', () => {
|
||||||
|
const input = ' ## Changes ##\n ### Features ###';
|
||||||
|
expect(reduceHeadings(input)).toBe('**Changes**\n**__Features__**');
|
||||||
|
});
|
||||||
|
|
||||||
test('convertLinksToMarkdown converts PR/issue/changelog links', () => {
|
test('convertLinksToMarkdown converts PR/issue/changelog links', () => {
|
||||||
const pr = 'https://github.com/owner/repo/pull/1';
|
const pr = 'https://github.com/owner/repo/pull/1';
|
||||||
const issue = 'https://github.com/owner/repo/issues/2';
|
const issue = 'https://github.com/owner/repo/issues/2';
|
||||||
|
|||||||
Reference in New Issue
Block a user