Modified Item's get_child_items to accept pattern and recurse parameters to support looking for specific patterns in the repository.
This commit is contained in:
@@ -274,7 +274,7 @@ class Item():
|
|||||||
def path(self):
|
def path(self):
|
||||||
return self._path # type: ignore[attr-defined]
|
return self._path # type: ignore[attr-defined]
|
||||||
|
|
||||||
def get_child_items(self) -> list[Item]:
|
def get_child_items(self, pattern: str | None = None, recurse: bool = False) -> list[Item]:
|
||||||
"""Get child items if this item is a folder."""
|
"""Get child items if this item is a folder."""
|
||||||
if self.git_object_type != "tree": # type: ignore[attr-defined]
|
if self.git_object_type != "tree": # type: ignore[attr-defined]
|
||||||
raise ValueError("Child items can only be fetched for folder items.")
|
raise ValueError("Child items can only be fetched for folder items.")
|
||||||
@@ -284,12 +284,15 @@ class Item():
|
|||||||
path=f"{self._repository.project.id}/_apis/git/repositories/{self._repository.id}/items",
|
path=f"{self._repository.project.id}/_apis/git/repositories/{self._repository.id}/items",
|
||||||
params={
|
params={
|
||||||
"scopePath": self.path,
|
"scopePath": self.path,
|
||||||
"recursionLevel": "oneLevel"
|
"recursionLevel": "oneLevel" if not recurse else "full"
|
||||||
}
|
}
|
||||||
).json().get("value", [])
|
).json().get("value", [])
|
||||||
child_items = []
|
child_items = []
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
i = Item(repository=self._repository, path=obj.get("path"))
|
obj_path = obj.get("path")
|
||||||
|
if pattern and not pathlib.PurePath(obj_path).match(pattern):
|
||||||
|
continue
|
||||||
|
i = Item(repository=self._repository, path=obj_path)
|
||||||
i.from_json(obj) # type: ignore[attr-defined]
|
i.from_json(obj) # type: ignore[attr-defined]
|
||||||
child_items.append(i)
|
child_items.append(i)
|
||||||
return child_items
|
return child_items
|
||||||
|
|||||||
Reference in New Issue
Block a user