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