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

Add missing entry kinds from keepachangelog #10

Merged
merged 2 commits into from
Aug 14, 2017
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
6 changes: 6 additions & 0 deletions changelog/next/2017-08-11T15:48:32.363Z_addition_all.yml
Original file line number Diff line number Diff line change
@@ -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/)
15 changes: 12 additions & 3 deletions src/api/getChangelogData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down
9 changes: 7 additions & 2 deletions src/templates/defaultTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 2 additions & 18 deletions test/specs/api/__snapshots__/generate.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand All @@ -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"
`;
9 changes: 9 additions & 0 deletions test/specs/api/__snapshots__/getChangelogData.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Array [
"entries": Object {
"addition": Array [],
"change": Array [],
"deprecation": Array [],
"fix": Array [
Object {
"component": "comp2",
Expand All @@ -14,6 +15,8 @@ Array [
"kind": "fix",
},
],
"removal": Array [],
"security": Array [],
},
"version": null,
},
Expand All @@ -28,7 +31,10 @@ Array [
"kind": "change",
},
],
"deprecation": Array [],
"fix": Array [],
"removal": Array [],
"security": Array [],
},
"version": Object {
"major": 1,
Expand All @@ -47,7 +53,10 @@ Array [
},
],
"change": Array [],
"deprecation": Array [],
"fix": Array [],
"removal": Array [],
"security": Array [],
},
"version": Object {
"major": 1,
Expand Down
16 changes: 16 additions & 0 deletions test/specs/api/getChangelogData.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});

});

});