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

ghooks configuration #81

Closed
wants to merge 5 commits into from

Conversation

ta2edchimp
Copy link
Collaborator

This PR introduces the ability to configure ghooks more detailed (as originally proposed here).

In package.json:

  "config": {
    "ghooks": {
        "randomConfig": ["randomValue"],
        "hooks": {
          "pre-commit": "echo \"some pre-commit hook\"
        }
    }

Replaces the old way (still working, but considered deprecated):

  "config": {
    "ghooks": {
        "pre-commit": "echo \"some pre-commit hook\""
    },
    "ghooks-randomConfig": ["introduced for backwards compatibility with hooks configuration"]
  }

The idea behind this PR is, for example to prepare ghooks to be able to optionally exit the hooks with a non-zero code (an error) if ghooks could not be loaded successfully. Therefore, I consider this PR as work in progress, until that particular feature can be (safely, this time) enabled again.

So in order to re-implement an »exit with error« functionality, I'd like to know what way to approach this would be the most adequate:

  1. upon install, check the config whether to »exit with error« and write the hooks' script accordingly
  2. try to obtain the responsible package.json and read the config, not exiting with an error if nothing explicitly states so.

When going route 1, I'd suggest making the install script "re-runnable", by adding it as bin.ghooks to the package.json.

@gtramontina @kentcdodds I'd like to hear from you what your thoughts are about this proposal (if/when you got time for this — no need to hurry).

Edit: If this gets merged eventually, I'd propose we call this a breaking change to trigger a major version bump?

@ta2edchimp
Copy link
Collaborator Author

Meh. CI builds seem to fail due to a bug in istanbul 😞

expect(getConfig()).to.deep.equal(expectedConfig)
})

it('reads custom configuration and hooks (overriding the deprecated way)', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

great coverage!

@kentcdodds
Copy link
Contributor

This looks awesome!

If this gets merged eventually, I'd propose we call this a breaking change to trigger a major version bump?

There's technically nothing breaking about this right? Unless I misunderstand what's going on here, it looks like we're just adding the ability to configure things. Seems fine to me. When we remove the ability to do the old stuff then we can version bump. But it looks like we've got backward compat right now.

@ta2edchimp
Copy link
Collaborator Author

ta2edchimp commented Apr 13, 2016

Yes, technically there shouldn't be anything breaking; I guess I only wanted to "feel" safe after "exit with error-gate" 😜

Atm I have the following steps on my todo list for the upcoming days:

  • Have a look into the code coverage issue.
  • Re-/Implement the "exit with error" option.
  • Update the ReadMe accordingly.

Please drop me a line here, if you'd prefer to put the (re-)implementation of "exit with error" into a separate PR (on the other hand, there would be no need for these changes, when there's nothing to configure).

... and thanks for taking the time to review this!

@kentcdodds
Copy link
Contributor

Please drop me a line here, if you'd prefer to put the (re-)implementation of "exit with error" into a separate PR (on the other hand, there would be no need for these changes, when there's nothing to configure).

I'm fine doing this in the same PR as long as it's backward compatible 👍

@ta2edchimp ta2edchimp changed the title WIP: ghooks configuration ghooks configuration Apr 18, 2016
// it gets substituted on ghooks' setup
// {{generated_config_start}}
return global.__testonly_ghooksConfig__ || {}
// {{generated_config_end}}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

global.__testonly_ghooksConfig__ is atm required to thoroughly test the optional behavior to exit with an error.

The whole block from {{generated_config_start}} to {{generated_config_end}} (including their comments) gets replaced when rendering the current config into the hook.template.

As a side note:
The hooks also get rendered into the template. I was unsure whether to ditch them, but maybe we can make use of them at a later point.

@gtramontina
Copy link
Collaborator

Hey everyone, really sorry for the silence… This looks great!

One other option, that just occurred me, could be simply having another config entry. Just like we have config.ghooks, I'm thinking we could also support config.ghooks-settings (or config.ghooks-options, or…) 💭 ?

When going route 1, I'd suggest making the install script "re-runnable", by adding it as bin.ghooks to the package.json.

If I correctly got what you're saying, I believe we can already re-run it with npm run ghooks install.

@kentcdodds
Copy link
Contributor

I'd be fine having a separate config property called ghooksSettings or whatever. I forget why we need settings for ghooks now though. It's been a while :-)

@gtramontina
Copy link
Collaborator

I thought an example would be useful… 😛

{
  "config": {
    "ghooks": {
      "pre-commit": "",
      
    },
    "ghooks-settings": {
      "exitWithError": true
    }
  }
}

gonna sleep now, it's freaking 3am here o_O

@ta2edchimp
Copy link
Collaborator Author

I forget why we need settings for ghooks now though. It's been a while :-)

It was mostly because of »exit with error-gate« and #28 (Specify project root manually).

Some place was concluded that it would be nice to eventually have

"config": {
    "ghooks": {
        "randomConfig": ["randomValue"],
        "hooks": {
          "pre-commit": "echo \"some pre-commit hook\"
        }
    }

and to allow config.ghooks-randomConfig (whilst marked as deprecated) too — for reasons of backwards compatibility with config.ghooks[ hookname ].


I should have some more time in the upcoming days, I'll at least update this PR / resolve the conflicts, so we'd have a clean status we'd be talking about ...

@codecov-io
Copy link

codecov-io commented May 31, 2016

Current coverage is 100%

Merging #81 into master will decrease coverage by n/a%

@@            master     #81   diff @@
======================================
  Files            4       5     +1   
  Lines          114     166    +52   
  Methods          0       7     +7   
  Branches         4       6     +2   
======================================
+ Hits           114     166    +52   
  Misses           0       0          
  Partials         0       0          

Powered by Codecov. Last updated by 73262f4...db08d89

@ta2edchimp ta2edchimp force-pushed the feat/pkg-config branch 2 times, most recently from bf49af4 to 32697d0 Compare May 31, 2016 08:57
Allow ghooks to be configured more detailed via
config.ghooks.[option] in package.json.

Hooks are now to be configured via the new
config.ghooks.hooks config-object in package.json.
(Still valid, but considered deprecated: config.ghooks.[hookname]).
@ta2edchimp
Copy link
Collaborator Author

Jesus Christ, that GitCop tried hard to get me arrested for being too verbose . . . 😞

@gtramontina
Copy link
Collaborator

😆 I guess I should tune it down a little…

@gtramontina
Copy link
Collaborator

What do you think about warning the developer if they are using the deprecated (hopefully soon-to-be removed) way?

@ta2edchimp
Copy link
Collaborator Author

Absolutely! I'm just unsure as where to output the warning (as in, on every invokation of a hook, only on the hooks' installation/setup, ...).

@kentcdodds
Copy link
Contributor

Re: GitCop, it seemed like a good idea at the time, but.... I don't use it anymore. Just too heavy handed and not flexible.

@gtramontina
Copy link
Collaborator

Closing this one as there will be no future development in ghooks. Thank you for your efforts, @ta2edchimp !

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

Successfully merging this pull request may close these issues.

4 participants