diff --git a/main.py b/main.py index e080273..58aac19 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,8 @@ class Repository: - def __init__(self, name, description): + def __init__(self, id, name, description): + self.id = id self.name = name self.description = description @@ -38,6 +39,32 @@ async def gitlab_create_repository(client, name, description = None): return response.status_code == 200 +async def gitlab_unprotect_branches(client, repository): + + gitlab_token = os.getenv(key = "GL_TOKEN") + + response = await client.get( + url = "https://gitlab.com/api/v4/projects/%i/protected_branches" % (repository), + headers = { + "Authorization": "Bearer %s" % gitlab_token + } + ) + data = response.json() + + for branch in data: + name = branch["name"] + + print("- Deleting branch protections for branch '%s'" % (name)) + + response = await client.delete( + url = "https://gitlab.com/api/v4/projects/%i/protected_branches/%s" % (repository, name), + headers = { + "Authorization": "Bearer %s" % gitlab_token + } + ) + + return response.status_code == 200 + async def mirror(client): github_token = os.getenv(key = "GH_TOKEN") @@ -74,6 +101,7 @@ async def mirror(client): ) repo = Repository( + id = None, name = name, description = description ) @@ -93,15 +121,22 @@ async def mirror(client): data = response.json() for repository in data: - (name) = ( + (id, name) = ( + repository["id"], repository["name"] ) repo = Repository( + id = id, name = name, description = None ) + await gitlab_unprotect_branches( + client = client, + repository = repo.id + ) + gitlab_repositories.append(repo) for repository in github_repositories: @@ -153,6 +188,7 @@ async def mirror(client): "git", "-C", directory, "push", + "--force", "--quiet", "--mirror", url @@ -163,7 +199,7 @@ async def mirror(client): async def main(): - async with httpx.AsyncClient(http2 = True) as client: + async with httpx.AsyncClient(http2 = True, verify = False) as client: await mirror(client = client) asyncio.run(main())