diff --git a/changelog/next/2017-08-11T15:48:32.363Z_addition_all.yml b/changelog/next/2017-08-11T15:48:32.363Z_addition_all.yml new file mode 100644 index 0000000..66a0970 --- /dev/null +++ b/changelog/next/2017-08-11T15:48:32.363Z_addition_all.yml @@ -0,0 +1,6 @@ +dateTime: '2017-08-11T15:48:32.363Z' +component: all +kind: addition +description: >- + New entry kinds "Security", "Removed" & "Deprecated" from + [keepachangelog](http://keepachangelog.com/) diff --git a/src/api/getChangelogData.js b/src/api/getChangelogData.js index b7c9e8e..b27f238 100644 --- a/src/api/getChangelogData.js +++ b/src/api/getChangelogData.js @@ -18,6 +18,14 @@ import type { import { stringifyVersion } from './utils'; import getSortedChangelogVersions from './getSortedChangelogVersions'; +const entryKinds = [ + 'addition', + 'change', + 'fix', + 'removal', + 'deprecation', + 'security', +]; export default function getChangelogData( config: ConfigType @@ -36,9 +44,10 @@ function getVersionChangelog( return { version, entries: { - addition: [], - change: [], - fix: [], + ...entryKinds.reduce((kinds, entryKind) => ({ + ...kinds, + [entryKind]: [] + }), {}), ...groupBy(( getVersionChangelogFileNames(config, stringifyVersion(version)) .map((entryFileName) => readFileSync(entryFileName).toString()) diff --git a/src/templates/defaultTemplate.js b/src/templates/defaultTemplate.js index 641a7a4..d96eebf 100644 --- a/src/templates/defaultTemplate.js +++ b/src/templates/defaultTemplate.js @@ -11,7 +11,10 @@ import type { const entryKindToReadable = { change: 'Changed', addition: 'Added', - fix: 'Fixed' + fix: 'Fixed', + security: 'Security', + removal: 'Removed', + deprecation: 'Deprecated' }; export default function defaultTemplate( @@ -33,7 +36,9 @@ function renderVersionChangelog( return [ `## Version \`${helpers.stringifyVersion(version)}\``, - ...entryKeys.map((entryKind) => renderEntriesOfKind(helpers, entryKind, entries[entryKind])) + ...entryKeys.map( + (entryKind) => renderEntriesOfKind(helpers, entryKind, entries[entryKind]) + ).filter((entry) => entry) ].join('\n\n'); } diff --git a/src/types.js b/src/types.js index d6f9295..9f1c116 100644 --- a/src/types.js +++ b/src/types.js @@ -26,7 +26,7 @@ export type VersionType = { patch: number }; -export type EntryKindType = 'addition' | 'change' | 'fix'; +export type EntryKindType = 'addition' | 'change' | 'fix' | 'security' | 'removal' | 'deprecation'; export type EntryType = { component: ?string, diff --git a/test/specs/api/__snapshots__/generate.spec.js.snap b/test/specs/api/__snapshots__/generate.spec.js.snap index 3cb59fe..66c587b 100644 --- a/test/specs/api/__snapshots__/generate.spec.js.snap +++ b/test/specs/api/__snapshots__/generate.spec.js.snap @@ -5,30 +5,18 @@ exports[`generate returns proper markdown string 1`] = ` ## Version \`next\` - - - - ### Fixed - **Comp 2:** comp2 fix description ## Version \`1.1.0\` - - ### Changed - **Comp 1:** comp1 change description - - ## Version \`1.0.0\` ### Added -- **Comp 1:** comp1 addition description - - - -" +- **Comp 1:** comp1 addition description" `; exports[`generate when there are no configured components renders "All" for the entries with null as component 1`] = ` @@ -37,9 +25,5 @@ exports[`generate when there are no configured components renders "All" for the ## Version \`next\` ### Added -- addition to no specific component - - - -" +- addition to no specific component" `; diff --git a/test/specs/api/__snapshots__/getChangelogData.spec.js.snap b/test/specs/api/__snapshots__/getChangelogData.spec.js.snap index fd12567..789a2ba 100644 --- a/test/specs/api/__snapshots__/getChangelogData.spec.js.snap +++ b/test/specs/api/__snapshots__/getChangelogData.spec.js.snap @@ -6,6 +6,7 @@ Array [ "entries": Object { "addition": Array [], "change": Array [], + "deprecation": Array [], "fix": Array [ Object { "component": "comp2", @@ -14,6 +15,8 @@ Array [ "kind": "fix", }, ], + "removal": Array [], + "security": Array [], }, "version": null, }, @@ -28,7 +31,10 @@ Array [ "kind": "change", }, ], + "deprecation": Array [], "fix": Array [], + "removal": Array [], + "security": Array [], }, "version": Object { "major": 1, @@ -47,7 +53,10 @@ Array [ }, ], "change": Array [], + "deprecation": Array [], "fix": Array [], + "removal": Array [], + "security": Array [], }, "version": Object { "major": 1, diff --git a/test/specs/api/getChangelogData.spec.js b/test/specs/api/getChangelogData.spec.js index 0cb913d..bfb0908 100644 --- a/test/specs/api/getChangelogData.spec.js +++ b/test/specs/api/getChangelogData.spec.js @@ -68,4 +68,20 @@ describe('getChangelogData', () => { expect(additionEntries[2].component).toBe('comp3'); }); + describe('when there are no entries of a certain kind', () => { + + it('returns an empty array for that kind', () => { + const changelogAPI = setup(); + + changelogAPI.addEntry({ + component: 'comp1', + kind: 'removal', + description: 'some removal description' + }); + + expect(changelogAPI.getChangelogData()[0].entries.deprecation).toEqual([]); + }); + + }); + });