Skip to content

Commit cce86a1

Browse files
authored
Merge pull request #248 from opsmill/develop
release v1.7.0
2 parents dbbe385 + 774cd52 commit cce86a1

File tree

18 files changed

+217
-31
lines changed

18 files changed

+217
-31
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ jobs:
116116

117117

118118
unit-tests:
119+
env:
120+
# workaround for Rich table column width
121+
COLUMNS: 140
119122
strategy:
120123
matrix:
121124
python-version:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang
1111

1212
<!-- towncrier release notes start -->
1313

14+
## [1.7.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.7.0) - 2025-01-23
15+
16+
### Added
17+
18+
- adds `infrahubctl repository list` command
19+
1420
## [1.6.1](https://github.com/opsmill/infrahub-sdk-python/tree/v1.6.1) - 2025-01-16
1521

1622
Fixes release of v1.6.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Aligned the environment variables used by the `infrahubctl` with the environment variables used by the SDK

changelog/towncrier.md.template

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{% if render_title %}
2+
{% if versiondata.name %}
3+
# {{ versiondata.name }} {{ versiondata.version }} ({{ versiondata.date }})
4+
{% else %}
5+
# {{ versiondata.version }} ({{ versiondata.date }})
6+
{% endif %}
7+
{% endif %}
8+
{% for section, _ in sections.items() %}
9+
{% if section %}
10+
11+
## {{section}}
12+
{% endif %}
13+
{% if sections[section] %}
14+
{% for category, val in definitions.items() if category in sections[section] %}
15+
### {{ definitions[category]['name'] }}
16+
17+
{% for text, values in sections[section][category].items() %}
18+
- {{ text }}
19+
{%- if values %}
20+
{% if "\n - " in text or '\n * ' in text %}
21+
22+
23+
(
24+
{%- else %}
25+
{% if text %} ({% endif %}
26+
{%- endif -%}
27+
{%- for issue in values %}
28+
{{ issue.split(": ", 1)[0] }}{% if not loop.last %}, {% endif %}
29+
{%- endfor %}
30+
{% if text %}){% endif %}
31+
32+
{% else %}
33+
34+
{% endif %}
35+
{% endfor %}
36+
37+
{% if issues_by_category[section][category] and "]: " in issues_by_category[section][category][0] %}
38+
{% for issue in issues_by_category[section][category] %}
39+
{{ issue }}
40+
{% endfor %}
41+
42+
{% endif %}
43+
{% if sections[section][category]|length == 0 %}
44+
No significant changes.
45+
46+
{% else %}
47+
{% endif %}
48+
{% endfor %}
49+
{% else %}
50+
No significant changes.
51+
52+
{% endif %}
53+
{% endfor +%}

infrahub_sdk/ctl/cli_commands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ async def run(
130130
debug: bool = False,
131131
_: str = CONFIG_PARAM,
132132
branch: str = typer.Option("main", help="Branch on which to run the script."),
133-
concurrent: int = typer.Option(
134-
4,
133+
concurrent: int | None = typer.Option(
134+
None,
135135
help="Maximum number of requests to execute at the same time.",
136-
envvar="INFRAHUBCTL_CONCURRENT_EXECUTION",
136+
envvar="INFRAHUB_MAX_CONCURRENT_EXECUTION",
137137
),
138-
timeout: int = typer.Option(60, help="Timeout in sec", envvar="INFRAHUBCTL_TIMEOUT"),
138+
timeout: int = typer.Option(60, help="Timeout in sec", envvar="INFRAHUB_TIMEOUT"),
139139
variables: list[str] | None = typer.Argument(
140140
None, help="Variables to pass along with the query. Format key=value key=value."
141141
),

infrahub_sdk/ctl/exporter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def dump(
2626
concurrent: int = typer.Option(
2727
4,
2828
help="Maximum number of requests to execute at the same time.",
29-
envvar="INFRAHUBCTL_CONCURRENT_EXECUTION",
29+
envvar="INFRAHUB_MAX_CONCURRENT_EXECUTION",
3030
),
31-
timeout: int = typer.Option(60, help="Timeout in sec", envvar="INFRAHUBCTL_TIMEOUT"),
31+
timeout: int = typer.Option(60, help="Timeout in sec", envvar="INFRAHUB_TIMEOUT"),
3232
exclude: list[str] = typer.Option(
3333
["CoreAccount"],
3434
help="Prevent node kind(s) from being exported, CoreAccount is excluded by default",

infrahub_sdk/ctl/importer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from asyncio import run as aiorun
24
from pathlib import Path
35

@@ -24,12 +26,12 @@ def load(
2426
quiet: bool = typer.Option(False, help="No console output"),
2527
_: str = CONFIG_PARAM,
2628
branch: str = typer.Option("main", help="Branch from which to export"),
27-
concurrent: int = typer.Option(
28-
4,
29+
concurrent: int | None = typer.Option(
30+
None,
2931
help="Maximum number of requests to execute at the same time.",
30-
envvar="INFRAHUBCTL_CONCURRENT_EXECUTION",
32+
envvar="INFRAHUB_MAX_CONCURRENT_EXECUTION",
3133
),
32-
timeout: int = typer.Option(60, help="Timeout in sec", envvar="INFRAHUBCTL_TIMEOUT"),
34+
timeout: int = typer.Option(60, help="Timeout in sec", envvar="INFRAHUB_TIMEOUT"),
3335
) -> None:
3436
"""Import nodes and their relationships into the database."""
3537
console = Console()

infrahub_sdk/ctl/repository.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import yaml
77
from pydantic import ValidationError
88
from rich.console import Console
9+
from rich.table import Table
910

1011
from infrahub_sdk.ctl.client import initialize_client
1112

1213
from ..async_typer import AsyncTyper
1314
from ..ctl.exceptions import FileNotValidError
1415
from ..ctl.utils import init_logging
15-
from ..graphql import Mutation
16+
from ..graphql import Mutation, Query
1617
from ..schema.repository import InfrahubRepositoryConfig
1718
from ._file import read_file
1819
from .parameters import CONFIG_PARAM
@@ -102,3 +103,57 @@ async def add(
102103
)
103104

104105
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)

infrahub_sdk/pytest_plugin/items/graphql_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def repr_failure(self, excinfo: ExceptionInfo, style: str | None = None) -> str:
4040
)
4141

4242
if isinstance(excinfo.value, OutputMatchError):
43-
return "\n".join([excinfo.value.message, excinfo.value.differences])
43+
return f"{excinfo.value.message}\n{excinfo.value.differences}"
4444

4545
return super().repr_failure(excinfo, style=style)
4646

infrahub_sdk/pytest_plugin/items/jinja2_transform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def repr_failure(self, excinfo: ExceptionInfo, style: str | None = None) -> str:
7979
return "\n".join(["Syntax error detected in the template", excinfo.value.message or ""])
8080

8181
if isinstance(excinfo.value, OutputMatchError):
82-
return "\n".join([excinfo.value.message, excinfo.value.differences])
82+
return f"{excinfo.value.message}\n{excinfo.value.differences}"
8383

8484
return super().repr_failure(excinfo, style=style)
8585

0 commit comments

Comments
 (0)