diff --git a/index.js b/index.js index e9e7506..2442312 100755 --- a/index.js +++ b/index.js @@ -8,13 +8,21 @@ const { configure } = require('./lib/commands/configure'); const { verify } = require('./lib/commands/verify'); const { getAllAssigned } = require('./lib/commands/getAllAssigned'); const { getAllSubmitted } = require('./lib/commands/getAllSubmitted'); - +const { disableCertificateVerification } = require('./lib/options/disableCertificateVerification'); const { readConfig } = require('./lib/utils/readConfig'); program .name('mergify') .version(pack.version); +const options = [ + { + trigger: '-s --self-signed', + description: 'disables the verification of certificates for commands', + fn: disableCertificateVerification + } +]; + const commands = [ { trigger: 'assigned', @@ -52,6 +60,10 @@ const run = async() => { await verify(); } + options.forEach(({trigger, description, fn}) => { + program.option(trigger, description, (...args) => fn(config, ...args)); + }); + commands.forEach(({ trigger, description, fn }) => { program .command(trigger) diff --git a/lib/commands/configure/index.js b/lib/commands/configure/index.js index c5ed370..53940ba 100644 --- a/lib/commands/configure/index.js +++ b/lib/commands/configure/index.js @@ -8,7 +8,7 @@ const chalk = require('chalk'); const configure = async() => { if(await checkConfigExists()){ - logger.log(chalk.red.bold('āš ļø Mergify is already configured. Configuring again will override the existing file.')); + logger.warn('Mergify is already configured. Configuring again will override the existing file.'); } try { diff --git a/lib/commands/verify/index.js b/lib/commands/verify/index.js index 4c26a67..ca4e063 100644 --- a/lib/commands/verify/index.js +++ b/lib/commands/verify/index.js @@ -22,8 +22,8 @@ const verify = async({ userId }) => { return process.exit(0); } catch (error) { spinner.stop(); - logger.log('\nšŸ™€ Oh no, could not complete verify. Please review your config'); - logger.log(error); + logger.err('Oh no, could not complete verify. Please review your config'); + logger.err(error); process.exit(1); } }; diff --git a/lib/options/disableCertificateVerification/index.js b/lib/options/disableCertificateVerification/index.js new file mode 100644 index 0000000..837ee69 --- /dev/null +++ b/lib/options/disableCertificateVerification/index.js @@ -0,0 +1,11 @@ +const {logger} = require('../../utils/logger'); + +const disableCertificateVerification = async() => { + logger.warn('Disabling certificate verification. This is unsafe and should only be used as last resort.'); + process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; + return; +}; + +module.exports = { + disableCertificateVerification +}; diff --git a/lib/utils/logger/index.js b/lib/utils/logger/index.js index 2f81c59..23791d8 100644 --- a/lib/utils/logger/index.js +++ b/lib/utils/logger/index.js @@ -1,3 +1,22 @@ +const chalk = require('chalk'); + +const getLogger = function(transport){ + return { + log : (...args) =>{ + transport.log(...args); + }, + + warn : (...args) =>{ + transport.log('āš ļø', chalk.yellow.bold(...args)); + }, + + err : (...args) =>{ + transport.log('šŸ™€', chalk.red.bold(...args)); + } + } +} + module.exports = { - logger: console -}; + logger: getLogger(console), + getLogger: getLogger +} diff --git a/lib/utils/logger/index.spec.js b/lib/utils/logger/index.spec.js new file mode 100644 index 0000000..f33c240 --- /dev/null +++ b/lib/utils/logger/index.spec.js @@ -0,0 +1,42 @@ +const {getLogger} = require('./index'); + +describe('utils/logger', () => { + let mockConsole; + let logger; + + beforeAll(() => { + mockConsole = { + content: '', + + log: function(...args) { + this.content = [...args]; + }, + } + logger = getLogger(mockConsole); + }); + + test('Testing normal log message', () => { + + logger.log('test', 'plop'); + + expect(mockConsole.content).toHaveLength(2); + expect(mockConsole.content).toEqual(['test', 'plop']); + }); + + test('Testing warning log message', () => { + + logger.warn('test', 'plop'); + + expect(mockConsole.content).toHaveLength(2); + expect(mockConsole.content[0]).toEqual('āš ļø'); + }); + + test('Testing error log message', () => { + + logger.err('test', 'plop'); + + expect(mockConsole.content).toHaveLength(2); + expect(mockConsole.content[0]).toEqual('šŸ™€'); + }); +}); + \ No newline at end of file