diff --git a/index.js b/index.js index 831d55a..f1c93b3 100644 --- a/index.js +++ b/index.js @@ -1,23 +1,14 @@ 'use strict'; -const ghGot = require('gh-got'); - -async function searchCommits(email, token) { - const result = await 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' - } +const {Octokit} = require('@octokit/rest'); + +async function searchCommits(octokit, email) { + const {data} = await octokit.search.commits({ + q: `author-email:${email}`, + sort: 'author-date', + // eslint-disable-next-line camelcase + per_page: 1 }); - const {body: data} = result; - if (data.total_count === 0) { throw new Error(`Couldn't find username for \`${email}\``); } @@ -30,20 +21,17 @@ module.exports = async (email, token) => { throw new Error('Email required'); } - const result = await ghGot('search/users', { - token, - query: { - q: `${email} in:email` - }, - headers: { - 'user-agent': 'https://github.com/sindresorhus/github-username' - } + const octokit = new Octokit({ + auth: token, + userAgent: 'https://github.com/sindresorhus/github-username' }); - const {body: data} = result; + const {data} = await octokit.search.users({ + q: `${email} in:email` + }); if (data.total_count === 0) { - return searchCommits(email, token); + return searchCommits(octokit, email); } return data.items[0].login; diff --git a/package.json b/package.json index c0d7cae..f54e7d5 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "git" ], "dependencies": { - "gh-got": "^8.1.0" + "@octokit/rest": "^18.0.6" }, "devDependencies": { "ava": "^1.4.1",