Skip to content

Commit aa8c93b

Browse files
blarghmateyasottile
authored andcommitted
fix: Allow skipping aliased hooks
There are situations where a hook with the same ID will be used multiple times, but with differing configurations. In the event that one of those configurations should not desired (or can't) be run in pre-commit CI it should be possible to skip using the `alias` configuration parameter. This adds support for the `alias` as an alternate to just `id` in the `ci:skip` list.
1 parent d7b98fe commit aa8c93b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

pre_commit_ci_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ def _check_autoupdate_branch(val: str) -> None:
2525
class ValidateSkip:
2626
def check(self, dct: dict[str, Any]) -> None:
2727
all_ids = {
28-
hook['id']
28+
hook_id
2929
for repo in dct['repos']
3030
for hook in repo['hooks']
31+
for hook_id in (hook['id'], hook.get('alias'))
32+
if hook_id is not None
3133
}
3234
unexpected_skip = set(dct.get('ci', {}).get('skip', ())) - all_ids
3335
if unexpected_skip:

tests/pre_commit_ci_config_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ def test_skip_referencing_missing_hook():
9494
)
9595

9696

97+
def test_skip_references_hook_with_alias():
98+
cfg = {
99+
'ci': {'skip': ['alternate-identity']},
100+
'repos': [
101+
{
102+
'repo': 'meta',
103+
'hooks': [
104+
{
105+
'id': 'identity',
106+
'alias': 'alternate-identity',
107+
},
108+
],
109+
},
110+
],
111+
}
112+
cfgv.validate(cfg, SCHEMA)
113+
114+
97115
def test_main_ok(tmpdir):
98116
cfg_s = '''\
99117
ci:

0 commit comments

Comments
 (0)