From aa65bb01e54367e5b7ffa118b5a14431af3ec1c7 Mon Sep 17 00:00:00 2001 From: Baptiste <32564248+BaptisteGi@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:39:00 +0100 Subject: [PATCH] Protocols command consumes default branch from env (#263) * Get default branch from env * Add comment on all hardcoded main branch to be fixed later * Add release note --- changelog/104.fixed.md | 1 + infrahub_sdk/ctl/cli_commands.py | 3 ++- infrahub_sdk/ctl/exporter.py | 2 +- infrahub_sdk/ctl/importer.py | 2 +- infrahub_sdk/ctl/menu.py | 2 +- infrahub_sdk/ctl/object.py | 2 +- infrahub_sdk/ctl/repository.py | 2 +- infrahub_sdk/ctl/schema.py | 4 ++-- 8 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 changelog/104.fixed.md diff --git a/changelog/104.fixed.md b/changelog/104.fixed.md new file mode 100644 index 0000000..e6e64a7 --- /dev/null +++ b/changelog/104.fixed.md @@ -0,0 +1 @@ +- `protocols` CTL command properly gets default branch setting from environment variable \ No newline at end of file diff --git a/infrahub_sdk/ctl/cli_commands.py b/infrahub_sdk/ctl/cli_commands.py index 3cb23a5..568e02c 100644 --- a/infrahub_sdk/ctl/cli_commands.py +++ b/infrahub_sdk/ctl/cli_commands.py @@ -129,7 +129,7 @@ async def run( method: str = "run", debug: bool = False, _: str = CONFIG_PARAM, - branch: str = typer.Option("main", help="Branch on which to run the script."), + branch: str = typer.Option("main", help="Branch on which to run the script."), # TODO: Replace main by None concurrent: int | None = typer.Option( None, help="Maximum number of requests to execute at the same time.", @@ -383,6 +383,7 @@ def protocols( else: client = initialize_client_sync() + branch = branch or client.default_branch schema.update(client.schema.fetch(branch=branch)) code_generator = CodeGenerator(schema=schema) diff --git a/infrahub_sdk/ctl/exporter.py b/infrahub_sdk/ctl/exporter.py index 50be328..c1e8141 100644 --- a/infrahub_sdk/ctl/exporter.py +++ b/infrahub_sdk/ctl/exporter.py @@ -22,7 +22,7 @@ def dump( directory: Path = typer.Option(directory_name_with_timestamp, help="Directory path to store export"), quiet: bool = typer.Option(False, help="No console output"), _: str = CONFIG_PARAM, - branch: str = typer.Option("main", help="Branch from which to export"), + branch: str = typer.Option("main", help="Branch from which to export"), # TODO: Replace main by None concurrent: int = typer.Option( 4, help="Maximum number of requests to execute at the same time.", diff --git a/infrahub_sdk/ctl/importer.py b/infrahub_sdk/ctl/importer.py index be08736..00d88db 100644 --- a/infrahub_sdk/ctl/importer.py +++ b/infrahub_sdk/ctl/importer.py @@ -25,7 +25,7 @@ def load( ), quiet: bool = typer.Option(False, help="No console output"), _: str = CONFIG_PARAM, - branch: str = typer.Option("main", help="Branch from which to export"), + branch: str = typer.Option("main", help="Branch from which to export"), # TODO: Replace main by None concurrent: int | None = typer.Option( None, help="Maximum number of requests to execute at the same time.", diff --git a/infrahub_sdk/ctl/menu.py b/infrahub_sdk/ctl/menu.py index fe9798f..533c0d0 100644 --- a/infrahub_sdk/ctl/menu.py +++ b/infrahub_sdk/ctl/menu.py @@ -27,7 +27,7 @@ def callback() -> None: async def load( menus: list[Path], debug: bool = False, - branch: str = typer.Option("main", help="Branch on which to load the menu."), + branch: str = typer.Option("main", help="Branch on which to load the menu."), # TODO: Replace main by None _: str = CONFIG_PARAM, ) -> None: """Load one or multiple menu files into Infrahub.""" diff --git a/infrahub_sdk/ctl/object.py b/infrahub_sdk/ctl/object.py index 5f8e71c..e619e22 100644 --- a/infrahub_sdk/ctl/object.py +++ b/infrahub_sdk/ctl/object.py @@ -27,7 +27,7 @@ def callback() -> None: async def load( paths: list[Path], debug: bool = False, - branch: str = typer.Option("main", help="Branch on which to load the objects."), + branch: str = typer.Option("main", help="Branch on which to load the objects."), # TODO: Replace main by None _: str = CONFIG_PARAM, ) -> None: """Load one or multiple objects files into Infrahub.""" diff --git a/infrahub_sdk/ctl/repository.py b/infrahub_sdk/ctl/repository.py index e57ee6b..09003f6 100644 --- a/infrahub_sdk/ctl/repository.py +++ b/infrahub_sdk/ctl/repository.py @@ -74,7 +74,7 @@ async def add( commit: str = "", read_only: bool = False, debug: bool = False, - branch: str = typer.Option("main", help="Branch on which to add the repository."), + branch: str = typer.Option("main", help="Branch on which to add the repository."), # TODO: Replace main by None _: str = CONFIG_PARAM, ) -> None: """Add a new repository.""" diff --git a/infrahub_sdk/ctl/schema.py b/infrahub_sdk/ctl/schema.py index 3c9557c..c3a2e79 100644 --- a/infrahub_sdk/ctl/schema.py +++ b/infrahub_sdk/ctl/schema.py @@ -108,7 +108,7 @@ def get_node(schemas_data: list[dict], schema_index: int, node_index: int) -> di async def load( schemas: list[Path], debug: bool = False, - branch: str = typer.Option("main", help="Branch on which to load the schema."), + branch: str = typer.Option("main", help="Branch on which to load the schema."), # TODO: Replace main by None wait: int = typer.Option(0, help="Time in seconds to wait until the schema has converged across all workers"), _: str = CONFIG_PARAM, ) -> None: @@ -159,7 +159,7 @@ async def load( async def check( schemas: list[Path], debug: bool = False, - branch: str = typer.Option("main", help="Branch on which to check the schema."), + branch: str = typer.Option("main", help="Branch on which to check the schema."), # TODO: Replace main by None _: str = CONFIG_PARAM, ) -> None: """Check if schema files are valid and what would be the impact of loading them with Infrahub."""