feat: support pipe characters in github names (#39)

This commit is contained in:
Chris Vickery 2017-04-07 06:52:55 -07:00 committed by Kent C. Dodds
parent 99db1bda78
commit e1e7ead47a
3 changed files with 28 additions and 2 deletions

View file

@ -18,5 +18,14 @@
"contributions": [
"review"
]
},
"pipey": {
"login": "pipey",
"name": "Who | Needs | Pipes?",
"profile": "http://github.com/chrisinajar",
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
"contributions": [
"doc"
]
}
}

View file

@ -4,17 +4,25 @@ var _ = require('lodash/fp');
var formatContributionType = require('./format-contribution-type');
var avatarTemplate = _.template('<img src="<%= contributor.avatar_url %>" width="<%= options.imageSize %>px;"/>');
var avatarBlockTemplate = _.template('[<%= avatar %><br /><sub><%= contributor.name %></sub>](<%= contributor.profile %>)');
var avatarBlockTemplate = _.template('[<%= avatar %><br /><sub><%= name %></sub>](<%= contributor.profile %>)');
var contributorTemplate = _.template('<%= avatarBlock %><br /><%= contributions %>');
var defaultImageSize = 100;
function defaultTemplate(templateData) {
var avatar = avatarTemplate(templateData);
var avatarBlock = avatarBlockTemplate(_.assign({avatar: avatar}, templateData));
var avatarBlock = avatarBlockTemplate(_.assign({
name: escapeName(templateData.contributor.name),
avatar: avatar
}, templateData));
return contributorTemplate(_.assign({avatarBlock: avatarBlock}, templateData));
}
function escapeName(name) {
return name.replace(new RegExp('\\|', 'g'), '&#124;');
}
module.exports = function formatContributor(options, contributor) {
var formatter = _.partial(formatContributionType, [options, contributor]);
var contributions = contributor.contributions

View file

@ -49,3 +49,12 @@ test('should default image size to 100', t => {
t.is(formatContributor(options, contributor), expected);
});
test('should format contributor with pipes in their name', t => {
const contributor = contributors.pipey;
const {options} = fixtures();
const expected = '[<img src="https://avatars1.githubusercontent.com/u/1500684" width="150px;"/><br /><sub>Who &#124; Needs &#124; Pipes?</sub>](http://github.com/chrisinajar)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=pipey)';
t.is(formatContributor(options, contributor), expected);
});