Skip to content

Commit e1e7ead

Browse files
chrisinajarKent C. Dodds
authored andcommitted
feat: support pipe characters in github names (#39)
1 parent 99db1bd commit e1e7ead

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

lib/generate/fixtures/contributors.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,14 @@
1818
"contributions": [
1919
"review"
2020
]
21+
},
22+
"pipey": {
23+
"login": "pipey",
24+
"name": "Who | Needs | Pipes?",
25+
"profile": "http://github.com/chrisinajar",
26+
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
27+
"contributions": [
28+
"doc"
29+
]
2130
}
2231
}

lib/generate/format-contributor.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ var _ = require('lodash/fp');
44
var formatContributionType = require('./format-contribution-type');
55

66
var avatarTemplate = _.template('<img src="<%= contributor.avatar_url %>" width="<%= options.imageSize %>px;"/>');
7-
var avatarBlockTemplate = _.template('[<%= avatar %><br /><sub><%= contributor.name %></sub>](<%= contributor.profile %>)');
7+
var avatarBlockTemplate = _.template('[<%= avatar %><br /><sub><%= name %></sub>](<%= contributor.profile %>)');
88
var contributorTemplate = _.template('<%= avatarBlock %><br /><%= contributions %>');
99

1010
var defaultImageSize = 100;
1111

1212
function defaultTemplate(templateData) {
1313
var avatar = avatarTemplate(templateData);
14-
var avatarBlock = avatarBlockTemplate(_.assign({avatar: avatar}, templateData));
14+
var avatarBlock = avatarBlockTemplate(_.assign({
15+
name: escapeName(templateData.contributor.name),
16+
avatar: avatar
17+
}, templateData));
18+
1519
return contributorTemplate(_.assign({avatarBlock: avatarBlock}, templateData));
1620
}
1721

22+
function escapeName(name) {
23+
return name.replace(new RegExp('\\|', 'g'), '&#124;');
24+
}
25+
1826
module.exports = function formatContributor(options, contributor) {
1927
var formatter = _.partial(formatContributionType, [options, contributor]);
2028
var contributions = contributor.contributions

lib/generate/format-contributor.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,12 @@ test('should default image size to 100', t => {
4949

5050
t.is(formatContributor(options, contributor), expected);
5151
});
52+
53+
test('should format contributor with pipes in their name', t => {
54+
const contributor = contributors.pipey;
55+
const {options} = fixtures();
56+
57+
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)';
58+
59+
t.is(formatContributor(options, contributor), expected);
60+
});

0 commit comments

Comments
 (0)