Skip to content

Commit 8f2f07e

Browse files
committed
feat: add create_diff method and enhance get_diff_summary to support time range filtering
1 parent b121963 commit 8f2f07e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

infrahub_sdk/client.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,12 +1164,14 @@ async def create_diff(
11641164
"to_time": to_time.isoformat(),
11651165
},
11661166
}
1167+
11671168
mutation_query = MUTATION_QUERY_TASK if not wait_until_completion else {"ok": None}
11681169
query = Mutation(mutation="DiffUpdate", input_data=input_data, query=mutation_query)
1169-
print(query.render())
11701170
response = await self.execute_graphql(query=query.render(), tracker="mutation-diff-update")
1171+
11711172
if not wait_until_completion and "task" in response["DiffUpdate"]:
11721173
return response["DiffUpdate"]["task"]["id"]
1174+
11731175
return response["DiffUpdate"]["ok"]
11741176

11751177
async def get_diff_summary(
@@ -2317,11 +2319,37 @@ def query_gql_query(
23172319
resp.raise_for_status()
23182320

23192321
return decode_json(response=resp)
2322+
2323+
def create_diff(
2324+
self, branch: str, name: str, from_time: datetime, to_time: datetime, wait_until_completion: bool = True
2325+
) -> str:
2326+
input_data = {
2327+
# Should be switched to `wait_until_completion` once `background_execution` is removed server side.
2328+
"wait_until_completion": wait_until_completion,
2329+
"data": {
2330+
"name": name,
2331+
"branch": branch,
2332+
"from_time": from_time.isoformat(),
2333+
"to_time": to_time.isoformat(),
2334+
},
2335+
}
2336+
2337+
mutation_query = MUTATION_QUERY_TASK if not wait_until_completion else {"ok": None}
2338+
query = Mutation(mutation="DiffUpdate", input_data=input_data, query=mutation_query)
2339+
response = self.execute_graphql(query=query.render(), tracker="mutation-diff-update")
2340+
2341+
if not wait_until_completion and "task" in response["DiffUpdate"]:
2342+
return response["DiffUpdate"]["task"]["id"]
2343+
2344+
return response["DiffUpdate"]["ok"]
2345+
23202346

23212347
def get_diff_summary(
23222348
self,
23232349
branch: str,
23242350
name: str | None = None,
2351+
from_time: datetime | None = None,
2352+
to_time: datetime | None = None,
23252353
timeout: int | None = None,
23262354
tracker: str | None = None,
23272355
raise_for_error: bool = True,
@@ -2330,6 +2358,9 @@ def get_diff_summary(
23302358
input_data = {"branch_name": branch}
23312359
if name:
23322360
input_data["name"] = name
2361+
if from_time and to_time:
2362+
input_data["from_time"] = from_time.isoformat()
2363+
input_data["to_time"] = to_time.isoformat()
23332364
response = self.execute_graphql(
23342365
query=query,
23352366
branch_name=branch,

0 commit comments

Comments
 (0)