kopia lustrzana https://github.com/Langenfeld/py-gitea
(fix) migrate function returns repository object with valid gitea, #22
rodzic
853b5b811b
commit
ba4202fe6f
|
@ -565,7 +565,7 @@ class Repository(ApiObject):
|
||||||
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: str = None, commit: "Commit" = None) -> List["Content"]:
|
def get_git_content(self, commit: "Commit" = None) -> List["Content"]:
|
||||||
"""https://try.gitea.io/api/swagger#/repository/repoGetContentsList"""
|
"""https://try.gitea.io/api/swagger#/repository/repoGetContentsList"""
|
||||||
url = f"/repos/{self.owner.username}/{self.name}/contents"
|
url = f"/repos/{self.owner.username}/{self.name}/contents"
|
||||||
data = {"ref": commit.sha} if commit else {}
|
data = {"ref": commit.sha} if commit else {}
|
||||||
|
@ -613,8 +613,10 @@ class Repository(ApiObject):
|
||||||
)
|
)
|
||||||
self.deleted = True
|
self.deleted = True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def migrate_repo(
|
def migrate_repo(
|
||||||
self,
|
cls,
|
||||||
|
gitea: "Gitea",
|
||||||
service: str,
|
service: str,
|
||||||
clone_addr: str,
|
clone_addr: str,
|
||||||
repo_name: str,
|
repo_name: str,
|
||||||
|
@ -641,8 +643,8 @@ class Repository(ApiObject):
|
||||||
AlreadyExistsException: If the Repository exists already.
|
AlreadyExistsException: If the Repository exists already.
|
||||||
Exception: If something else went wrong.
|
Exception: If something else went wrong.
|
||||||
"""
|
"""
|
||||||
result = self.gitea.requests_post(
|
result = gitea.requests_post(
|
||||||
self.REPO_MIGRATE,
|
cls.REPO_MIGRATE,
|
||||||
data={
|
data={
|
||||||
"auth_password": auth_password,
|
"auth_password": auth_password,
|
||||||
"auth_token": auth_token,
|
"auth_token": auth_token,
|
||||||
|
@ -666,15 +668,15 @@ class Repository(ApiObject):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if "id" in result:
|
if "id" in result:
|
||||||
self.gitea.logger.info(
|
gitea.logger.info(
|
||||||
"Successfully created Job to Migrate Repository %s " % result["name"]
|
"Successfully created Job to Migrate Repository %s " % result["name"]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.gitea.logger.error(result["message"])
|
gitea.logger.error(result["message"])
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Repository not Migrated... (gitea: %s)" % result["message"]
|
"Repository not Migrated... (gitea: %s)" % result["message"]
|
||||||
)
|
)
|
||||||
return Repository.parse_response(self, result)
|
return Repository.parse_response(gitea, result)
|
||||||
|
|
||||||
|
|
||||||
class Milestone(ApiObject):
|
class Milestone(ApiObject):
|
||||||
|
|
|
@ -433,9 +433,9 @@ def test_delete_user(instance):
|
||||||
User.request(instance, user_name)
|
User.request(instance, user_name)
|
||||||
|
|
||||||
|
|
||||||
def test_migrate_repo(instance):
|
def test_migrate_repo_gitea(instance):
|
||||||
service = Repository(instance)
|
repo = Repository.migrate_repo(
|
||||||
repo = service.migrate_repo(
|
instance,
|
||||||
MigrationServices.GITEA,
|
MigrationServices.GITEA,
|
||||||
"https://gitea.com/gitea/awesome-gitea.git",
|
"https://gitea.com/gitea/awesome-gitea.git",
|
||||||
test_repo,
|
test_repo,
|
||||||
|
@ -445,5 +445,23 @@ def test_migrate_repo(instance):
|
||||||
assert repo.description == "user owned repo"
|
assert repo.description == "user owned repo"
|
||||||
assert not repo.private
|
assert not repo.private
|
||||||
assert repo.owner.username == "test"
|
assert repo.owner.username == "test"
|
||||||
|
assert "README.md" in [f.name for f in repo.get_git_content()]
|
||||||
|
repo = Repository.request(instance, "test", test_repo)
|
||||||
|
repo.delete()
|
||||||
|
|
||||||
|
|
||||||
|
def test_migrate_repo_github(instance):
|
||||||
|
repo = Repository.migrate_repo(
|
||||||
|
instance,
|
||||||
|
MigrationServices.GITHUB,
|
||||||
|
"https://github.com/Langenfeld/py-gitea",
|
||||||
|
test_repo,
|
||||||
|
"cloning py-gitea to test py-gitea",
|
||||||
|
)
|
||||||
|
assert repo.name == test_repo
|
||||||
|
assert repo.description == "cloning py-gitea to test py-gitea"
|
||||||
|
assert not repo.private
|
||||||
|
assert repo.owner.username == "test"
|
||||||
|
assert "README.md" in [f.name for f in repo.get_git_content()]
|
||||||
repo = Repository.request(instance, "test", test_repo)
|
repo = Repository.request(instance, "test", test_repo)
|
||||||
repo.delete()
|
repo.delete()
|
||||||
|
|
Ładowanie…
Reference in New Issue