From e185515ec4aac88e305f1257414947df99f5ecd3 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 12 Feb 2025 14:03:49 +0100 Subject: [PATCH 1/8] Remove default value main for branch parameter --- infrahub_sdk/ctl/cli_commands.py | 2 +- 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 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/infrahub_sdk/ctl/cli_commands.py b/infrahub_sdk/ctl/cli_commands.py index 568e02c8..19980eb2 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."), # TODO: Replace main by None + branch: str = typer.Option(None, help="Branch on which to run the script."), concurrent: int | None = typer.Option( None, help="Maximum number of requests to execute at the same time.", diff --git a/infrahub_sdk/ctl/exporter.py b/infrahub_sdk/ctl/exporter.py index c1e81412..ae5e5d18 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"), # TODO: Replace main by None + branch: str = typer.Option(None, help="Branch from which to export"), 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 00d88db5..4645fa06 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"), # TODO: Replace main by None + branch: str = typer.Option(None, help="Branch from which to export"), 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 533c0d0d..560564ed 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."), # TODO: Replace main by None + branch: str = typer.Option(None, help="Branch on which to load the menu."), _: 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 e619e229..b589fcc2 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."), # TODO: Replace main by None + branch: str = typer.Option(None, help="Branch on which to load the objects."), _: 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 8f793946..a8476200 100644 --- a/infrahub_sdk/ctl/repository.py +++ b/infrahub_sdk/ctl/repository.py @@ -74,7 +74,7 @@ async def add( ref: str = "", read_only: bool = False, debug: bool = False, - branch: str = typer.Option("main", help="Branch on which to add the repository."), # TODO: Replace main by None + branch: str = typer.Option(None, help="Branch on which to add the repository."), _: str = CONFIG_PARAM, ) -> None: """Add a new repository.""" diff --git a/infrahub_sdk/ctl/schema.py b/infrahub_sdk/ctl/schema.py index c3a2e794..6e9ff994 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."), # TODO: Replace main by None + branch: str = typer.Option(None, help="Branch on which to load the schema."), 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."), # TODO: Replace main by None + branch: str = typer.Option(None, help="Branch on which to check the schema."), _: str = CONFIG_PARAM, ) -> None: """Check if schema files are valid and what would be the impact of loading them with Infrahub.""" From 2c1ebf526301ac9aa6412f0fa69685109eaf8583 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 12 Feb 2025 14:05:17 +0100 Subject: [PATCH 2/8] Changelog --- changelog/264.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/264.fixed.md diff --git a/changelog/264.fixed.md b/changelog/264.fixed.md new file mode 100644 index 00000000..da596b06 --- /dev/null +++ b/changelog/264.fixed.md @@ -0,0 +1 @@ +Remove default value "main" for branch parameter from all Infrahub CTL commands. \ No newline at end of file From 9b7ffea97a3c9344805c8e4e1c80efa6f395719e Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 12 Feb 2025 14:31:34 +0100 Subject: [PATCH 3/8] Remove branch parameter from repository commands as node is branch agnostic --- infrahub_sdk/ctl/repository.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/infrahub_sdk/ctl/repository.py b/infrahub_sdk/ctl/repository.py index a8476200..3610ca1e 100644 --- a/infrahub_sdk/ctl/repository.py +++ b/infrahub_sdk/ctl/repository.py @@ -69,12 +69,11 @@ async def add( name: str, location: str, description: str = "", - username: str | None = None, + username: str = "", password: str = "", ref: str = "", read_only: bool = False, debug: bool = False, - branch: str = typer.Option(None, help="Branch on which to add the repository."), _: str = CONFIG_PARAM, ) -> None: """Add a new repository.""" @@ -111,18 +110,17 @@ async def add( query={"ok": None}, ) - await client.execute_graphql(query=query.render(), branch_name=branch, tracker="mutation-repository-create") + await client.execute_graphql(query=query.render(), tracker="mutation-repository-create") @app.command() async def list( - branch: str | None = None, debug: bool = False, _: str = CONFIG_PARAM, ) -> None: init_logging(debug=debug) - client = initialize_client(branch=branch) + client = initialize_client() repo_status_query = { "CoreGenericRepository": { @@ -142,7 +140,7 @@ async def list( } query = Query(name="GetRepositoryStatus", query=repo_status_query) - resp = await client.execute_graphql(query=query.render(), branch_name=branch, tracker="query-repository-list") + resp = await client.execute_graphql(query=query.render(), tracker="query-repository-list") table = Table(title="List of all Repositories") From e3c7d6f0517af6d23a610c588ebcfcc87d1acf66 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 12 Feb 2025 14:36:53 +0100 Subject: [PATCH 4/8] Add None for username --- infrahub_sdk/ctl/repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrahub_sdk/ctl/repository.py b/infrahub_sdk/ctl/repository.py index 3610ca1e..6c8cef29 100644 --- a/infrahub_sdk/ctl/repository.py +++ b/infrahub_sdk/ctl/repository.py @@ -69,7 +69,7 @@ async def add( name: str, location: str, description: str = "", - username: str = "", + username: str | None = None, password: str = "", ref: str = "", read_only: bool = False, From 4064ecf81a0995988baa43621549bab3fe6fd5eb Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 12 Feb 2025 14:42:32 +0100 Subject: [PATCH 5/8] Remove branch parameter from tests --- tests/unit/ctl/test_repository_app.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/unit/ctl/test_repository_app.py b/tests/unit/ctl/test_repository_app.py index 04d05ed4..63eec7e2 100644 --- a/tests/unit/ctl/test_repository_app.py +++ b/tests/unit/ctl/test_repository_app.py @@ -74,7 +74,6 @@ def test_repo_no_username_or_password(self, mock_init_client, mock_client) -> No } } """, - branch_name="main", tracker="mutation-repository-create", ) @@ -135,7 +134,6 @@ def test_repo_no_username(self, mock_init_client, mock_client) -> None: } } """, - branch_name="main", tracker="mutation-repository-create", ) @@ -198,7 +196,6 @@ def test_repo_username(self, mock_init_client, mock_client) -> None: } } """, - branch_name="main", tracker="mutation-repository-create", ) @@ -260,7 +257,6 @@ def test_repo_readonly_true(self, mock_init_client, mock_client) -> None: } } """, - branch_name="main", tracker="mutation-repository-create", ) @@ -329,7 +325,6 @@ def test_repo_description_commit_branch(self, mock_init_client, mock_client) -> } } """, - branch_name="develop", tracker="mutation-repository-create", ) From 833074d85001159da1675783e673a91ae9efd3ec Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 12 Feb 2025 14:48:14 +0100 Subject: [PATCH 6/8] Remove branch parameter from test --- tests/unit/ctl/test_repository_app.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit/ctl/test_repository_app.py b/tests/unit/ctl/test_repository_app.py index 63eec7e2..7fb01ee1 100644 --- a/tests/unit/ctl/test_repository_app.py +++ b/tests/unit/ctl/test_repository_app.py @@ -284,8 +284,6 @@ def test_repo_description_commit_branch(self, mock_init_client, mock_client) -> "This is a test description", "--ref", "my-custom-branch", - "--branch", - "develop", ], ) assert output.exit_code == 0 @@ -329,6 +327,6 @@ def test_repo_description_commit_branch(self, mock_init_client, mock_client) -> ) def test_repo_list(self, mock_repositories_list) -> None: - result = runner.invoke(app, ["repository", "list", "--branch", "main"]) + result = runner.invoke(app, ["repository", "list"]) assert result.exit_code == 0 assert strip_color(result.stdout) == read_fixture("output.txt", "integration/test_infrahubctl/repository_list") From c602b6637895be6b8baee147d94d2a2288b2d345 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Thu, 13 Feb 2025 13:55:03 +0100 Subject: [PATCH 7/8] Add option to list repository by branch --- infrahub_sdk/ctl/repository.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/infrahub_sdk/ctl/repository.py b/infrahub_sdk/ctl/repository.py index 6c8cef29..80318678 100644 --- a/infrahub_sdk/ctl/repository.py +++ b/infrahub_sdk/ctl/repository.py @@ -115,6 +115,7 @@ async def add( @app.command() async def list( + branch: str = typer.Option(None, help="Branch on which to check the schema."), debug: bool = False, _: str = CONFIG_PARAM, ) -> None: @@ -140,7 +141,7 @@ async def list( } query = Query(name="GetRepositoryStatus", query=repo_status_query) - resp = await client.execute_graphql(query=query.render(), tracker="query-repository-list") + resp = await client.execute_graphql(query=query.render(), branch_name=branch, tracker="query-repository-list") table = Table(title="List of all Repositories") From 7efa67df01d652795034f1ecce54b4a13e2e2afa Mon Sep 17 00:00:00 2001 From: Baptiste <32564248+BaptisteGi@users.noreply.github.com> Date: Tue, 18 Feb 2025 09:31:47 +0100 Subject: [PATCH 8/8] Adjust parameter help --- infrahub_sdk/ctl/repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrahub_sdk/ctl/repository.py b/infrahub_sdk/ctl/repository.py index 80318678..d999eabc 100644 --- a/infrahub_sdk/ctl/repository.py +++ b/infrahub_sdk/ctl/repository.py @@ -115,7 +115,7 @@ async def add( @app.command() async def list( - branch: str = typer.Option(None, help="Branch on which to check the schema."), + branch: str = typer.Option(None, help="Branch on which to list repositories."), debug: bool = False, _: str = CONFIG_PARAM, ) -> None: