From a0d1b6f80a95c9172444c0ded4ecdc15d0bf0d4a Mon Sep 17 00:00:00 2001 From: Langenfeld Date: Tue, 9 Nov 2021 14:33:23 +0100 Subject: [PATCH] add apiendpoint to request file listing from repositories --- gitea/gitea.py | 12 ++++++++++++ gitea/giteaApiObject.py | 2 +- tests/test_api.py | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gitea/gitea.py b/gitea/gitea.py index bcabb99..3b2bc77 100644 --- a/gitea/gitea.py +++ b/gitea/gitea.py @@ -237,6 +237,7 @@ class Repository(GiteaApiObject): REPO_USER_TIME = """/repos/%s/%s/times/%s""" # , , REPO_COMMITS = "/repos/%s/%s/commits" # , REPO_TRANSFER = "/repos/{owner}/{repo}/transfer" + REPO_CONTENTS = "/repos/{owner}/{repo}/contents" def __init__(self, gitea, id: int): super(Repository, self).__init__(gitea, id=id) @@ -410,6 +411,17 @@ class Repository(GiteaApiObject): self.gitea.requests_post(url, data=data) # TODO: make sure this instance is either updated or discarded + def get_git_content(self, ref : str = "HEAD"): + """https://git.sopranium.de/api/swagger#/repository/repoGetContentsList""" + url = Repository.REPO_CONTENTS.format(owner=self.owner.username, repo=self.name) + data = {"ref": ref} + result = self.gitea.requests_get(url) + return result + + def get_file_content(self): + """https://git.sopranium.de/api/swagger#/repository/repoGetContents""" + pass + def delete(self): self.gitea.requests_delete( Repository.REPO_DELETE % (self.owner.username, self.name) diff --git a/gitea/giteaApiObject.py b/gitea/giteaApiObject.py index b7ea64f..63255bf 100644 --- a/gitea/giteaApiObject.py +++ b/gitea/giteaApiObject.py @@ -10,7 +10,7 @@ class GiteaApiObject(BasicGiteaApiObject): @classmethod def request(cls, gitea, id): - """Use for ginving a nice e.g. 'request(gita, orgname, repo, ticket)'. + """Use for giving a nice e.g. 'request(gita, orgname, repo, ticket)'. All args are put into an args tuple for passing around""" return cls._request(gitea, {"id": id}) diff --git a/tests/test_api.py b/tests/test_api.py index eda2449..b9c287d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -133,6 +133,12 @@ def test_list_branches(instance): master = [b for b in branches if b.name == "master"] assert len(master) > 0 +def test_list_files(instance): + org = Organization.request(instance, test_org) + repo = org.get_repository(test_repo) + content = repo.get_git_content() + assert True + def test_create_branch(instance): org = Organization.request(instance, test_org) repo = org.get_repository(test_repo)