Skip to content

Commit 9fb8d3c

Browse files
authored
Add graph_version and status to branch (#600)
1 parent 115333e commit 9fb8d3c

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `graph_version` and `status` properties to `Branch`

infrahub_sdk/branch.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import warnings
4+
from enum import Enum
45
from typing import TYPE_CHECKING, Any, Literal, overload
56
from urllib.parse import urlencode
67

@@ -14,13 +15,22 @@
1415
from .client import InfrahubClient, InfrahubClientSync
1516

1617

18+
class BranchStatus(str, Enum):
19+
OPEN = "OPEN"
20+
NEED_REBASE = "NEED_REBASE"
21+
NEED_UPGRADE_REBASE = "NEED_UPGRADE_REBASE"
22+
DELETING = "DELETING"
23+
24+
1725
class BranchData(BaseModel):
1826
id: str
1927
name: str
2028
description: str | None = None
2129
sync_with_git: bool
2230
is_default: bool
2331
has_schema_changes: bool
32+
graph_version: int | None = None
33+
status: BranchStatus = BranchStatus.OPEN
2434
origin_branch: str | None = None
2535
branched_from: str
2636

@@ -34,6 +44,8 @@ class BranchData(BaseModel):
3444
"is_default": None,
3545
"sync_with_git": None,
3646
"has_schema_changes": None,
47+
"graph_version": None,
48+
"status": None,
3749
}
3850

3951
BRANCH_DATA_FILTER = {"@filters": {"name": "$branch_name"}}

infrahub_sdk/ctl/branch.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ async def list_branch(_: str = CONFIG_PARAM) -> None:
4646
table.add_column("Sync with Git")
4747
table.add_column("Has Schema Changes")
4848
table.add_column("Is Default")
49+
table.add_column("Status")
4950

5051
# identify the default branch and always print it first
5152
default_branch = [branch for branch in branches.values() if branch.is_default][0]
@@ -57,6 +58,7 @@ async def list_branch(_: str = CONFIG_PARAM) -> None:
5758
"[green]True" if default_branch.sync_with_git else "[#FF7F50]False",
5859
"[green]True" if default_branch.has_schema_changes else "[#FF7F50]False",
5960
"[green]True" if default_branch.is_default else "[#FF7F50]False",
61+
default_branch.status,
6062
)
6163

6264
for branch in branches.values():
@@ -71,6 +73,7 @@ async def list_branch(_: str = CONFIG_PARAM) -> None:
7173
"[green]True" if branch.sync_with_git else "[#FF7F50]False",
7274
"[green]True" if default_branch.has_schema_changes else "[#FF7F50]False",
7375
"[green]True" if branch.is_default else "[#FF7F50]False",
76+
branch.status,
7477
)
7578

7679
console.print(table)

tests/unit/ctl/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ async def mock_branches_list_query(httpx_mock: HTTPXMock) -> HTTPXMock:
3636
"origin_branch": "main",
3737
"branched_from": "2023-02-17T09:30:17.811719Z",
3838
"has_schema_changes": False,
39+
"graph_version": 99,
40+
"status": "OPEN",
3941
},
4042
{
4143
"id": "7d9f817a-b958-4e76-8528-8afd0c689ada",
@@ -45,6 +47,8 @@ async def mock_branches_list_query(httpx_mock: HTTPXMock) -> HTTPXMock:
4547
"origin_branch": "main",
4648
"branched_from": "2023-02-17T09:30:17.811719Z",
4749
"has_schema_changes": True,
50+
"graph_version": None,
51+
"status": "NEED_UPGRADE_REBASE",
4852
},
4953
]
5054
}

tests/unit/sdk/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,8 @@ async def mock_branches_list_query(httpx_mock: HTTPXMock) -> HTTPXMock:
14981498
"origin_branch": "main",
14991499
"branched_from": "2023-02-17T09:30:17.811719Z",
15001500
"has_schema_changes": False,
1501+
"graph_version": 99,
1502+
"status": "OPEN",
15011503
},
15021504
{
15031505
"id": "7d9f817a-b958-4e76-8528-8afd0c689ada",
@@ -1507,6 +1509,8 @@ async def mock_branches_list_query(httpx_mock: HTTPXMock) -> HTTPXMock:
15071509
"origin_branch": "main",
15081510
"branched_from": "2023-02-17T09:30:17.811719Z",
15091511
"has_schema_changes": True,
1512+
"graph_version": None,
1513+
"status": "NEED_UPGRADE_REBASE",
15101514
},
15111515
]
15121516
}

0 commit comments

Comments
 (0)