Skip to content

Commit

Permalink
fix(changelog): type(scope) detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Richter committed Nov 7, 2020
1 parent 655d574 commit 5045808
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ The default emojis for the commit types are:
"style": "💅",
// internal types
"deps": "🔼", // will be set when dependencies are found in PR commit subject
"dep": "🔼", // will be set when dependencies are found in PR commit subject
"internal": "🏡", // will be set for types: "chore", "build", "test", "ci" or commits without type
}
Expand Down
10 changes: 5 additions & 5 deletions lib/steps/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function getTypeCategory(type, options) {
descr = 'Bug Fixes';
break;

case 'dep':
case 'deps':
descr = 'Dependencies';
break;

Expand Down Expand Up @@ -172,7 +172,7 @@ function sortByType(data) {
'perf',
'refactor',
'fix',
'dep',
'deps',
'revert',
'style',
'docs',
Expand All @@ -195,10 +195,10 @@ function sortByType(data) {
* @return {string}
*/
function getType(title) {
const match = title.match(/^(\w+):/);
const match = title.match(/^(\w+)[:(]/);
let type = match && match[1];
if (findDependency(title)) {
type = 'dep';
if (findDependency(title) && type === 'chore') {
type = 'deps';
}
return type || 'internal';
}
Expand Down
113 changes: 60 additions & 53 deletions test/steps/changelog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ describe('generateChangeLog', () => {
{ headline: 'Code Refactoring', prefixes: ['refactor'] },
{ headline: 'Bug Fixes', prefixes: ['fix'] },
{ headline: 'Performance Improvements', prefixes: ['perf'] },
{ headline: 'Dependencies', prefixes: ['dep'] },
{ headline: 'Dependencies', prefixes: ['deps'] },
{ headline: 'Documentation', prefixes: ['docs'] },
{ headline: 'Polish', prefixes: ['style'] },
{ headline: 'Reverts', prefixes: ['revert'] },
Expand Down Expand Up @@ -629,7 +629,7 @@ describe('generateChangeLog', () => {
}
});

it('identifies & highlights dependency updates in commit subject and groups them into "Dependencies" category', async () => {
it('identifies & highlights dependency updates in commit subject and groups them into "Dependencies" category for type "chore"', async () => {
function removeBackticks(str) {
return str.replace(/`/g, '');
}
Expand All @@ -648,34 +648,40 @@ describe('generateChangeLog', () => {
];

for (const subject of subjectCases) {
const commits = [
{
sha: '1234567890123456789012345678901234567890',
type: 'fix',
subject: Array.isArray(subject) ? subject.join(' ') : subject,
},
];
const options = {
...defaultOptions,
commits,
};
const href = `https://github.com/usr/proj/commit/${commits[0].sha}`;
const expectedEntries = [
`* [\`1234567\`](${href}) fix: \`${
Array.isArray(subject)
? subject.map(removeBackticks).join('` `')
: removeBackticks(subject)
}\``,
];

const changelog = await generateChangeLog(
null,
pkg,
options
).then(res => res.split('\n'));

const index = assertEntries(changelog, expectedEntries);
assert.strictEqual(changelog[index - 2], '#### Dependencies');
for (const type of ['chore', 'fix']) {
const commits = [
{
sha: '1234567890123456789012345678901234567890',
type,
subject: Array.isArray(subject) ? subject.join(' ') : subject,
},
];
const options = {
...defaultOptions,
commits,
};
const href = `https://github.com/usr/proj/commit/${commits[0].sha}`;

const expectedEntries = [
`* [\`1234567\`](${href}) ${type}: \`${
Array.isArray(subject)
? subject.map(removeBackticks).join('` `')
: removeBackticks(subject)
}\``,
];

const changelog = await generateChangeLog(
null,
pkg,
options
).then(res => res.split('\n'));

const index = assertEntries(changelog, expectedEntries);
assert.strictEqual(
changelog[index - 2],
`#### ${type === 'chore' ? 'Dependencies' : 'Bug Fixes'}`
);
}
}
});
});
Expand Down Expand Up @@ -719,42 +725,43 @@ describe('generateChangeLog', () => {
{ headline: 'Code Refactoring', prefixes: ['refactor'] },
{ headline: 'Bug Fixes', prefixes: ['fix'] },
{ headline: 'Performance Improvements', prefixes: ['perf'] },
{ headline: 'Dependencies', prefixes: ['dep'] },
{ headline: 'Dependencies', prefixes: ['deps'] },
{ headline: 'Documentation', prefixes: ['docs'] },
{ headline: 'Polish', prefixes: ['style'] },
{ headline: 'Reverts', prefixes: ['revert'] },
{
headline: 'Internal',
prefixes: ['ci', 'test', 'build', 'chore'],
emoji_id: 'internal',
},
];

const headlineLevel = '####';
const href0 = `https://github.com/usr/proj/commit/${defaultCommit.sha}`;

const emojiMaps = generateChangeLog.emojiMaps.get('default');
for (const { headline, prefixes } of testCases) {
for (const prefix of prefixes) {
const expectedEntries = [
`* [\`1234567\`](${href0}) ${prefix}: something`,
];

changelog = await generateChangeLog(
null,
{ repository: 'usr/proj' },
{
commits: [{ ...defaultCommit, type: prefix }],
}
);
const lines = changelog.split('\n');

const indices = assertEntries(changelog, expectedEntries);
assert.strictEqual(
lines[indices[0] - 2],
`${headlineLevel} ${
emojiMaps[prefix] || emojiMaps['internal']
} ${headline}`
);
for (const { headline, prefixes, emoji_id } of testCases) {
for (const scope of ['', '(test)']) {
for (const prefix of prefixes) {
const expectedEntries = [
`* [\`1234567\`](${href0}) ${prefix}${scope}: something`,
];

changelog = await generateChangeLog(
null,
{ repository: 'usr/proj' },
{
commits: [{ ...defaultCommit, type: prefix + scope }],
}
);
const lines = changelog.split('\n');

const indices = assertEntries(changelog, expectedEntries);
assert.strictEqual(
lines[indices[0] - 2],
`${headlineLevel} ${emojiMaps[emoji_id || prefix]} ${headline}`
);
}
}
}
});
Expand Down

0 comments on commit 5045808

Please sign in to comment.