Skip to content

Commit

Permalink
Convert custom labels to Map
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Mar 9, 2018
1 parent 67121ed commit d6b8db9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ function stripTrailingEmptyLine(text) {
}

function getValidLabels(prLogConfig) {
return prLogConfig && prLogConfig.validLabels || defaultValidLabels;
if (prLogConfig && prLogConfig.validLabels) {
return new Map(prLogConfig.validLabels);
}

return defaultValidLabels;
}

function validateVersionnumber(versionNumber) {
Expand Down
7 changes: 4 additions & 3 deletions test/unit/lib/cliSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ test('does not throw if the repository is dirty', async (t) => {
test('uses custom labels if they are provided in package.json', async (t) => {
const packageInfo = {
repository: { url: 'https://github.com/foo/bar.git' },
'pr-log': { validLabels: { foo: 'Foo', bar: 'Bar' } }
'pr-log': { validLabels: [ [ 'foo', 'Foo' ], [ 'bar', 'Bar' ] ] }
};
const expectedLabels = new Map([ [ 'foo', 'Foo' ], [ 'bar', 'Bar' ] ]);
const createChangelog = sinon.stub().returns('generated changelog');
const getMergedPullRequests = sinon.stub().resolves();
const cli = createCli({ packageInfo, createChangelog, getMergedPullRequests });

await cli.run('1.0.0', options);

t.is(getMergedPullRequests.callCount, 1);
t.deepEqual(getMergedPullRequests.firstCall.args, [ 'foo/bar', { foo: 'Foo', bar: 'Bar' } ]);
t.deepEqual(getMergedPullRequests.firstCall.args, [ 'foo/bar', expectedLabels ]);

t.is(createChangelog.callCount, 1);
t.deepEqual(createChangelog.firstCall.args, [ '1.0.0', { foo: 'Foo', bar: 'Bar' }, undefined, 'foo/bar' ]);
t.deepEqual(createChangelog.firstCall.args, [ '1.0.0', expectedLabels, undefined, 'foo/bar' ]);
});

test('reports the generated changelog', async (t) => {
Expand Down

0 comments on commit d6b8db9

Please sign in to comment.