|
| 1 | +import click |
| 2 | + |
| 3 | +from kcidev.subcommands.detect.helper import ( |
| 4 | + get_issues, |
| 5 | + get_issues_for_specific_item, |
| 6 | + print_stats, |
| 7 | +) |
| 8 | +from kcidev.subcommands.results import trees |
| 9 | + |
| 10 | + |
| 11 | +@click.command( |
| 12 | + name="issues", |
| 13 | + help="""Detect KCIDB issues for builds and boots |
| 14 | +
|
| 15 | +\b |
| 16 | +The command is used to fetch KCIDB issues associated with builds and boots. |
| 17 | +Provide `--builds` and `--boots` option for builds issue detection and boots |
| 18 | +issue detection respectively. |
| 19 | +`--all-checkouts` option can be used to fetch KCIDB issues for all the |
| 20 | +failed and inconclusive builds/boots from all available trees on the dashboard. |
| 21 | +Issues for a single build/boot can be retrieved by providing `--id` |
| 22 | +option. |
| 23 | + |
| 24 | +\b |
| 25 | +Examples: |
| 26 | + # Detect build issues |
| 27 | + kci-dev detect issues --builds --id <build-id> |
| 28 | + kci-dev detect issues --builds --all-checkouts --days <number-of-days> --origin <origin> |
| 29 | + # Detect boot issues |
| 30 | + kci-dev detect issues --boots --id <boot-id> |
| 31 | + kci-dev detect issues --boots --all-checkouts --days <number-of-days> --origin <origin> |
| 32 | +""", |
| 33 | +) |
| 34 | +@click.option( |
| 35 | + "--origin", |
| 36 | + help="Select KCIDB origin", |
| 37 | + default="maestro", |
| 38 | +) |
| 39 | +@click.option( |
| 40 | + "--builds", |
| 41 | + is_flag=True, |
| 42 | + help="Fetch KCIDB issues for builds", |
| 43 | +) |
| 44 | +@click.option( |
| 45 | + "--boots", |
| 46 | + is_flag=True, |
| 47 | + help="Fetch KCIDB issues for boots", |
| 48 | +) |
| 49 | +@click.option( |
| 50 | + "--id", |
| 51 | + "item_id", |
| 52 | + help="Build/boot id to get issues for", |
| 53 | +) |
| 54 | +@click.option( |
| 55 | + "--all-checkouts", |
| 56 | + is_flag=True, |
| 57 | + help="Fetch KCIDB issues for all failed/inconclusive builds/boots of all available checkouts", |
| 58 | +) |
| 59 | +@click.option("--arch", help="Filter by arch") |
| 60 | +@click.option( |
| 61 | + "--days", |
| 62 | + help="Provide a period of time in days to get results for", |
| 63 | + type=int, |
| 64 | + default="7", |
| 65 | +) |
| 66 | +@click.pass_context |
| 67 | +def issues( |
| 68 | + ctx, |
| 69 | + origin, |
| 70 | + builds, |
| 71 | + boots, |
| 72 | + item_id, |
| 73 | + all_checkouts, |
| 74 | + arch, |
| 75 | + days, |
| 76 | +): |
| 77 | + |
| 78 | + if not (builds or boots): |
| 79 | + raise click.UsageError("Provide --builds or --boots to fetch issues for") |
| 80 | + |
| 81 | + if builds and boots: |
| 82 | + raise click.UsageError("Specify only one option from --builds and --boots") |
| 83 | + |
| 84 | + item_type = "builds" if builds else "boots" |
| 85 | + |
| 86 | + if not (all_checkouts or item_id): |
| 87 | + raise click.UsageError("Provide --all-checkouts or --id") |
| 88 | + |
| 89 | + print("Fetching KCIDB issues...") |
| 90 | + if all_checkouts: |
| 91 | + if item_id: |
| 92 | + raise click.UsageError("Cannot use --all-checkouts with --id") |
| 93 | + final_stats = [] |
| 94 | + trees_list = ctx.invoke(trees, origin=origin, days=days, verbose=False) |
| 95 | + for tree in trees_list: |
| 96 | + giturl = tree["git_repository_url"] |
| 97 | + branch = tree["git_repository_branch"] |
| 98 | + commit = tree["git_commit_hash"] |
| 99 | + tree_name = tree["tree_name"] |
| 100 | + stats = get_issues( |
| 101 | + ctx, origin, item_type, giturl, branch, commit, tree_name, arch |
| 102 | + ) |
| 103 | + final_stats.extend(stats) |
| 104 | + if final_stats: |
| 105 | + headers = [ |
| 106 | + "tree/branch", |
| 107 | + "ID", |
| 108 | + "Issues", |
| 109 | + ] |
| 110 | + max_col_width = [None, None, None] |
| 111 | + table_fmt = "simple_grid" |
| 112 | + print_stats(final_stats, headers, max_col_width, table_fmt) |
| 113 | + |
| 114 | + elif item_id: |
| 115 | + stats = get_issues_for_specific_item(item_type, item_id) |
| 116 | + if stats: |
| 117 | + headers = [ |
| 118 | + "ID", |
| 119 | + "Issues", |
| 120 | + ] |
| 121 | + max_col_width = [None, None] |
| 122 | + table_fmt = "simple_grid" |
| 123 | + print_stats(stats, headers, max_col_width, table_fmt) |
0 commit comments