diff --git a/lib/contributors/github.js b/lib/contributors/github.js index 3c6a1404..0e77ac48 100644 --- a/lib/contributors/github.js +++ b/lib/contributors/github.js @@ -12,11 +12,14 @@ module.exports = function getUserInfo(username) { }) .then(res => { var body = JSON.parse(res.body); + var profile = body.blog || body.html_url; + profile = profile.startsWith('http') ? profile : 'http://' + profile; + return { login: body.login, name: body.name || username, avatar_url: body.avatar_url, - profile: body.blog || body.html_url + profile }; }); }; diff --git a/lib/contributors/github.test.js b/lib/contributors/github.test.js index 0ddbaedf..c3df530b 100644 --- a/lib/contributors/github.test.js +++ b/lib/contributors/github.test.js @@ -41,3 +41,19 @@ test('should fill in the name when an empty string is returned', t => { t.is(info.name, 'nodisplayname'); }); }); + +test('should append http when no absolute link is provided', t => { + nock('https://api.github.com') + .get('/users/nodisplayname') + .reply(200, { + login: 'nodisplayname', + name: '', + avatar_url: 'https://avatars2.githubusercontent.com/u/3869412?v=3&s=400', + html_url: 'www.github.com/nodisplayname' + }); + + return getUserInfo('nodisplayname') + .then(info => { + t.is(info.profile, 'http://www.github.com/nodisplayname'); + }); +});