mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
feat: support pipe characters in github names (#39)
This commit is contained in:
parent
99db1bda78
commit
e1e7ead47a
3 changed files with 28 additions and 2 deletions
|
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'), '|');
|
||||
}
|
||||
|
||||
module.exports = function formatContributor(options, contributor) {
|
||||
var formatter = _.partial(formatContributionType, [options, contributor]);
|
||||
var contributions = contributor.contributions
|
||||
|
|
|
@ -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 | Needs | Pipes?</sub>](http://github.com/chrisinajar)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=pipey)';
|
||||
|
||||
t.is(formatContributor(options, contributor), expected);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue