diff --git a/lib/cli.js b/lib/cli.js index 3c56e95..b7faaea 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -102,7 +102,7 @@ if (argv.version) { process.exit(argv.help ? 0 : 1); } else { const cwd = process.cwd(); - const packageJsonFile = path.join(cwd, 'package.json'); // eslint-disable-next-line import/no-dynamic-require + const packageJsonFile = path.join(cwd, 'package.json'); // eslint-disable-next-line import/no-dynamic-require const pkg = require(packageJsonFile); diff --git a/lib/github/client.js b/lib/github/client.js index 84b1583..4447df9 100644 --- a/lib/github/client.js +++ b/lib/github/client.js @@ -32,87 +32,110 @@ 'use strict'; -const util = require('util'); - const Gofer = require('gofer'); +const pkg = require('../../package'); + const parseRepository = require('./parse-repository'); -function Github(config) { - Gofer.call(this, config, 'github'); -} +class Github extends Gofer { + constructor(config) { + super(config, 'github', pkg.version, pkg.name); + } -util.inherits(Github, Gofer); -Github.prototype.registerEndpoints({ - pull: function pull(request) { + get pull() { return { - commits: function commits(pullId) { - return request('/repos/{owner}/{repo}/pulls/{pullId}/commits', { - pathParams: { - pullId, - }, - }).json(); - }, - get: function get(pullId) { - return request('/repos/{owner}/{repo}/pulls/{pullId}', { - pathParams: { - pullId, - }, - }).json(); - }, + /** + * @param {string} pullId + * @return {Promise} + */ + get: pullId => + this.get('/repos/{owner}/{repo}/pulls/{pullId}', { + pathParams: { pullId }, + endpointName: 'pull.get', + }).json(), + /** + * @param {string} pullId + * @return {Promise} + */ + commits: pullId => + this.get('/repos/{owner}/{repo}/pulls/{pullId}/commits', { + pathParams: { pullId }, + endpointName: 'pull.commits', + }).json(), }; - }, - labels: function labelsEndpoint(request) { + } + + get labels() { return { - create: function create(label) { - return request('/repos/{owner}/{repo}/labels', { - method: 'POST', + /** + * + * @param {string} label + * @return {Promise} + */ + create: label => + this.post('/repos/{owner}/{repo}/labels', { json: label, - }).json(); - }, - list: function list() { - return request('/repos/{owner}/{repo}/labels', {}).json(); - }, - listByIssue: function listByIssue(issueId) { - return request('/repos/{owner}/{repo}/issues/{issueId}/labels', { - pathParams: { - issueId, - }, - }).json(); - }, - setForIssue: function setForIssue(issueId, labels) { - return request('/repos/{owner}/{repo}/issues/{issueId}/labels', { - method: 'PUT', - pathParams: { - issueId, - }, + endpointName: 'labels.create', + }).json(), + + /** + * @return {Promise} + */ + list: () => this.get('/repos/{owner}/{repo}/labels', {}).json(), + + /** + * @param {string} issueId + * @return {Promise} + */ + listByIssue: issueId => + this.get('/repos/{owner}/{repo}/issues/{issueId}/labels', { + pathParams: { issueId }, + endpointName: 'labels.listByIssue', + }).json(), + + /** + * @param {string} issueId + * @param {string[]} labels + * @return {FetchResponse} + */ + setForIssue: (issueId, labels) => + this.put('/repos/{owner}/{repo}/issues/{issueId}/labels', { + pathParams: { issueId }, json: labels, - }); - }, + endpointName: 'labels.setForIssue', + }), }; - }, - releases: function releases(request) { + } + + get releases() { return { - create: function create(release) { - return request('/repos/{owner}/{repo}/releases', { - method: 'POST', + /** + * @param release + * @return {Promise} + */ + create: release => + this.post('/repos/{owner}/{repo}/releases', { json: release, - }).json(); - }, + endpointName: 'releases.create', + }).json(), }; - }, - tags: function tags(request) { + } + + get tags() { return { - get: function get(tag) { - return request('/repos/{owner}/{repo}/git/refs/tags/{tag}', { - pathParams: { - tag, - }, - }).json(); - }, + /** + * @param {string} tag + * @return {Promise} + */ + get: tag => + this.get('/repos/{owner}/{repo}/git/refs/tags/{tag}', { + pathParams: { tag }, + endpointName: 'tags.get', + }).json(), }; - }, -}); + } +} Github.forRepository = function forRepository(repository) { const repoInfo = parseRepository(repository); diff --git a/package-lock.json b/package-lock.json index ed89d21..bd1dc6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,9 +34,9 @@ "dev": true }, "@eslint/eslintrc": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.3.0.tgz", - "integrity": "sha512-1JTKgrOKAHVivSvOYw+sJOunkBjUOvjqWk1DPja7ZFhIS2mX/4EgTT8M7eTK9jrKhL/FvXXEbQwIs3pg1xp3dg==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.0.tgz", + "integrity": "sha512-2ZPCc+uNbjV5ERJr+aKSPRwZgKd2z11x0EgLvb1PURmUrn9QNRXFqje0Ldq454PfAVyaJYyrDvvIKSFP4NnBog==", "dev": true, "requires": { "ajv": "^6.12.4", @@ -46,9 +46,25 @@ "ignore": "^4.0.6", "import-fresh": "^3.2.1", "js-yaml": "^3.13.1", - "lodash": "^4.17.20", "minimatch": "^3.0.4", "strip-json-comments": "^3.1.1" + }, + "dependencies": { + "globals": { + "version": "12.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", + "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "dev": true, + "requires": { + "type-fest": "^0.8.1" + } + }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true + } } }, "@istanbuljs/schema": { @@ -542,13 +558,13 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "eslint": { - "version": "7.20.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.20.0.tgz", - "integrity": "sha512-qGi0CTcOGP2OtCQBgWZlQjcTuP0XkIpYFj25XtRTQSHC+umNnp7UMshr2G8SLsRFYDdAPFeHOsiteadmMH02Yw==", + "version": "7.22.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.22.0.tgz", + "integrity": "sha512-3VawOtjSJUQiiqac8MQc+w457iGLfuNGLFn8JmF051tTKbh5/x/0vlcEj8OgDCaw7Ysa2Jn8paGshV7x2abKXg==", "dev": true, "requires": { "@babel/code-frame": "7.12.11", - "@eslint/eslintrc": "^0.3.0", + "@eslint/eslintrc": "^0.4.0", "ajv": "^6.10.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", @@ -561,10 +577,10 @@ "espree": "^7.3.1", "esquery": "^1.4.0", "esutils": "^2.0.2", - "file-entry-cache": "^6.0.0", + "file-entry-cache": "^6.0.1", "functional-red-black-tree": "^1.0.1", "glob-parent": "^5.0.0", - "globals": "^12.1.0", + "globals": "^13.6.0", "ignore": "^4.0.6", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", @@ -572,7 +588,7 @@ "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", - "lodash": "^4.17.20", + "lodash": "^4.17.21", "minimatch": "^3.0.4", "natural-compare": "^1.4.0", "optionator": "^0.9.1", @@ -726,9 +742,9 @@ } }, "eslint-plugin-mocha": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-8.0.0.tgz", - "integrity": "sha512-n67etbWDz6NQM+HnTwZHyBwz/bLlYPOxUbw7bPuCyFujv7ZpaT/Vn6KTAbT02gf7nRljtYIjWcTxK/n8a57rQQ==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-8.1.0.tgz", + "integrity": "sha512-1EgHvXKRl7W3mq3sntZAi5T24agRMyiTPL4bSXe+B4GksYOjAPEWYx+J3eJg4It1l2NMNZJtk0gQyQ6mfiPhQg==", "dev": true, "requires": { "eslint-utils": "^2.1.0", @@ -1023,27 +1039,27 @@ } }, "glob-parent": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", - "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, "requires": { "is-glob": "^4.0.1" } }, "globals": { - "version": "12.4.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", - "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "version": "13.7.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.7.0.tgz", + "integrity": "sha512-Aipsz6ZKRxa/xQkZhNg0qIWXT6x6rD46f6x/PCnBomlttdIyAPak4YD9jTmKpZ72uROSMU87qJtcgpgHaVchiA==", "dev": true, "requires": { - "type-fest": "^0.8.1" + "type-fest": "^0.20.2" }, "dependencies": { "type-fest": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", - "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true } } @@ -1642,9 +1658,9 @@ "dev": true }, "mocha": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-8.3.0.tgz", - "integrity": "sha512-TQqyC89V1J/Vxx0DhJIXlq9gbbL9XFNdeLQ1+JsnZsVaSOV1z3tWfw0qZmQJGQRIfkvZcs7snQnZnOCKoldq1Q==", + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-8.3.2.tgz", + "integrity": "sha512-UdmISwr/5w+uXLPKspgoV7/RXZwKRTiTjJ2/AC5ZiEztIoOYdfKb19+9jNmEInzx5pBsCyJQzarAxqIGBNYJhg==", "dev": true, "requires": { "@ungap/promise-all-settled": "1.1.2", @@ -2180,9 +2196,9 @@ "dev": true }, "semver": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", - "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", "requires": { "lru-cache": "^6.0.0" } @@ -2503,9 +2519,9 @@ }, "dependencies": { "ajv": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-7.1.1.tgz", - "integrity": "sha512-ga/aqDYnUy/o7vbsRTFhhTsNeXiYb5JWDIcRIeZfwRNCefwjNTVYCGdGSUrEmiu3yDK3vFvNbgJxvrQW4JXrYQ==", + "version": "7.2.4", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-7.2.4.tgz", + "integrity": "sha512-nBeQgg/ZZA3u3SYxyaDvpvDtgZ/EZPF547ARgZBrG9Bhu1vKDwAIjtIf+sDtJUKa2zOcEbmRLBRSyMraS/Oy1A==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1", @@ -2634,9 +2650,9 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "v8-compile-cache": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz", - "integrity": "sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", + "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, "v8-to-istanbul": { diff --git a/package.json b/package.json index dba2a54..9b70eeb 100644 --- a/package.json +++ b/package.json @@ -48,19 +48,19 @@ "gofer": "^5.1.0", "minimist": "^1.2.5", "rc": "^1.2.8", - "semver": "^7.3.4", + "semver": "^7.3.5", "string.prototype.replaceall": "^1.0.5" }, "devDependencies": { "c8": "^7.6.0", - "eslint": "^7.20.0", + "eslint": "^7.22.0", "eslint-config-groupon": "^10.0.2", "eslint-plugin-import": "^2.22.1", - "eslint-plugin-mocha": "^8.0.0", + "eslint-plugin-mocha": "^8.1.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^3.3.1", - "mocha": "^8.3.0", "mkdirp": "^1.0.4", + "mocha": "^8.3.2", "prettier": "^2.2.1" }, "author": {