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)
|
||||
# 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"""
|
||||
url = f"/repos/{self.owner.username}/{self.name}/contents"
|
||||
data = {"ref": commit.sha} if commit else {}
|
||||
|
@ -613,8 +613,10 @@ class Repository(ApiObject):
|
|||
)
|
||||
self.deleted = True
|
||||
|
||||
@classmethod
|
||||
def migrate_repo(
|
||||
self,
|
||||
cls,
|
||||
gitea: "Gitea",
|
||||
service: str,
|
||||
clone_addr: str,
|
||||
repo_name: str,
|
||||
|
@ -641,8 +643,8 @@ class Repository(ApiObject):
|
|||
AlreadyExistsException: If the Repository exists already.
|
||||
Exception: If something else went wrong.
|
||||
"""
|
||||
result = self.gitea.requests_post(
|
||||
self.REPO_MIGRATE,
|
||||
result = gitea.requests_post(
|
||||
cls.REPO_MIGRATE,
|
||||
data={
|
||||
"auth_password": auth_password,
|
||||
"auth_token": auth_token,
|
||||
|
@ -666,15 +668,15 @@ class Repository(ApiObject):
|
|||
},
|
||||
)
|
||||
if "id" in result:
|
||||
self.gitea.logger.info(
|
||||
gitea.logger.info(
|
||||
"Successfully created Job to Migrate Repository %s " % result["name"]
|
||||
)
|
||||
else:
|
||||
self.gitea.logger.error(result["message"])
|
||||
gitea.logger.error(result["message"])
|
||||
raise Exception(
|
||||
"Repository not Migrated... (gitea: %s)" % result["message"]
|
||||
)
|
||||
return Repository.parse_response(self, result)
|
||||
return Repository.parse_response(gitea, result)
|
||||
|
||||
|
||||
class Milestone(ApiObject):
|
||||
|
|
|
@ -433,9 +433,9 @@ def test_delete_user(instance):
|
|||
User.request(instance, user_name)
|
||||
|
||||
|
||||
def test_migrate_repo(instance):
|
||||
service = Repository(instance)
|
||||
repo = service.migrate_repo(
|
||||
def test_migrate_repo_gitea(instance):
|
||||
repo = Repository.migrate_repo(
|
||||
instance,
|
||||
MigrationServices.GITEA,
|
||||
"https://gitea.com/gitea/awesome-gitea.git",
|
||||
test_repo,
|
||||
|
@ -445,5 +445,23 @@ def test_migrate_repo(instance):
|
|||
assert repo.description == "user owned repo"
|
||||
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.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.delete()
|
||||
|
|
Ładowanie…
Reference in New Issue