github-username
Advanced tools
Comparing version 4.0.0 to 4.1.0
26
index.js
'use strict'; | ||
const ghGot = require('gh-got'); | ||
function searchCommits(email, token) { | ||
return ghGot('search/commits', { | ||
token, | ||
query: { | ||
q: `author-email:${email}`, | ||
sort: 'author-date', | ||
// eslint-disable-next-line camelcase | ||
per_page: 1 | ||
}, | ||
headers: { | ||
accept: 'application/vnd.github.cloak-preview', | ||
'user-agent': 'https://github.com/sindresorhus/github-username' | ||
} | ||
}).then(result => { | ||
const data = result.body; | ||
if (data.total_count === 0) { | ||
throw new Error(`Couldn't find username for \`${email}\``); | ||
} | ||
return data.items[0].author.login; | ||
}); | ||
} | ||
module.exports = (email, token) => { | ||
@@ -21,3 +45,3 @@ if (!(typeof email === 'string' && email.includes('@'))) { | ||
if (data.total_count === 0) { | ||
throw new Error(`Couldn't find username for \`${email}\``); | ||
return searchCommits(email, token); | ||
} | ||
@@ -24,0 +48,0 @@ |
{ | ||
"name": "github-username", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Get a GitHub username from an email address", | ||
@@ -31,3 +31,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"gh-got": "^5.0.0" | ||
"gh-got": "^6.0.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "devDependencies": { |
@@ -5,9 +5,7 @@ # github-username [](https://travis-ci.org/sindresorhus/github-username) | ||
*Only works for users that have their email publicly listed on their profile.* | ||
## Install | ||
``` | ||
$ npm install --save github-username | ||
$ npm install github-username | ||
``` | ||
@@ -42,3 +40,3 @@ | ||
Type: `string` | ||
Type: `string` | ||
@@ -45,0 +43,0 @@ GitHub [personal access token](https://github.com/settings/tokens/new). |
Sorry, the diff of this file is not supported yet
3739
43
52
+ Addeddecompress-response@3.3.0(transitive)
+ Addedgh-got@6.0.0(transitive)
+ Addedgot@7.1.0(transitive)
+ Addedhas-symbol-support-x@1.4.2(transitive)
+ Addedhas-to-string-tag-x@1.4.1(transitive)
+ Addedis-object@1.0.2(transitive)
+ Addedisurl@1.0.0(transitive)
+ Addedmimic-response@1.0.1(transitive)
+ Addedp-cancelable@0.3.0(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-timeout@1.2.1(transitive)
+ Addedurl-to-options@1.0.1(transitive)
- Removedcapture-stack-trace@1.0.2(transitive)
- Removedcreate-error-class@3.0.2(transitive)
- Removedgh-got@5.0.0(transitive)
- Removedgot@6.7.1(transitive)
- Removedis-redirect@1.0.0(transitive)
- Removedunzip-response@2.0.1(transitive)
Updatedgh-got@^6.0.0