-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add self-signed option to allow configure with private gitlab instances #32
base: master
Are you sure you want to change the base?
Conversation
* Also add support for command options
index.js
Outdated
program | ||
.command(trigger) | ||
.description(description) | ||
.action((...args) => fn(config, ...args)); | ||
|
||
if(options && options.length > 0){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not happy about the way the JS is written here. @RamonGebben I could use your help to make it more beautiful :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up removing the logic since it is irrelevant at the moment
Some commands from @RamonGebben that I still have to process :
I will leave the command level option logic so we can reuse it later. |
* Remove logic for option specific command
Alright, all feedback processed. @RamonGebben , this is coming back to you :). |
index.js
Outdated
if(options && options.length > 0){ | ||
options.forEach( | ||
(option) => { | ||
program.commands[program.commands.length - 1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This index is a bit confusing to me. It looks like you're trying to get the current index.
Maybe grab the index of current iteration at line 62.
const chalk = require('chalk'); | ||
|
||
const disableCertificateVerification = async() => { | ||
logger.log(chalk.red.bold('⚠️ Disabling certificate verification. This is unsafe and should only be used as last resort.')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's extend the logger to have a .warn
or .danger
and have the chalk stuff in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I gave it a go. Let me see if you are happy about the implementation :).
|
||
const disableCertificateVerification = async() => { | ||
logger.log(chalk.red.bold('⚠️ Disabling certificate verification. This is unsafe and should only be used as last resort.')); | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this need to be set every time the user calls mergify?
Every command you give to mergify is like calling a script so that would be a new process and the function is only invoked from the configure command.
So I think you want to write into the config that the user has set this. And check it before doFetch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second glance, after reviewing the command refactoring. This flag will need to available on each command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do kinda agree with the comment. Thinking about #11 for example, some of the options should definitely be part of the config.
I think that this first version of the implementation is probably good enough for now though. Let's see what happens
* Avoid having to use chalk all the time
Now the test coverage has dropped by 4.6% can you see if you can up that again as well? |
lib/utils/logger/index.js
Outdated
module.exports = { | ||
logger: console | ||
}; | ||
logger: new Logger() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we need a constructor for this. I think we should just use an object literal since we don't need to access anything in the this
context.
So maybe like
const logger = { warn: (...args) => console.log(...args) }
That way we don't need to new
it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, that's how I had it first but I didn't get it working.
Let me try again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I get if I try to use an object literal
/Users/jlengrand/IdeaProjects/mergify/lib/utils/logger/index.js:4
log = (...args) =>{
^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
Seems like variable arguments is not supported in the same way in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, got it working!
lib/commands/configure/index.js
Outdated
@@ -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.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all warnings have a
Same goes for the Uh-oh cat 🙀.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
lib/utils/logger/index.js
Outdated
@@ -1,3 +1,19 @@ | |||
const chalk = require('chalk'); | |||
|
|||
var Logger = function(){}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's turn this into a getLogger function and pass a transport
as the first argument.
Which returns the object literal which I was talking about down below.
That way you can provide a mocked version of console
in your tests. And naturally this would have more options for the future as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea what you're talking about. This is all Chinese at the moment
Alright, all what's left now is to test. |
Alright, I have something but I'm not happy about the tests. Can you please have a look at it? |
|
||
test('Testing normal log message', () => { | ||
|
||
logger.log('test', 'plop'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use mock functions from Jest?
https://jestjs.io/docs/en/mock-functions
Then you could getLogger
with { log: jest.fn() }
const mockConsole = {
log: jest.fn(),
};
logger = getLogger(mockConsole);
logger.log('Pizza')
expect(mockConsole.log.mock.results[0].value).toBe('Pizza')
|
||
const getLogger = function(transport){ | ||
return { | ||
log : (...args) =>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting can be a little prettier:
return {
log: (...args) => {
},
}
@@ -52,6 +60,10 @@ const run = async() => { | |||
await verify(); | |||
} | |||
|
|||
options.forEach(({trigger, description, fn}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put whitespace around deconstruction arguments?
({ a, b }) => //...
Fixes #27