Commit 07f32b03 authored by Evangelos Ribeiro Tzaras's avatar Evangelos Ribeiro Tzaras
Browse files

setup-pureos-pkg-repo: Don't use obsolete API for protecting branches

The correct way (nowadays) to protect a branch is by using the
protected_branches endpoint
(see https://docs.gitlab.com/ee/api/protected_branches.html)

Fixes #4
parent 6df534d1
Pipeline #76364 passed with stages
in 3 minutes and 30 seconds
......@@ -71,6 +71,22 @@ def get_branch(project, branch):
return branch
def protect_branch(project, branch):
if branch.protected:
return
name = branch.name
try:
data = {
"name": name,
}
project.protectedbranches.create(data)
print(f"Protected branch {name}")
except Exception as e:
print(f"Unexpected exception: {e}")
sys.exit(1)
def msg_auth_fail(exit_code):
print(f"\nAuthentication Error: Looks like you don't have sufficient access rights to modify/check resources on '{URL}'!\n"
"You have a role of 'Maintainer' or 'Owner' on this GitLab instance?\n"
......@@ -135,14 +151,14 @@ def main(argv):
def_branch = get_branch(project, default_branch)
if def_branch:
def_branch.protect()
protect_branch(project, def_branch)
else:
ret = 1
print(f"Branch '{default_branch}' not found")
branch = get_branch(project, PRISTINE_TAR_BRANCH)
if branch:
branch.protect()
protect_branch(project, branch)
else:
ret = 1
print(f"Branch '{PRISTINE_TAR_BRANCH}' not found")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment