Skip to content

Commit 9f8073f

Browse files
committed
Add wait_until_completion to InfrahubBranchManager.create
1 parent a0afaa0 commit 9f8073f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

infrahub_sdk/branch.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import warnings
34
from typing import TYPE_CHECKING, Any, Optional, Union
45
from urllib.parse import urlencode
56

@@ -77,10 +78,19 @@ async def create(
7778
branch_name: str,
7879
sync_with_git: bool = True,
7980
description: str = "",
80-
background_execution: bool = False,
81-
) -> BranchData:
81+
wait_until_completion: bool = True,
82+
background_execution: Optional[bool] = False,
83+
) -> BranchData | str:
84+
if background_execution is not None:
85+
warnings.warn(
86+
"`background_execution` is deprecated, please use `wait_until_completion` instead.",
87+
DeprecationWarning,
88+
stacklevel=1,
89+
)
90+
91+
wait_until_completion = wait_until_completion or not background_execution
8292
input_data = {
83-
"background_execution": background_execution,
93+
"wait_until_completion": wait_until_completion,
8494
"data": {
8595
"name": branch_name,
8696
"description": description,
@@ -90,7 +100,8 @@ async def create(
90100

91101
query = Mutation(mutation="BranchCreate", input_data=input_data, query=MUTATION_QUERY_DATA)
92102
response = await self.client.execute_graphql(query=query.render(), tracker="mutation-branch-create")
93-
103+
if not wait_until_completion:
104+
return BranchData(**response["BranchCreate"]["task"]["id"])
94105
return BranchData(**response["BranchCreate"]["object"])
95106

96107
async def delete(self, branch_name: str) -> bool:

tests/integration/test_infrahub_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,7 @@ async def test_profile(self, client: InfrahubClient, db: InfrahubDatabase, init_
283283

284284
obj1 = await client.get(kind="BuiltinStatus", id=obj.id)
285285
assert obj1.description.value == "description in profile"
286+
287+
async def test_create_branch_async(self, client: InfrahubClient, db: InfrahubDatabase, init_db_base, base_dataset):
288+
task_id = await client.branch.create(branch_name="new-branch")
289+
assert isinstance(task_id, str)

0 commit comments

Comments
 (0)