Added listing descendant items.

This commit is contained in:
2025-11-03 00:09:05 +01:00
parent 53e1ae186e
commit 2f1e1a583f
2 changed files with 24 additions and 1 deletions

View File

@@ -229,10 +229,27 @@ class Item(DevOps):
get_url=f"{self._repository._project.id}/_apis/git/repositories/{self._repository.id}/items",
params={
"path": self._path,
"$format": "json"
"$format": "json",
"recursionLevel": "none"
}
)
@property
def path(self):
return self._path
@property
def children(self):
"""List items under this item if it is a folder."""
if self.git_object_type == "tree":
return self._entities(
entity_class=Item,
key_name="path",
list_url=f"{self._repository._project.id}/_apis/git/repositories/{self._repository.id}/items",
params={
"scopePath": self._path,
"recursionLevel": "oneLevel"
}
)
else:
raise ValueError("Items can only be listed for folder items.")

View File

@@ -38,3 +38,9 @@ print(f"Item type: {item.git_object_type}")
print(f"Item commit ID: {item.commit_id}")
print(f"Item URL: {item.url}")
print()
print("Listing items under the /container folder:")
docs_item = Item(repo, path="/container")
for sub_item in docs_item.children:
print(f"{sub_item.path} ({sub_item.git_object_type}): {sub_item.commit_id}")
print()