Skip to content

Commit

Permalink
fix: non-http prepended urls (#35)
Browse files Browse the repository at this point in the history
* Add editor config

* Fix non-http prepended urls

* Remove editorconfig

* Use startsWith and shorthand operator
  • Loading branch information
alexjoverm authored and Kent C. Dodds committed Feb 23, 2017
1 parent 1305a7c commit a879de2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/contributors/github.js
Expand Up @@ -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
};
});
};
16 changes: 16 additions & 0 deletions lib/contributors/github.test.js
Expand Up @@ -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');
});
});

0 comments on commit a879de2

Please sign in to comment.