(lines: list[str])
| 62 | |
| 63 | |
| 64 | def find_on_block(lines: list[str]) -> OnBlock | None: |
| 65 | on_start = None |
| 66 | on_indent = 0 |
| 67 | for index, line in enumerate(lines): |
| 68 | if line.strip() == "on:": |
| 69 | on_start = index |
| 70 | on_indent = line_indent(line) |
| 71 | break |
| 72 | |
| 73 | if on_start is None: |
| 74 | return None |
| 75 | |
| 76 | on_end = len(lines) |
| 77 | for index in range(on_start + 1, len(lines)): |
| 78 | stripped = lines[index].strip() |
| 79 | if not stripped or stripped.startswith("#"): |
| 80 | continue |
| 81 | if line_indent(lines[index]) <= on_indent: |
| 82 | on_end = index |
| 83 | break |
| 84 | |
| 85 | child_indent = 2 |
| 86 | for index in range(on_start + 1, on_end): |
| 87 | stripped = lines[index].strip() |
| 88 | if not stripped or stripped.startswith("#"): |
| 89 | continue |
| 90 | indent = line_indent(lines[index]) |
| 91 | if indent > on_indent: |
| 92 | child_indent = indent |
| 93 | break |
| 94 | |
| 95 | event_starts: list[tuple[str, int]] = [] |
| 96 | for index in range(on_start + 1, on_end): |
| 97 | if line_indent(lines[index]) != child_indent: |
| 98 | continue |
| 99 | match = EVENT_RE.match(lines[index].strip()) |
| 100 | if match: |
| 101 | event_starts.append((match.group(1), index)) |
| 102 | |
| 103 | events: dict[str, EventBlock] = {} |
| 104 | for position, (name, start) in enumerate(event_starts): |
| 105 | end = ( |
| 106 | event_starts[position + 1][1] |
| 107 | if position + 1 < len(event_starts) |
| 108 | else on_end |
| 109 | ) |
| 110 | events[name] = EventBlock(name=name, start=start, end=end, indent=child_indent) |
| 111 | |
| 112 | return OnBlock(start=on_start, end=on_end, child_indent=child_indent, events=events) |
| 113 | |
| 114 | |
| 115 | def remove_pull_request_if_needed(path: Path, allow_pr: bool) -> WorkflowResult: |
no test coverage detected