Skip to content

Commit 3762cf5

Browse files
committed
adds infrahubctl repository list command
1 parent 3bf1c5c commit 3762cf5

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

infrahub_sdk/ctl/repository.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import yaml
66
from pydantic import ValidationError
77
from rich.console import Console
8+
from rich.table import Table
89

910
from infrahub_sdk.ctl.client import initialize_client
1011

1112
from ..async_typer import AsyncTyper
1213
from ..ctl.exceptions import FileNotValidError
1314
from ..ctl.utils import init_logging
14-
from ..graphql import Mutation
15+
from ..graphql import Mutation, Query
1516
from ..schema import InfrahubRepositoryConfig
1617
from ._file import read_file
1718
from .parameters import CONFIG_PARAM
@@ -101,3 +102,63 @@ async def add(
101102
)
102103

103104
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

Comments
 (0)