feat: allow author login/name to work in commit message templates #3793 (#3794)

This commit is contained in:
Max Metral
2020-05-25 02:36:35 -04:00
committed by GitHub
parent c28cc0c9e7
commit 2ecafd3354
3 changed files with 56 additions and 8 deletions

View File

@ -113,6 +113,50 @@ describe('formatters', () => {
).toEqual('Custom commit message');
});
it('should use empty values if "authorLogin" and "authorName" are missing in commit message', () => {
config.getIn.mockReturnValueOnce(
Map({
update: '{{author-login}} - {{author-name}}: Create {{collection}} “{{slug}}”',
}),
);
expect(
commitMessageFormatter(
'update',
config,
{
slug: 'doc-slug',
path: 'file-path',
collection,
},
true,
),
).toEqual(' - : Create Collection “doc-slug”');
});
it('should return custom create message with author information', () => {
config.getIn.mockReturnValueOnce(
Map({
create: '{{author-login}} - {{author-name}}: Create {{collection}} “{{slug}}”',
}),
);
expect(
commitMessageFormatter(
'create',
config,
{
slug: 'doc-slug',
path: 'file-path',
collection,
authorLogin: 'user-login',
authorName: 'Test User',
},
true,
),
).toEqual('user-login - Test User: Create Collection “doc-slug”');
});
it('should return custom open authoring message', () => {
config.getIn.mockReturnValueOnce(
Map({

View File

@ -57,6 +57,10 @@ export const commitMessageFormatter = (
return path || '';
case 'collection':
return collection ? collection.get('label_singular') || collection.get('label') : '';
case 'author-login':
return authorLogin || '';
case 'author-name':
return authorName || '';
default:
console.warn(`Ignoring unknown variable “${variable}” in commit message template.`);
return '';