diff --git a/packages/publisher/github/package.json b/packages/publisher/github/package.json index 8ed6215f3d..9db05e7059 100644 --- a/packages/publisher/github/package.json +++ b/packages/publisher/github/package.json @@ -7,6 +7,10 @@ "license": "MIT", "main": "dist/PublisherGithub.js", "typings": "dist/PublisherGithub.d.ts", + "scripts": { + "test": "yarn test:base test/**/*_spec.ts", + "test:base": "cross-env TS_NODE_FILES=1 mocha --config ../../../.mocharc.js" + }, "devDependencies": { "chai": "^4.3.3", "mocha": "^9.0.1", @@ -23,8 +27,8 @@ "@octokit/core": "^3.2.4", "@octokit/rest": "^18.0.11", "@octokit/types": "^6.1.2", + "debug": "^4.3.1", "fs-extra": "^10.0.0", - "lodash": "^4.17.20", "mime-types": "^2.1.25" } } diff --git a/packages/publisher/github/src/util/github.ts b/packages/publisher/github/src/util/github.ts index 4149765e38..00b7e1451a 100644 --- a/packages/publisher/github/src/util/github.ts +++ b/packages/publisher/github/src/util/github.ts @@ -1,6 +1,9 @@ +import debug from 'debug'; import { Octokit } from '@octokit/rest'; import { OctokitOptions } from '@octokit/core/dist-types/types.d'; -import { merge } from 'lodash'; + +const logInfo = debug('electron-forge:publisher:github:info'); +const logDebug = debug('electron-forge:publisher:github:debug'); export default class GitHub { private options: OctokitOptions; @@ -12,10 +15,19 @@ export default class GitHub { requireAuth: boolean = false, options: OctokitOptions = {}, ) { - this.options = merge( - options, - { headers: { 'user-agent': 'Electron Forge' } }, - ); + const noOp = () => {}; + + this.options = { + ...options, + log: { + debug: logDebug.enabled ? logDebug : noOp, + error: console.error, + info: logInfo.enabled ? logInfo : noOp, + warn: console.warn, + }, + userAgent: 'Electron Forge', + }; + if (authToken) { this.token = authToken; } else if (process.env.GITHUB_TOKEN) { diff --git a/packages/publisher/github/test/github_spec.ts b/packages/publisher/github/test/github_spec.ts index 6c1295e8c4..46402a8b9d 100644 --- a/packages/publisher/github/test/github_spec.ts +++ b/packages/publisher/github/test/github_spec.ts @@ -1,4 +1,6 @@ import { expect } from 'chai'; +import { Octokit } from '@octokit/rest'; +import { OctokitOptions } from '@octokit/core/dist-types/types.d'; import proxyquire from 'proxyquire'; import sinon, { SinonSpy } from 'sinon'; @@ -37,6 +39,12 @@ describe('GitHub', () => { }); describe('getGitHub', () => { + function getOptions(api: Octokit): OctokitOptions { + const { options } = api as any; + delete options.log; + return options; + } + it('should create a new GitHubAPI', () => { const gh = new GitHub(); expect(gitHubSpy.callCount).to.equal(0); @@ -50,31 +58,27 @@ describe('GitHub', () => { }); const api = gh.getGitHub(); - expect((api as any).options).to.deep.equal({ + expect(getOptions(api)).to.deep.equal({ auth: '1234', baseUrl: 'https://github.example.com:8443/enterprise', - headers: { - 'user-agent': 'Electron Forge', - }, + userAgent: 'Electron Forge', }); }); it('should not override the user agent', () => { - const gh = new GitHub('1234', true, { headers: { 'user-agent': 'Something' } }); + const gh = new GitHub('1234', true, { userAgent: 'Something' }); const api = gh.getGitHub(); - expect((api as any).options.headers['user-agent']).to.equal('Electron Forge'); + expect(getOptions(api).userAgent).to.equal('Electron Forge'); }); it('should authenticate if a token is present', () => { const gh = new GitHub('token'); const api = gh.getGitHub(); gh.getGitHub(); - expect((api as any).options).to.deep.equal({ + expect(getOptions(api)).to.deep.equal({ auth: 'token', - headers: { - 'user-agent': 'Electron Forge', - }, + userAgent: 'Electron Forge', }); }); @@ -82,10 +86,8 @@ describe('GitHub', () => { const gh = new GitHub(); const api = gh.getGitHub(); gh.getGitHub(); - expect((api as any).options).to.deep.equal({ - headers: { - 'user-agent': 'Electron Forge', - }, + expect(getOptions(api)).to.deep.equal({ + userAgent: 'Electron Forge', }); });