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

Shared hooks #155

Closed
bbros-dev opened this issue Oct 20, 2020 · 9 comments · Fixed by #343
Closed

Shared hooks #155

bbros-dev opened this issue Oct 20, 2020 · 9 comments · Fixed by #343
Labels
feature request A new lefthook feature description

Comments

@bbros-dev
Copy link

bbros-dev commented Oct 20, 2020

Thank you for the effort you have put into lefthook and for making it opensource.

It would be useful to be able to share hooks.
since Pre-Commit already does this, consuming their convention would immediately provide a resource of hooks?

Or not, that doesn't matter.
The important idea is being able to share hooks - I suggest also looking at the git sub-repo as a way to manage shared repositories.

Pre-commit Example:

repos:
  - repo: git:https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.30.0
    hooks:
      - id: terraform_fmt
      - id: terragrunt_fmt
      - id: terraform_docs
  - repo: git:https://github.com/pre-commit/pre-commit-hooks
    rev: v2.5.0
    hooks:
      - id: check-merge-conflict
@bbros-dev bbros-dev changed the title Sharable repos Shared hooks Oct 20, 2020
@bbros-dev
Copy link
Author

Wrting the code you wish you had...:

pre-commit:
  parallel: true
  commands:
    ...
  scripts:
    "terraform_tfsec.sh "
    ...
  repos:
     their-tfm:
       vendor: git
       repo: git:https://github.com/antonbabenko/pre-commit-terraform

This would populate a folder .lefthook-shared with the sub-repo / folder their-tfm
The psuedo code:

mkdir .lefthook-shared
git sub-repo clone git:https://github.com/antonbabenko/pre-commit-terraform ./.lefthook-shared/their-tfm

Note that scripts references a script located here ./.lefthook-shared/their-tfm/terraform_tfsec.sh

Of course the above is PoC and the pre-commit repo scripts are not expected to work out the box.

@aminya
Copy link
Contributor

aminya commented Jun 3, 2021

This would be nice. But I think we can also start porting pre_commit_hooks to Go and add to Lefthook. This would make using Lefthook nicer.

https://github.com/pre-commit/pre-commit-hooks/tree/master/pre_commit_hooks

@kunickiaj
Copy link

Wrting the code you wish you had...:

pre-commit:
  parallel: true
  commands:
    ...
  scripts:
    "terraform_tfsec.sh "
    ...
  repos:
     their-tfm:
       vendor: git
       repo: git:https://github.com/antonbabenko/pre-commit-terraform

This would populate a folder .lefthook-shared with the sub-repo / folder their-tfm
The psuedo code:

mkdir .lefthook-shared
git sub-repo clone git:https://github.com/antonbabenko/pre-commit-terraform ./.lefthook-shared/their-tfm

Note that scripts references a script located here ./.lefthook-shared/their-tfm/terraform_tfsec.sh

Of course the above is PoC and the pre-commit repo scripts are not expected to work out the box.

Exactly why I found this issue. Don't really want to define our hook scripts in multiple repos and have to maintain that across repos. I couldn't find a way to do that with lefthook, am I missing something?

@kunickiaj
Copy link

Any idea if this is ever going to happen?

@mrexox
Copy link
Member

mrexox commented Jun 22, 2022

Adding a repo of scripts for lefthook and referring it from the config might be helpful.

I would really appreciate if you could provide the way you see it. Any use case example would be helpful.

@kunickiaj
Copy link

I think the OP's example is pretty much exactly the same as my use case. I've used (and currently use pre-commit) to run hooks across many repos. Reference terraform pre-commit hooks in my config so they aren't defined per repo, just configured per repo.

@oatovar
Copy link
Contributor

oatovar commented Aug 27, 2022

@mrexox I was looking into leveraging this functionality recently and came across this issue. I've opened up #323 with an implementation of this functionality. I've attempted to keep Lefthook as fast as possible when processing remote configs, so all git processing is done within a goroutine. I hope to contribute this feature to the project as I'm a big fan, and appreciate all feedback! 😄

@JuliusHenke
Copy link
Contributor

JuliusHenke commented Oct 19, 2022

The proposed config solution for repos sound really cool.

In the meantime I ended up with a different solution for sharing hooks. I publish an npm package containing the shared hooks (e.g. lefthook-shared). Then I install lefthook-shared in all projects consuming the shared hooks and reference the node_modules location of the package.

Example lefthook.yml configuration of consuming project:

source_dir: "./node_modules/lefthook-shared/lefthook"
pre-commit:
  scripts:
    "script.sh":
      runner: bash

@mrexox
Copy link
Member

mrexox commented Oct 19, 2022

Whoa! This is a really cool hack! 💯

BTW I hope to finish the PR with remote hooks support and release it with 1.2.0 in about 2 weeks

@mrexox mrexox added the feature request A new lefthook feature description label Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new lefthook feature description
Projects
None yet
6 participants