kopia lustrzana https://github.com/Langenfeld/py-gitea
(feat) adding file to repo by api (closes #16)
rodzic
0a620188ff
commit
e321c0bddd
|
@ -535,18 +535,20 @@ class Repository(ApiObject):
|
|||
else:
|
||||
return [Content.parse_response(self.gitea, f) for f in self.gitea.requests_get(url, data)]
|
||||
|
||||
def create_file(self, file_path: str, data: "data" = dict):
|
||||
def create_file(self, file_path: str, content: str, data: dict = None):
|
||||
"""https://try.gitea.io/api/swagger#/repository/repoCreateFile"""
|
||||
if not data:
|
||||
data = {}
|
||||
url = f"/repos/{self.owner.username}/{self.name}/contents/{file_path}"
|
||||
if "content" not in data:
|
||||
raise Exception("No Data to upload is supplied. Please give 'content' Field with data")
|
||||
data.update({"content": content})
|
||||
return self.gitea.requests_post(url, data)
|
||||
|
||||
def change_file(self, file_path: str, data: "data" = dict):
|
||||
def change_file(self, file_path: str, file_sha: str, content: str, data: dict = None):
|
||||
"""https://try.gitea.io/api/swagger#/repository/repoCreateFile"""
|
||||
if not data:
|
||||
data = {}
|
||||
url = f"/repos/{self.owner.username}/{self.name}/contents/{file_path}"
|
||||
if "content" not in data:
|
||||
raise Exception("No Data to upload is supplied. Please give 'content' Field with data")
|
||||
data.update({"sha": file_sha, "data": content})
|
||||
return self.gitea.requests_put(url, data)
|
||||
|
||||
def delete(self):
|
||||
|
|
|
@ -153,7 +153,7 @@ def test_create_file(instance):
|
|||
org = Organization.request(instance, test_org)
|
||||
repo = org.get_repository(test_repo)
|
||||
repo.create_file("testfile.md",
|
||||
{"content": TESTFILE_CONENTE_B64.decode("ascii")})
|
||||
content = TESTFILE_CONENTE_B64.decode("ascii"))
|
||||
# test if putting was successful
|
||||
content = repo.get_git_content()
|
||||
readmes = [c for c in content if c.name == "testfile.md"]
|
||||
|
@ -171,8 +171,8 @@ def test_change_file(instance):
|
|||
content = repo.get_git_content()
|
||||
readmes = [c for c in content if c.name == "testfile.md"]
|
||||
# change
|
||||
repo.change_file("testfile.md",
|
||||
{"content": TESTFILE_CONENTE_B64.decode("ascii"), "sha": readmes[0].sha})
|
||||
repo.change_file("testfile.md", readmes[0].sha,
|
||||
content = TESTFILE_CONENTE_B64.decode("ascii"))
|
||||
# test if putting was successful
|
||||
content = repo.get_git_content()
|
||||
readmes = [c for c in content if c.name == "testfile.md"]
|
||||
|
|
Ładowanie…
Reference in New Issue