Skip to content

Commit

Permalink
feat: support pipe characters in github names (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisinajar authored and Kent C. Dodds committed Apr 7, 2017
1 parent 99db1bd commit e1e7ead
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/generate/fixtures/contributors.json
Expand Up @@ -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"
]
}
}
12 changes: 10 additions & 2 deletions lib/generate/format-contributor.js
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions lib/generate/format-contributor.test.js
Expand Up @@ -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);
});

0 comments on commit e1e7ead

Please sign in to comment.