Skip to content

Commit

Permalink
Migrate to latest octokit
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jun 20, 2021
1 parent e082eee commit 51b871d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/plugin/github/GitHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const DEFAULT_RETRY_MIN_TIMEOUT = 1000;
const parseErrormsg = err => {
let msg = err;
if (err instanceof Error) {
const { status, message, headers } = err;
const { status, message } = err;
const { headers } = err.response;
msg = `${_.get(headers, 'status', status)} (${message})`;
}
return msg;
Expand Down
9 changes: 5 additions & 4 deletions test/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const tokenRef = 'GITHUB_TOKEN';
const pushRepo = 'git://github.com:user/repo';
const host = 'github.com';
const git = { changelog: null };
const requestErrorOptions = { request: { url: '', headers: {} }, response: { headers: {} } };

test.serial('should validate token', async t => {
const tokenRef = 'MY_GITHUB_TOKEN';
Expand Down Expand Up @@ -224,7 +225,7 @@ test('should throw for unauthenticated user', async t => {
const options = { github: { tokenRef, pushRepo, host } };
const github = factory(GitHub, { options });
const stub = sinon.stub(github.client.users, 'getAuthenticated');
stub.throws(new RequestError('Bad credentials', 401, { request: { url: '', headers: {} } }));
stub.throws(new RequestError('Bad credentials', 401, requestErrorOptions));

await t.throwsAsync(runTasks(github), {
message: /^Could not authenticate with GitHub using environment variable "GITHUB_TOKEN"/
Expand All @@ -239,7 +240,7 @@ test('should throw for non-collaborator', async t => {
const options = { github: { tokenRef, pushRepo, host } };
const github = factory(GitHub, { options });
const stub = sinon.stub(github.client.repos, 'checkCollaborator');
stub.throws(new RequestError('HttpError', 401, { request: { url: '', headers: {} } }));
stub.throws(new RequestError('HttpError', 401, requestErrorOptions));

await t.throwsAsync(runTasks(github), { message: /^User john is not a collaborator for user\/repo/ });

Expand Down Expand Up @@ -270,7 +271,7 @@ test.serial('should skip authentication and collaborator checks when running on
test('should handle octokit client error (without retries)', async t => {
const github = factory(GitHub, { options: { github: { tokenRef, pushRepo, host } } });
const stub = sinon.stub(github.client.repos, 'createRelease');
stub.throws(new RequestError('Not found', 404, { request: { url: '', headers: {} } }));
stub.throws(new RequestError('Not found', 404, requestErrorOptions));
interceptAuthentication();
interceptCollaborator();

Expand All @@ -284,7 +285,7 @@ test('should handle octokit client error (with retries)', async t => {
const options = { github: { tokenRef, pushRepo, host, retryMinTimeout: 0 } };
const github = factory(GitHub, { options });
const stub = sinon.stub(github.client.repos, 'createRelease');
stub.throws(new RequestError('Request failed', 500, { request: { url: '', headers: {} } }));
stub.throws(new RequestError('Request failed', 500, requestErrorOptions));
interceptAuthentication();
interceptCollaborator();

Expand Down

0 comments on commit 51b871d

Please sign in to comment.