Skip to content

Commit

Permalink
Release v3.11.1 (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangoslen authored Dec 29, 2024
1 parent c131cb1 commit a841dcd
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 73 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [UNRELEASED]

## [3.11.1]

### Fixed
- Corrects the regex introduced in [3.11.0](https://github.com/dangoslen/dependabot-changelog-helper/releases/tag/v3.11.0) to correct reading too many entries ([#278](https://github.com/dangoslen/dependabot-changelog-helper/issues/278))
- Corrects adding a newline after the first entry in multi-package updates ([#308](https://github.com/dangoslen/dependabot-changelog-helper/issues/308))

## [3.11.0]

### Fixed
Expand Down
123 changes: 100 additions & 23 deletions __tests__/changelog-updater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const CHANGELOG_WITH_PROPER_SECTIONS_AND_ENTRIES_GETS_SORTED = `# Changelog
## [v1.0.0]
### Dependencies
- Bump \`different-package\` from v1 to v2
- Bump \`xyz\` from v1 to v2`
- Bump \`xyz\` from v1 to v2
`

test('adds an entry to the changelog and it gets sorted', async () => {
mockReadStream(CHANGELOG_WITH_PROPER_SECTIONS_AND_ENTRIES_GETS_SORTED)
Expand All @@ -33,15 +34,17 @@ test('adds an entry to the changelog and it gets sorted', async () => {
### Dependencies
- Bump \`different-package\` from v1 to v2
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
- Bump \`xyz\` from v1 to v2`)
- Bump \`xyz\` from v1 to v2
`)
})

const CHANGELOG_WITH_PROPER_SECTIONS_AND_ENTRIES_NOT_SORTED = `# Changelog
## [v1.0.0]
### Dependencies
- Bump \`different-package\` from v1 to v2
- Bump \`xyz\` from v1 to v2`
- Bump \`xyz\` from v1 to v2
`

test('adds an entry to the changelog and it does not get sorted', async () => {
mockReadStream(CHANGELOG_WITH_PROPER_SECTIONS_AND_ENTRIES_NOT_SORTED)
Expand All @@ -54,14 +57,16 @@ test('adds an entry to the changelog and it does not get sorted', async () => {
### Dependencies
- Bump \`different-package\` from v1 to v2
- Bump \`xyz\` from v1 to v2
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))`)
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
`)
})

const CHANGELOG_WITH_PROPER_SECTIONS_AND_ENTRIES = `# Changelog
## [v1.0.0]
### Dependencies
- Bump \`different-package\` from v1 to v2`
- Bump \`different-package\` from v1 to v2
`

test('adds an entry to the changelog when section already exists with section', async () => {
mockReadStream(CHANGELOG_WITH_PROPER_SECTIONS_AND_ENTRIES)
Expand All @@ -73,14 +78,16 @@ test('adds an entry to the changelog when section already exists with section',
## [v1.0.0]
### Dependencies
- Bump \`different-package\` from v1 to v2
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))`)
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
`)
})

const CHANGELOG_WITH_PROPER_SECTIONS_AND_ENTRIES_UNRELEASED = `# Changelog
## [UNRELEASED]
### Dependencies
- Bump \`different-package\` from v1 to v2`
- Bump \`different-package\` from v1 to v2
`

test('adds an entry to the changelog when section exists under default unreleased version', async () => {
mockReadStream(CHANGELOG_WITH_PROPER_SECTIONS_AND_ENTRIES_UNRELEASED)
Expand All @@ -92,15 +99,17 @@ test('adds an entry to the changelog when section exists under default unrelease
## [UNRELEASED]
### Dependencies
- Bump \`different-package\` from v1 to v2
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))`)
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
`)
})

const CHANGELOG_WITH_PROPER_SECTIONS_UNRELEASED = `# Changelog
## [UNRELEASED]
### Dependencies`
### Dependencies
`

test('adds an entry to the changelog when section already exists, but no entry', async () => {
test('adds an entry to the changelog when section already exists but no entries doe', async () => {
mockReadStream(CHANGELOG_WITH_PROPER_SECTIONS_UNRELEASED)

await runUpdate('v1.0.0', './CHANGELOG.md', 'Bump', 'Dependencies')
Expand All @@ -109,12 +118,14 @@ test('adds an entry to the changelog when section already exists, but no entry',
## [UNRELEASED]
### Dependencies
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))`)
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
`)
})

const CHANGELOG_MISSING_DEPENDENCIES = `# Changelog
## [UNRELEASED]`
## [UNRELEASED]
`

test('adds section and an entry to the changelog when version exists but section does not', async () => {
const readable = Readable.from([CHANGELOG_MISSING_DEPENDENCIES])
Expand All @@ -127,7 +138,8 @@ test('adds section and an entry to the changelog when version exists but section
## [UNRELEASED]
### Changed
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))`)
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
`)
})

const CHANGELOG_WITH_MULTIPLE_VERSIONS = `# Changelog
Expand Down Expand Up @@ -500,7 +512,8 @@ const CHANGELOG_WITH_EXISTING_SECTION_BETWEEN_OTHERS = `# Changelog
## [v0.9.0]
### Dependencies
- Bump \`package\` from alpha to v1`
- Bump \`package\` from alpha to v1
`

test('updates existing section when between other sections', async () => {
mockReadStream(CHANGELOG_WITH_EXISTING_SECTION_BETWEEN_OTHERS)
Expand All @@ -525,15 +538,17 @@ test('updates existing section when between other sections', async () => {
## [v0.9.0]
### Dependencies
- Bump \`package\` from alpha to v1`
- Bump \`package\` from alpha to v1
`
)
})

const CHANGELOG_WITH_PROPER_SECTIONS_AND_ENTRIES_DIFFERENT_PREFIX = `# Changelog
## [v1.0.0]
### Dependencies
- Bump \`different-package\` from v1 to v2`
- Bump \`different-package\` from v1 to v2
`

test('adds an entry with a different prefix to the changelog when section already exists with entry', async () => {
mockReadStream(CHANGELOG_WITH_PROPER_SECTIONS_AND_ENTRIES_DIFFERENT_PREFIX)
Expand All @@ -545,14 +560,16 @@ test('adds an entry with a different prefix to the changelog when section alread
## [v1.0.0]
### Dependencies
- Bump \`different-package\` from v1 to v2
- Update \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))`)
- Update \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
`)
})

const CHANGELOG_WITH_DUPLICATE_ENTRY_DIFFERENT_PREFIX = `# Changelog
## [v1.0.0]
### Dependencies
- Bump \`package\` from v1 to v2`
- Bump \`package\` from v1 to v2
`

test('keeps prefix on entry with a different prefix but is otherwise a duplicate', async () => {
mockReadStream(CHANGELOG_WITH_DUPLICATE_ENTRY_DIFFERENT_PREFIX)
Expand All @@ -563,14 +580,16 @@ test('keeps prefix on entry with a different prefix but is otherwise a duplicate
## [v1.0.0]
### Dependencies
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))`)
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
`)
})

const CHANGELOG_WITH_EXISTING_ENTRY_DIFFERENT_PREFIX = `# Changelog
## [v1.0.0]
### Dependencies
- Bump \`package\` from v1 to v1.1`
- Bump \`package\` from v1 to v1.1
`

test('keeps prefix on entry with a different prefix', async () => {
mockReadStream(CHANGELOG_WITH_EXISTING_ENTRY_DIFFERENT_PREFIX)
Expand All @@ -581,7 +600,8 @@ test('keeps prefix on entry with a different prefix', async () => {
## [v1.0.0]
### Dependencies
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))`)
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
`)
})

const CHANGELOG_WITH_MULTI_LINE_ENTRY_NO_DEPENDENCY_SECTION = `# Changelog
Expand Down Expand Up @@ -645,12 +665,67 @@ test('updates section with an entry and accounts for multi-line entry', async ()
`)
})

const CHANGELOG_WITHOUT_EXISTING_SECTION_AND_SEPARATED_SECTIONS_ADDS_MULTI_PACKAGE_UPDATE = `# Changelog
## [v1.0.0]
### Added
- Added a new feature
### Removed
- Removed a feature
## [v0.9.0]
### Dependencies
- Bump \`package\` from alpha to v1
`

test('adds section when sections separated by blank lines and adds multi package updates properly', async () => {
mockReadStream(
CHANGELOG_WITHOUT_EXISTING_SECTION_AND_SEPARATED_SECTIONS_ADDS_MULTI_PACKAGE_UPDATE
)

await runUpdate('v1.0.0', './CHANGELOG.md', 'Bump', 'Dependencies', 'none', [
{
pullRequestNumber: 123,
repository: 'owner/repo',
package: 'other-package',
newVersion: 'v2',
oldVersion: 'v1'
}
])

expectWrittenChangelogToBe(
`# Changelog
## [v1.0.0]
### Added
- Added a new feature
### Removed
- Removed a feature
### Dependencies
- Bump \`package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
- Bump \`other-package\` from v1 to v2 ([#123](https://github.com/owner/repo/pull/123))
## [v0.9.0]
### Dependencies
- Bump \`package\` from alpha to v1
`
)
})

async function runUpdate(
version: string,
changelogPath: PathLike,
entryPrefix: string,
sectionHeader: string,
sort: string = 'none'
sort: string = 'none',
additionalEntries: VersionEntry[] = []
): Promise<void> {
const updater = new DefaultChangelogUpdater(
version,
Expand All @@ -659,8 +734,10 @@ async function runUpdate(
sectionHeader,
sort
)

const entries = [PACKAGE_ENTRY, ...additionalEntries]
await updater.readChangelog()
await updater.updateChangelog(PACKAGE_ENTRY)
await updater.addEntries(entries)
await updater.writeChangelog()
}

Expand Down
40 changes: 22 additions & 18 deletions __tests__/dependabot-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('run', () => {

const mockUpdater = {
readChangelog: jest.fn(),
updateChangelog: jest.fn(),
addEntries: jest.fn(),
writeChangelog: jest.fn()
}

Expand Down Expand Up @@ -46,13 +46,15 @@ describe('run', () => {
run().then(() => {
expect(mockUpdater.readChangelog).toHaveBeenCalled()
expect(mockExtractor.getEntries).toHaveBeenCalled()
expect(mockUpdater.updateChangelog).toHaveBeenCalledWith({
pullRequestNumber: 123,
repository: 'repo',
package: 'package',
oldVersion: 'v2',
newVersion: 'v3'
})
expect(mockUpdater.addEntries).toHaveBeenCalledWith([
{
pullRequestNumber: 123,
repository: 'repo',
package: 'package',
oldVersion: 'v2',
newVersion: 'v3'
}
])
expect(mockUpdater.writeChangelog).toHaveBeenCalled()
expect(core.setFailed).not.toHaveBeenCalled()
})
Expand All @@ -63,7 +65,7 @@ describe('run', () => {

const mockUpdater = {
readChangelog: jest.fn(),
updateChangelog: jest.fn(),
addEntries: jest.fn(),
writeChangelog: jest.fn()
}

Expand All @@ -85,7 +87,7 @@ describe('run', () => {
run().then(() => {
expect(mockUpdater.readChangelog).not.toHaveBeenCalled()
expect(mockExtractor.getEntries).not.toHaveBeenCalled()
expect(mockUpdater.updateChangelog).not.toHaveBeenCalled()
expect(mockUpdater.addEntries).not.toHaveBeenCalled()
expect(mockUpdater.writeChangelog).not.toHaveBeenCalled()
expect(core.setFailed).not.toHaveBeenCalled()
})
Expand All @@ -96,7 +98,7 @@ describe('run', () => {

const mockUpdater = {
readChangelog: jest.fn(),
updateChangelog: jest.fn(),
addEntries: jest.fn(),
writeChangelog: jest.fn()
}

Expand Down Expand Up @@ -126,13 +128,15 @@ describe('run', () => {
run().then(() => {
expect(mockUpdater.readChangelog).toHaveBeenCalled()
expect(mockExtractor.getEntries).toHaveBeenCalled()
expect(mockUpdater.updateChangelog).toHaveBeenCalledWith({
pullRequestNumber: 123,
repository: 'repo',
package: 'package',
oldVersion: 'v2',
newVersion: 'v3'
})
expect(mockUpdater.addEntries).toHaveBeenCalledWith([
{
pullRequestNumber: 123,
repository: 'repo',
package: 'package',
oldVersion: 'v2',
newVersion: 'v3'
}
])
expect(mockUpdater.writeChangelog).toHaveBeenCalled()
expect(core.setFailed).not.toHaveBeenCalled()
})
Expand Down
5 changes: 3 additions & 2 deletions __tests__/entry-extractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ const PULL_REQUEST_WITH_COMMITS_IN_BODY = {
Changelog
Commits
* Updates \`dep\` from a to b
<li>Updates \`dep\` from a to b</li>
<li>Bumps \`dep\` from a to b</li>
`
}
}
Expand Down Expand Up @@ -232,7 +233,7 @@ describe('the dependabot extractor', () => {
expect(entry.newVersion).toStrictEqual('3.12.3')
})

test('extracts multiple entries from body', async () => {
test('extracts multiple entries from body, skipping commits in a list', async () => {
const entries = extractor.getEntries(PULL_REQUEST_WITH_COMMITS_IN_BODY)

expect(entries).toHaveLength(1)
Expand Down
2 changes: 1 addition & 1 deletion coverage/badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a841dcd

Please sign in to comment.