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

fix(changelog): type(scope) detection #69

Merged
merged 1 commit into from
Nov 9, 2020
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
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