Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#PIPE-3 - Added testcase and fixed code to work for parsing numbers to the changelog #5

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading