From a879de2a7fe4386da7e3e29c1b3fceb146da6354 Mon Sep 17 00:00:00 2001 From: Alex Jover Date: Thu, 23 Feb 2017 20:02:55 +0100 Subject: [PATCH] fix: non-http prepended urls (#35) * Add editor config * Fix non-http prepended urls * Remove editorconfig * Use startsWith and shorthand operator --- lib/contributors/github.js | 5 ++++- lib/contributors/github.test.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/contributors/github.js b/lib/contributors/github.js index 3c6a140..0e77ac4 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 0ddbaed..c3df530 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'); + }); +});