|
6 | 6 | import yaml |
7 | 7 | from pydantic import ValidationError |
8 | 8 | from rich.console import Console |
| 9 | +from rich.table import Table |
9 | 10 |
|
10 | 11 | from infrahub_sdk.ctl.client import initialize_client |
11 | 12 |
|
12 | 13 | from ..async_typer import AsyncTyper |
13 | 14 | from ..ctl.exceptions import FileNotValidError |
14 | 15 | from ..ctl.utils import init_logging |
15 | | -from ..graphql import Mutation |
| 16 | +from ..graphql import Mutation, Query |
16 | 17 | from ..schema.repository import InfrahubRepositoryConfig |
17 | 18 | from ._file import read_file |
18 | 19 | from .parameters import CONFIG_PARAM |
@@ -102,3 +103,57 @@ async def add( |
102 | 103 | ) |
103 | 104 |
|
104 | 105 | await client.execute_graphql(query=query.render(), branch_name=branch, tracker="mutation-repository-create") |
| 106 | + |
| 107 | + |
| 108 | +@app.command() |
| 109 | +async def list( |
| 110 | + branch: str | None = None, |
| 111 | + debug: bool = False, |
| 112 | + _: str = CONFIG_PARAM, |
| 113 | +) -> None: |
| 114 | + init_logging(debug=debug) |
| 115 | + |
| 116 | + client = initialize_client(branch=branch) |
| 117 | + |
| 118 | + repo_status_query = { |
| 119 | + "CoreGenericRepository": { |
| 120 | + "edges": { |
| 121 | + "node": { |
| 122 | + "__typename": None, |
| 123 | + "name": {"value": None}, |
| 124 | + "operational_status": {"value": None}, |
| 125 | + "sync_status": {"value": None}, |
| 126 | + "internal_status": {"value": None}, |
| 127 | + "... on CoreReadOnlyRepository": { |
| 128 | + "ref": {"value": None}, |
| 129 | + }, |
| 130 | + } |
| 131 | + } |
| 132 | + }, |
| 133 | + } |
| 134 | + |
| 135 | + query = Query(name="GetRepositoryStatus", query=repo_status_query) |
| 136 | + resp = await client.execute_graphql(query=query.render(), branch_name=branch, tracker="query-repository-list") |
| 137 | + |
| 138 | + table = Table(title="List of all Repositories") |
| 139 | + |
| 140 | + table.add_column("Name", justify="right", style="cyan", no_wrap=True) |
| 141 | + table.add_column("Type") |
| 142 | + table.add_column("Operational status") |
| 143 | + table.add_column("Sync status") |
| 144 | + table.add_column("Internal status") |
| 145 | + table.add_column("Ref") |
| 146 | + |
| 147 | + for repository_node in resp["CoreGenericRepository"]["edges"]: |
| 148 | + repository = repository_node["node"] |
| 149 | + |
| 150 | + table.add_row( |
| 151 | + repository["name"]["value"], |
| 152 | + repository["__typename"], |
| 153 | + repository["operational_status"]["value"], |
| 154 | + repository["sync_status"]["value"], |
| 155 | + repository["internal_status"]["value"], |
| 156 | + repository["ref"]["value"] if "ref" in repository else "", |
| 157 | + ) |
| 158 | + |
| 159 | + console.print(table) |
0 commit comments