|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import functools |
| 4 | +import itertools |
4 | 5 | import textwrap |
5 | 6 | from typing import Callable |
6 | 7 |
|
@@ -49,6 +50,10 @@ def _preserve_style(n: ScalarNode, *, s: str) -> str: |
49 | 50 | return f'{n.style}{s}{n.style}' |
50 | 51 |
|
51 | 52 |
|
| 53 | +def _fix_stage(n: ScalarNode) -> str: |
| 54 | + return _preserve_style(n, s=f'pre-{n.value}') |
| 55 | + |
| 56 | + |
52 | 57 | def _migrate_composed(contents: str) -> str: |
53 | 58 | tree = yaml_compose(contents) |
54 | 59 | rewrites: list[tuple[ScalarNode, Callable[[ScalarNode], str]]] = [] |
@@ -76,6 +81,22 @@ def _migrate_composed(contents: str) -> str: |
76 | 81 | if node.value == 'python_venv': |
77 | 82 | rewrites.append((node, python_venv_replace)) |
78 | 83 |
|
| 84 | + # stages rewrites |
| 85 | + default_stages_matcher = (MappingValue('default_stages'), SequenceItem()) |
| 86 | + default_stages_match = match(tree, default_stages_matcher) |
| 87 | + hook_stages_matcher = ( |
| 88 | + MappingValue('repos'), |
| 89 | + SequenceItem(), |
| 90 | + MappingValue('hooks'), |
| 91 | + SequenceItem(), |
| 92 | + MappingValue('stages'), |
| 93 | + SequenceItem(), |
| 94 | + ) |
| 95 | + hook_stages_match = match(tree, hook_stages_matcher) |
| 96 | + for node in itertools.chain(default_stages_match, hook_stages_match): |
| 97 | + if node.value in {'commit', 'push', 'merge-commit'}: |
| 98 | + rewrites.append((node, _fix_stage)) |
| 99 | + |
79 | 100 | rewrites.sort(reverse=True, key=lambda nf: nf[0].start_mark.index) |
80 | 101 |
|
81 | 102 | src_parts = [] |
|
0 commit comments