Skip to content

Commit

Permalink
#PIPE-3 - Added testcase and fixed code to work for parsing "[#1234](…
Browse files Browse the repository at this point in the history
…hello-world)" into the changelog
  • Loading branch information
Ryangr0 committed Apr 5, 2024
1 parent c7721d6 commit 76e8c03
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions __tests__/changelog_entries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ test('Extract multiple changelog entries from markdown with regular line breaks'
expect(extractEntriesFromMarkdown(txt)).toEqual(expectedOutput)
})

test('Changelog Entry with numbered change is extracted properly', async () => {
const txt = `## Changelog
### Changed
- [#1234](/hello-world) Test changelog modification`

const expectedOutput : ChangelogEntry[] = [
{
text: '[#1234](/hello-world) Test changelog modification',
type: 'changed'
}
]

expect(extractEntriesFromMarkdown(txt)).toEqual(expectedOutput)
})

test('Extract multiple changelog entries from markdown with \r\n line breaks', async () => {
const txt = '## Description\r\n<!-- Please include a summary of the changes and the related issue. Please also include relevant context. -->\r\n\r\n## How Has This Been Tested?\r\n<!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration -->\r\n\r\n## Checklist:\r\n- [ ] My code is up to date with the development branch, i\'ve pulled in the latest changes\r\n- [ ] I\'ve added the build label to my PR\r\n\r\n## Changelog\r\n### Changed\r\n- [Hello](World) Hello world\r\n- [Hello](World) Hello world 2\r\n- [Hello](World) Hello world 3\r\nSomething that\'s not the correct format\r\n\r\n## Deprecated (incorrect)\r\n- [Hello](World) Incorrect deprecated change\r\n\r\n### Fixed\r\n- [A fix](www.vendic.nl) Fixed\r\n- A great fix!\r\n'
const expectedOutput : ChangelogEntry[] = [
Expand Down Expand Up @@ -141,3 +156,5 @@ test('Extract CHANGELOG section from pull request body', async () => {

expect(extractChangelogSection(fileContents)).toEqual(expectedResult)
})


4 changes: 3 additions & 1 deletion src/changelog_entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export function extractEntriesFromMarkdown(markdown : string) : ChangelogEntry[]
core.info('Extracting entries from markdown')
core.debug('Searching through:')
core.debug(markdown)
const themesContent = markdown.match(/###[^#]+/mg);

const patternStr = new RegExp("###(.*(?:(?:\\n|\\r\\n).+)*(?:\\n|\\r\\n)?)", "mg")
const themesContent = markdown.match(patternStr);

if (!Array.isArray(themesContent) || Array.isArray(themesContent) && themesContent.length === 0) {
return []
Expand Down

0 comments on commit 76e8c03

Please sign in to comment.