Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/+branch-graph-version-status.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `graph_version` and `status` properties to `Branch`
12 changes: 12 additions & 0 deletions infrahub_sdk/branch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import warnings
from enum import Enum
from typing import TYPE_CHECKING, Any, Literal, overload
from urllib.parse import urlencode

Expand All @@ -14,13 +15,22 @@
from .client import InfrahubClient, InfrahubClientSync


class BranchStatus(str, Enum):
OPEN = "OPEN"
NEED_REBASE = "NEED_REBASE"
NEED_UPGRADE_REBASE = "NEED_UPGRADE_REBASE"
DELETING = "DELETING"


class BranchData(BaseModel):
id: str
name: str
description: str | None = None
sync_with_git: bool
is_default: bool
has_schema_changes: bool
graph_version: int | None = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably also add status.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, we get that regardless with the query as seen in the integration tests..

status: BranchStatus = BranchStatus.OPEN
origin_branch: str | None = None
branched_from: str

Expand All @@ -34,6 +44,8 @@ class BranchData(BaseModel):
"is_default": None,
"sync_with_git": None,
"has_schema_changes": None,
"graph_version": None,
"status": None,
}

BRANCH_DATA_FILTER = {"@filters": {"name": "$branch_name"}}
Expand Down
3 changes: 3 additions & 0 deletions infrahub_sdk/ctl/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async def list_branch(_: str = CONFIG_PARAM) -> None:
table.add_column("Sync with Git")
table.add_column("Has Schema Changes")
table.add_column("Is Default")
table.add_column("Status")

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

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

console.print(table)
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/ctl/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ async def mock_branches_list_query(httpx_mock: HTTPXMock) -> HTTPXMock:
"origin_branch": "main",
"branched_from": "2023-02-17T09:30:17.811719Z",
"has_schema_changes": False,
"graph_version": 99,
"status": "OPEN",
},
{
"id": "7d9f817a-b958-4e76-8528-8afd0c689ada",
Expand All @@ -45,6 +47,8 @@ async def mock_branches_list_query(httpx_mock: HTTPXMock) -> HTTPXMock:
"origin_branch": "main",
"branched_from": "2023-02-17T09:30:17.811719Z",
"has_schema_changes": True,
"graph_version": None,
"status": "NEED_UPGRADE_REBASE",
},
]
}
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/sdk/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,8 @@ async def mock_branches_list_query(httpx_mock: HTTPXMock) -> HTTPXMock:
"origin_branch": "main",
"branched_from": "2023-02-17T09:30:17.811719Z",
"has_schema_changes": False,
"graph_version": 99,
"status": "OPEN",
},
{
"id": "7d9f817a-b958-4e76-8528-8afd0c689ada",
Expand All @@ -1507,6 +1509,8 @@ async def mock_branches_list_query(httpx_mock: HTTPXMock) -> HTTPXMock:
"origin_branch": "main",
"branched_from": "2023-02-17T09:30:17.811719Z",
"has_schema_changes": True,
"graph_version": None,
"status": "NEED_UPGRADE_REBASE",
},
]
}
Expand Down
Loading