Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jlengrand
Copy link
Collaborator

@jlengrand jlengrand commented Apr 27, 2018

  • Also add support for command options

Fixes #27

@coveralls
Copy link

coveralls commented Apr 27, 2018

Pull Request Test Coverage Report for Build 56

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.4%) to 96.429%

Totals Coverage Status
Change from base Build 46: 0.4%
Covered Lines: 54
Relevant Lines: 56

💛 - Coveralls

@jlengrand jlengrand changed the base branch from commands to master April 29, 2018 09:43
index.js Outdated
program
.command(trigger)
.description(description)
.action((...args) => fn(config, ...args));

if(options && options.length > 0){
Copy link
Collaborator Author

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 :).

Copy link
Collaborator Author

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

@jlengrand jlengrand changed the title Add self-signed option to allow configure with private gitlab instances WIP: Add self-signed option to allow configure with private gitlab instances Apr 29, 2018
@jlengrand
Copy link
Collaborator Author

Some commands from @RamonGebben that I still have to process :

  • The option should be at software level, not command level (nothing should work without the flag)
  • Use index for command level options instead of weird command indexing.

I will leave the command level option logic so we can reuse it later.

Julien Lengrand-Lambert added 2 commits April 29, 2018 11:52
@jlengrand
Copy link
Collaborator Author

Alright, all feedback processed. @RamonGebben , this is coming back to you :).

@jlengrand jlengrand requested a review from RamonGebben April 29, 2018 10:08
@jlengrand jlengrand changed the title WIP: Add self-signed option to allow configure with private gitlab instances Add self-signed option to allow configure with private gitlab instances Apr 29, 2018
index.js Outdated
if(options && options.length > 0){
options.forEach(
(option) => {
program.commands[program.commands.length - 1]
Copy link
Owner

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.'));
Copy link
Owner

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

Copy link
Collaborator Author

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";
Copy link
Owner

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

Copy link
Owner

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.

Copy link
Collaborator Author

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
@RamonGebben
Copy link
Owner

Now the test coverage has dropped by 4.6% can you see if you can up that again as well?

module.exports = {
logger: console
};
logger: new Logger()
Copy link
Owner

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.

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, got it working!

@@ -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.');
Copy link
Owner

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 ⚠️ in front maybe also put those in the logger.
Same goes for the Uh-oh cat 🙀.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -1,3 +1,19 @@
const chalk = require('chalk');

var Logger = function(){};
Copy link
Owner

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.

Copy link
Collaborator Author

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

@jlengrand
Copy link
Collaborator Author

Alright, all what's left now is to test.

@jlengrand
Copy link
Collaborator Author

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');
Copy link
Owner

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) =>{
Copy link
Owner

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}) => {
Copy link
Owner

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 }) => //...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configure fails when running against an instance with a self-signed certificate
3 participants