Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Support whitelisting hooks installed when using pre-commit init-templatedir #1352
Comments
|
I'm not quite sure how this would work, the |
|
@deric4 did you have any additional ideas on how this would work? |
|
I think so, I had gotten started on testing it out but got sidetracked |
|
Was able to play with this some more today after finally getting vscode, homebrew, pyenv, and tox to play nice I'm sure there's a fair bit that I haven't taken into account, but was hoping something along either of the two options below might not too far into the weeds ConfigurationConfig file should support a list of allowed repos and/or hook ids. I don't know what a realistic schema for the config would be, or where/how pre-commit would source it quite yet, but something like repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
hooks:
- check-docstring-first
#maybe something like this for option 2?
- src: https://github.com/pre-commit/*
ImplementationOption 1 - pre_commit:repository:_cloned_repository_hooks At some point before pre-commit/pre_commit/repository.py Lines 142 to 173 in bcff73c debugging screen shot showing available vars/values at this point Option 2 - add additional config/repo info in ~/.cache/pre-commit/db.db My initial proposal for supporting file path based whitelisting conflated my personal development patterns/layout and what I was really wanting: allow any hooks defined in repos from a whitelist of GitHub users or organizations. example: # whitelist config
repos:
- src: https://github.com/asottile/*Would allow the auto install of hooks defined in repositories under github/asottile So cloning https://github.com/asottile/pyupgrade auto installs everything in that projects Not sure implementation would be very straightforward since the hook id, and which config files they're defined in, doesn't appear in db.db dump of db.db after cloning pyupgrade
Initially thought maybe some tom-foolery in pre_commit:store:Store init might make sense, along with a query that returns only whitelisted repos/hook ids: pre-commit/pre_commit/store.py Lines 39 to 42 in bcff73c |
ideally, let's make this as broad as possible and only make it super granular if needed. I suspect that this means just whitelist of particular repositories (and maybe an extension to allow wildcards there? idk) mostly just looking to keep the scope and complexity of this as small as possible -- don't really want to have to build something for like as for config, maybe just a flat file? though that kinda closes the door on expanding this feature (though I can't really perceive any valuable expansions |
Makes sense. Would being able to ignore the white list configuration need to be supported (similar to
White listing specific repos I think gets most of the way there, perhaps just a regex match against a list of allowed values?
pre-commit/pre_commit/clientlib.py Lines 299 to 304 in bcff73c Any recommendation on where to persist the config file? I had initially thought keeping it in |
nah, probably the error message would just say "you configured this, you asked for this -- delete $CONFIG_FILE or add blah blah to it"
I don't think it would be "persisted" per-se, it would be edited by a human -- probably in |
|
Ok awesome, i'll try and take a crack at a PR. Thanks for the feedback! |

Auto installing hooks has been one of my favorite features especially when bouncin around 100s of organization/personal repos but I'm also cloning quite a few "untrusted" repos. Having an easier way of whitelisting either individual hooks, hooks in a specific repos' .pre-commit-config.yaml, or even file paths would be would be pretty awesome, e.g ~/projects/trusted-repos/*.
Willing to take a crack at a PR if this is even doable. Either way, thanks for one of my favorite tools! :)