Skip to content

Commit

Permalink
Delete branch protections
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartatz committed Aug 27, 2024
1 parent 5c26e03 commit 7bc0738
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -74,6 +101,7 @@ async def mirror(client):
)

repo = Repository(
id = None,
name = name,
description = description
)
Expand All @@ -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:
Expand Down Expand Up @@ -153,6 +188,7 @@ async def mirror(client):
"git",
"-C", directory,
"push",
"--force",
"--quiet",
"--mirror",
url
Expand All @@ -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())

0 comments on commit 7bc0738

Please sign in to comment.