kopia lustrzana https://github.com/Langenfeld/py-gitea
cont.
rodzic
a383f655da
commit
690816f3d5
|
@ -443,23 +443,22 @@ class Repository(GiteaApiObject):
|
||||||
self.gitea.requests_post(url, data=data)
|
self.gitea.requests_post(url, data=data)
|
||||||
# TODO: make sure this instance is either updated or discarded
|
# TODO: make sure this instance is either updated or discarded
|
||||||
|
|
||||||
def get_git_content(self, file_path: str = None, commit : "Commit" = None) -> List["Content"]:
|
def get_git_content(self: str = None, commit : "Commit" = None) -> List["Content"]:
|
||||||
"""https://git.sopranium.de/api/swagger#/repository/repoGetContentsList"""
|
"""https://git.sopranium.de/api/swagger#/repository/repoGetContentsList"""
|
||||||
url = Repository.REPO_CONTENTS.format(owner=self.owner.username, repo=self.name)
|
url = Repository.REPO_CONTENTS.format(owner=self.owner.username, repo=self.name)
|
||||||
data = {"ref": "HEAD" if commit is None else commit.sha}
|
data = {"ref": "HEAD" if commit is None else commit.sha}
|
||||||
if file_path: data["filepath"] = file_path
|
|
||||||
result = [Content.parse_response(self.gitea, f) for f in self.gitea.requests_get(url, data)]
|
result = [Content.parse_response(self.gitea, f) for f in self.gitea.requests_get(url, data)]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_file_content(self, content: "Content", commit : "Commit" = None) -> Union[str, List["Content"]]:
|
def get_file_content(self, content: "Content", commit : "Commit" = None) -> Union[str, List["Content"]]:
|
||||||
"""https://git.sopranium.de/api/swagger#/repository/repoGetContents"""
|
"""https://git.sopranium.de/api/swagger#/repository/repoGetContents"""
|
||||||
|
url = Repository.REPO_CONTENT.format(owner=self.owner.username,
|
||||||
|
repo=self.name, filepath=content.path)
|
||||||
|
data = {"ref": "HEAD" if commit is None else commit.sha}
|
||||||
if content.type == Content.FILE:
|
if content.type == Content.FILE:
|
||||||
url = Repository.REPO_CONTENT.format(owner=self.owner.username,
|
|
||||||
repo=self.name, filepath=content.path)
|
|
||||||
data = {"ref": "HEAD" if commit is None else commit.sha}
|
|
||||||
return self.gitea.requests_get(url, data)["content"]
|
return self.gitea.requests_get(url, data)["content"]
|
||||||
else:
|
else:
|
||||||
return self.get_git_content(content.path, commit)
|
return [Content.parse_response(self.gitea, f) for f in self.gitea.requests_get(url, data)]
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
self.gitea.requests_delete(
|
self.gitea.requests_delete(
|
||||||
|
|
|
@ -142,6 +142,20 @@ def test_list_files_and_content(instance):
|
||||||
readme_content = repo.get_file_content(readmes[0])
|
readme_content = repo.get_file_content(readmes[0])
|
||||||
assert len(readme_content) > 0
|
assert len(readme_content) > 0
|
||||||
|
|
||||||
|
# TODO: make this testable
|
||||||
|
"""
|
||||||
|
def test_list_files_and_content_testorg(instance):
|
||||||
|
org = Organization.request(instance, "testtest")
|
||||||
|
repo = org.get_repository("test")
|
||||||
|
content = repo.get_git_content()
|
||||||
|
readmes = [c for c in content if c.name == "filefolder"]
|
||||||
|
assert len(readmes) > 0
|
||||||
|
readme_content = repo.get_file_content(readmes[0])
|
||||||
|
assert len(readme_content) > 0
|
||||||
|
lower_readme = [c for c in readme_content if c.name == "testfile.md"]
|
||||||
|
lower_r_content = repo.get_file_content(lower_readme[0])
|
||||||
|
assert len(lower_r_content) > 0
|
||||||
|
"""
|
||||||
|
|
||||||
def test_create_branch(instance):
|
def test_create_branch(instance):
|
||||||
org = Organization.request(instance, test_org)
|
org = Organization.request(instance, test_org)
|
||||||
|
|
Ładowanie…
Reference in New Issue