|
7 | 7 | from smith.cli.handlers import ( |
8 | 8 | _csv_list, |
9 | 9 | handle_cache_clean, |
| 10 | + handle_ci_artifacts_grep, |
| 11 | + handle_ci_artifacts_list, |
10 | 12 | handle_ci_grep, |
11 | 13 | handle_ci_list, |
12 | 14 | handle_code_grep, |
@@ -183,6 +185,32 @@ def _add_ci_grep_options(parser: argparse.ArgumentParser) -> None: |
183 | 185 | parser.add_argument("--case-sensitive", action="store_true") |
184 | 186 |
|
185 | 187 |
|
| 188 | +def _add_artifact_grep_options(parser: argparse.ArgumentParser) -> None: |
| 189 | + parser.add_argument("--path", help="Artifact path scope within the extracted archive") |
| 190 | + parser.add_argument("--glob", help="Artifact filename glob filter") |
| 191 | + parser.add_argument( |
| 192 | + "pattern", |
| 193 | + help=( |
| 194 | + 'Regex pattern. Use ".*" to match all. ' |
| 195 | + 'Form: smith <remote> pipelines artifacts grep <scope> <pipeline_id> <job_id> "<regex>"' |
| 196 | + ), |
| 197 | + ) |
| 198 | + parser.add_argument( |
| 199 | + "--output-mode", |
| 200 | + choices=["content", "files_with_matches", "count"], |
| 201 | + default="content", |
| 202 | + ) |
| 203 | + parser.add_argument("--context-lines", type=int, default=3) |
| 204 | + parser.add_argument("--from-line", type=int) |
| 205 | + parser.add_argument("--to-line", type=int) |
| 206 | + parser.add_argument( |
| 207 | + "--reverse", |
| 208 | + action="store_true", |
| 209 | + help="Emit matches in reverse order so the most recent hits appear first.", |
| 210 | + ) |
| 211 | + parser.add_argument("--case-sensitive", action="store_true") |
| 212 | + |
| 213 | + |
186 | 214 | def _add_work_search_filters(parser: argparse.ArgumentParser, *, include_area: bool = True) -> None: |
187 | 215 | if include_area: |
188 | 216 | parser.add_argument("--area") |
@@ -549,6 +577,56 @@ def _add_remote_pipelines_group(remote_subparsers: Any, *, remote: RemoteConfig) |
549 | 577 | _add_output_format(pipelines_grep) |
550 | 578 | _set_handler(pipelines_grep, handle_ci_grep, "pipelines.grep", primary_path="pipelines grep") |
551 | 579 |
|
| 580 | + if remote.provider == "gitlab": |
| 581 | + pipelines_artifacts = _add_parser( |
| 582 | + pipelines_sub, |
| 583 | + "artifacts", |
| 584 | + help_text="List and grep GitLab job artifacts", |
| 585 | + ) |
| 586 | + pipelines_artifacts_sub = pipelines_artifacts.add_subparsers( |
| 587 | + dest="pipelines_artifacts_action", |
| 588 | + required=True, |
| 589 | + ) |
| 590 | + |
| 591 | + pipelines_artifacts_list = _add_parser( |
| 592 | + pipelines_artifacts_sub, |
| 593 | + "list", |
| 594 | + help_text="List artifact paths for a job", |
| 595 | + ) |
| 596 | + _add_pipeline_positional_args( |
| 597 | + pipelines_artifacts_list, |
| 598 | + remote=remote, |
| 599 | + id_label=id_label, |
| 600 | + ) |
| 601 | + pipelines_artifacts_list.add_argument("job_id", type=int, help="Job ID") |
| 602 | + _add_output_format(pipelines_artifacts_list) |
| 603 | + _set_handler( |
| 604 | + pipelines_artifacts_list, |
| 605 | + handle_ci_artifacts_list, |
| 606 | + "pipelines.artifacts.list", |
| 607 | + primary_path="pipelines artifacts list", |
| 608 | + ) |
| 609 | + |
| 610 | + pipelines_artifacts_grep = _add_parser( |
| 611 | + pipelines_artifacts_sub, |
| 612 | + "grep", |
| 613 | + help_text="Search extracted GitLab job artifacts", |
| 614 | + ) |
| 615 | + _add_pipeline_positional_args( |
| 616 | + pipelines_artifacts_grep, |
| 617 | + remote=remote, |
| 618 | + id_label=id_label, |
| 619 | + ) |
| 620 | + pipelines_artifacts_grep.add_argument("job_id", type=int, help="Job ID") |
| 621 | + _add_artifact_grep_options(pipelines_artifacts_grep) |
| 622 | + _add_output_format(pipelines_artifacts_grep) |
| 623 | + _set_handler( |
| 624 | + pipelines_artifacts_grep, |
| 625 | + handle_ci_artifacts_grep, |
| 626 | + "pipelines.artifacts.grep", |
| 627 | + primary_path="pipelines artifacts grep", |
| 628 | + ) |
| 629 | + |
552 | 630 |
|
553 | 631 | def _add_remote_stories_group(remote_subparsers: Any, *, remote: RemoteConfig) -> None: |
554 | 632 | stories = _add_parser(remote_subparsers, "stories", help_text="Get, search, and get mine") |
|
0 commit comments