(path: Path, allow_pr: bool)
| 113 | |
| 114 | |
| 115 | def remove_pull_request_if_needed(path: Path, allow_pr: bool) -> WorkflowResult: |
| 116 | original_text = path.read_text(encoding="utf-8") |
| 117 | if allow_pr: |
| 118 | return WorkflowResult(path, (), original_text, original_text) |
| 119 | |
| 120 | lines = original_text.splitlines(keepends=True) |
| 121 | on_block = find_on_block(lines) |
| 122 | if on_block is None: |
| 123 | return WorkflowResult(path, (), original_text, original_text) |
| 124 | |
| 125 | pull_request = on_block.events.get("pull_request") |
| 126 | if pull_request is None: |
| 127 | return WorkflowResult(path, (), original_text, original_text) |
| 128 | |
| 129 | updated_lines = lines[: pull_request.start] + lines[pull_request.end :] |
| 130 | return WorkflowResult( |
| 131 | path=path, |
| 132 | changes=("remove pull_request",), |
| 133 | original_text=original_text, |
| 134 | updated_text="".join(updated_lines), |
| 135 | ) |
| 136 | |
| 137 | |
| 138 | def workflow_files(workflows_dir: Path) -> list[Path]: |
no test coverage detected