Added a method to get the content of files.
Some checks failed
/ unit-tests (push) Failing after 10s

This commit is contained in:
2025-11-08 14:56:10 +01:00
parent 27a5a13c47
commit 9b2922c1ef

View File

@@ -247,6 +247,20 @@ class Item():
) )
self.from_json(r.json()) # type: ignore[attr-defined] self.from_json(r.json()) # type: ignore[attr-defined]
def get_content(self) -> bytes:
"""Get the content of the item if it is a file."""
if self.git_object_type != "blob": # type: ignore[attr-defined]
raise ValueError("Content can only be fetched for blob items.")
r = self._repository._project.organization.get_path(
path=f"{self._repository._project.id}/_apis/git/repositories/{self._repository.id}/items",
params={
"path": self.path,
"recursionLevel": "none"
}
)
return r.content
@property @property
def path(self): def path(self):
return self._path # type: ignore[attr-defined] return self._path # type: ignore[attr-defined]