Added listing descendant items.
This commit is contained in:
19
devops.py
19
devops.py
@@ -229,10 +229,27 @@ class Item(DevOps):
|
|||||||
get_url=f"{self._repository._project.id}/_apis/git/repositories/{self._repository.id}/items",
|
get_url=f"{self._repository._project.id}/_apis/git/repositories/{self._repository.id}/items",
|
||||||
params={
|
params={
|
||||||
"path": self._path,
|
"path": self._path,
|
||||||
"$format": "json"
|
"$format": "json",
|
||||||
|
"recursionLevel": "none"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self):
|
def path(self):
|
||||||
return self._path
|
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.")
|
||||||
|
|||||||
@@ -38,3 +38,9 @@ print(f"Item type: {item.git_object_type}")
|
|||||||
print(f"Item commit ID: {item.commit_id}")
|
print(f"Item commit ID: {item.commit_id}")
|
||||||
print(f"Item URL: {item.url}")
|
print(f"Item URL: {item.url}")
|
||||||
print()
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user