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

Support pipe characters in github names #39

Merged
merged 1 commit into from
Apr 7, 2017
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
9 changes: 9 additions & 0 deletions lib/generate/fixtures/contributors.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
});