Skip to content

Commit

Permalink
Update octokit version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jcc20 committed Feb 16, 2023
1 parent adbfe47 commit aaa69dc
Show file tree
Hide file tree
Showing 12 changed files with 4,468 additions and 2,553 deletions.
8 changes: 5 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"presets": ["@babel/preset-env"],
"plugins": [
["module-resolver", {
"alias": {
"test": "./test"
},
"root": ["./src"]
}]
],
"presets": ["es2015-node", "stage-1"]
}],
["lodash"]

]
}
35 changes: 13 additions & 22 deletions dist/bin/labels.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
#! /usr/bin/env node
'use strict';

var _copyFromRepoCommand = require('../commands/copy-from-repo-command');

var _listCommand = require('../commands/list-command');

var _updateCommand = require('../commands/update-command');

var _package = require('../../package.json');

var _yargs = require('yargs');

var _yargs2 = _interopRequireDefault(_yargs);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
* Program options.
* Module dependencies.
*/

_yargs2.default // eslint-disable-line no-unused-expressions
.usage('Usage: $0 [options]').env('GITHUB_LABELS').command(['*', 'update'], 'Update repository labels', _updateCommand.updateConfig, _updateCommand.update).command('copy', 'Copy labels from repository', _copyFromRepoCommand.copyFromRepoConfig, _copyFromRepoCommand.copyFromRepo).command('list', 'List labels from repository', _listCommand.listConfig, _listCommand.list).help('h').alias('h', 'help').version('version', 'Version', _package.version).alias('V', 'version').wrap(null).argv;

"use strict";

var _copyFromRepoCommand = require("../commands/copy-from-repo-command");
var _listCommand = require("../commands/list-command");
var _updateCommand = require("../commands/update-command");
var _package = require("../../package.json");
var _yargs = _interopRequireDefault(require("yargs"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Module dependencies.
*/
* Program options.
*/
_yargs["default"] // eslint-disable-line no-unused-expressions
.usage('Usage: $0 [options]').env('GITHUB_LABELS').command(['*', 'update'], 'Update repository labels', _updateCommand.updateConfig, _updateCommand.update).command('copy', 'Copy labels from repository', _copyFromRepoCommand.copyFromRepoConfig, _copyFromRepoCommand.copyFromRepo).command('list', 'List labels from repository', _listCommand.listConfig, _listCommand.list).help('h').alias('h', 'help').version('version', 'Version', _package.version).alias('V', 'version').wrap(null).argv;
512 changes: 332 additions & 180 deletions dist/client.js

Large diffs are not rendered by default.

171 changes: 95 additions & 76 deletions dist/commands/copy-from-repo-command.js

Large diffs are not rendered by default.

160 changes: 88 additions & 72 deletions dist/commands/list-command.js

Large diffs are not rendered by default.

193 changes: 106 additions & 87 deletions dist/commands/update-command.js

Large diffs are not rendered by default.

179 changes: 102 additions & 77 deletions dist/index.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"lint-staged"
],
"dependencies": {
"@octokit/rest": "^15.9.2",
"@octokit/rest": "^19.0.5",
"bluebird": "^3.3.1",
"fs": "^0.0.2",
"inquirer": "^6.0.0",
Expand All @@ -54,20 +54,20 @@
"yargs": "^11.0.0"
},
"devDependencies": {
"babel-cli": "^6.4.0",
"babel-jest": "^23.2.0",
"babel-plugin-module-resolver": "^3.1.1",
"babel-preset-es2015-node": "^6.1.1",
"babel-preset-stage-1": "^6.24.1",
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.12",
"@babel/node": "^7.20.7",
"@babel/preset-env": "^7.20.2",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-module-resolver": "^4.1.0",
"coveralls": "^3.0.1",
"eslint": "5.0.1",
"eslint-config-seegno": "10.0.0",
"faker": "^4.1.0",
"jest": "^23.2.0",
"jest": "^27.0.6",
"lint-staged": "7.2.0",
"pre-commit": "^1.2.2",
"standard-http-error": "^2.0.0"
},
"pre-commit": "^1.2.2"
},
"engines": {
"node": "^6.14.0 || ^8.10.0 || >=9.10.0"
},
Expand Down
Empty file modified src/bin/labels.js
100644 → 100755
Empty file.
24 changes: 11 additions & 13 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
* Module dependencies.
*/

import { Octokit } from '@octokit/rest';
import { differenceBy, get, has } from 'lodash';
import Github from '@octokit/rest';

/**
* GitHub configuration.
* GitHub timeout default value.
*/

const config = {
debug: false,
timeout: 5000,
version: '3.0.0'
};
const defaultTimeout = 5000;

/**
* Get repository owner and name and include a validation.
Expand All @@ -40,10 +36,12 @@ export default class Client {
* Constructor.
*/

constructor({ token, ...options }) {
this.github = new Github({ ...config, ...options });

this.github.authenticate({ token, type: 'oauth' });
constructor({ timeout, token, ...options }) {
this.github = new Octokit({
auth: token,
request: { timeout: timeout || defaultTimeout },
...options
});
}

/**
Expand Down Expand Up @@ -71,7 +69,7 @@ export default class Client {
try {
label = await this.getLabel(repository, name);
} catch (err) {
if (!has(err, 'code') || get(err, 'code') !== 404) {
if (!has(err, 'status') || get(err, 'status') !== 404) {
throw err;
}
}
Expand Down Expand Up @@ -104,7 +102,7 @@ export default class Client {
async getLabels(repository) {
const { owner, repo } = getRepositoryOptions(repository);

const result = await this.github.issues.getLabels({
const result = await this.github.issues.listLabelsForRepo({
owner,
repo
});
Expand Down
39 changes: 21 additions & 18 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* Module dependencies.
*/

import { Octokit } from '@octokit/rest';
import Client from 'client';
import Github from '@octokit/rest';
import HttpError from 'standard-http-error';

/**
* Jest mocks.
Expand All @@ -21,7 +20,6 @@ describe('Client', () => {
const defaultOptions = { token: 'foobiz' };
const repository = 'corge/waldo';
const repositoryOptions = { owner: 'corge', repo: 'waldo' };
let authenticate;
let client;
let createLabel;
let deleteLabel;
Expand All @@ -31,7 +29,6 @@ describe('Client', () => {
let updateLabels;

beforeEach(() => {
authenticate = jest.fn();
createLabel = jest.fn();
deleteLabel = jest.fn();
getLabel = jest.fn();
Expand All @@ -46,19 +43,14 @@ describe('Client', () => {
updateLabels
};

Github.mockImplementation(() => ({ authenticate, issues }));
Octokit.mockImplementation(() => ({ issues }));

client = new Client(defaultOptions);
});

describe('constructor', () => {
it('should create an instance of `client` with given arguments', () => {
expect(client.github).toEqual({ authenticate, issues });
});

it('should call `github.authenticate` with given token and type as `oauth`', () => {
expect(client.github.authenticate).toHaveBeenCalledTimes(1);
expect(client.github.authenticate).toHaveBeenCalledWith({ token: 'foobiz', type: 'oauth' });
expect(client.github).toEqual({ issues });
});
});

Expand Down Expand Up @@ -96,19 +88,30 @@ describe('Client', () => {
});

it('should throw if `getLabel` throws an error with code different than 404', async () => {
client.getLabel = jest.fn(() => { throw new HttpError(100); });
client.getLabel = jest.fn(() => {
const err = new Error('');

err.status = 100;
throw err;
});

try {
await client.createOrUpdateLabel(repository);

fail();
} catch (e) {
expect(e.code).toBe(100);
expect(e.status).toBe(100);
}
});

it('should call `createLabel` with given `repository`, `name` and `color` if `getLabel` throws an error with code 404', async () => {
client.getLabel = jest.fn(() => { throw new HttpError(404); });
client.getLabel = jest.fn(() => {
const err = new Error('404 not found');

err.status = 404;
throw err;
});

client.updateLabel = jest.fn();
client.createLabel = jest.fn(() => Promise.resolve('foobiz'));

Expand Down Expand Up @@ -179,15 +182,15 @@ describe('Client', () => {
});

it('should call `github.issues.getLabels` with repository options', () => {
client.github.issues.getLabels = jest.fn(() => true);
client.github.issues.listLabelsForRepo = jest.fn(() => true);
client.getLabels(repository, 'foobar');

expect(client.github.issues.getLabels).toHaveBeenCalledTimes(1);
expect(client.github.issues.getLabels).toHaveBeenCalledWith({ ...repositoryOptions });
expect(client.github.issues.listLabelsForRepo).toHaveBeenCalledTimes(1);
expect(client.github.issues.listLabelsForRepo).toHaveBeenCalledWith({ ...repositoryOptions });
});

it('should return the data property from the result of the call `github.issues.getLabels`', () => {
client.github.issues.getLabels = jest.fn(() => Promise.resolve({ data: 'foobar' }));
client.github.issues.listLabelsForRepo = jest.fn(() => Promise.resolve({ data: 'foobar' }));

return client.getLabels(repository).then(label => {
expect(label).toBe('foobar');
Expand Down
Loading

0 comments on commit aaa69dc

Please sign in to comment.