From 464a71d87f746e0212723b8cb721596a1a264951 Mon Sep 17 00:00:00 2001 From: Mohan Boddu Date: May 11 2021 19:42:04 +0000 Subject: Disabling pushing to c9s branch in the fork Signed-off-by: Mohan Boddu --- diff --git a/src/centpkg/utils.py b/src/centpkg/utils.py index cf98c1c..6d27b0e 100644 --- a/src/centpkg/utils.py +++ b/src/centpkg/utils.py @@ -63,6 +63,32 @@ def do_fork(logger, base_url, token, repo_name, namespace, cli_name): except Exception: pass + if rv.ok: + fork_id = rv.json()['id'] + try: + # Unprotect c9s in fork + rv = requests.delete('{0}/projects/{1}/protected_branches/{2}'.format(api_url, fork_id, 'c9s'), headers=header) + except ConnectionError as error: + error_msg = ('The connection to API failed while trying to unprotect c9s branch' + 'in the fork. The error was: {0}'.format(str(error))) + raise rpkgError(error_msg) + + + try: + # Reprotect c9s to disable pushes + # Only maintainers in gitlab are allowed to push with the following config + # In CS, every pkg maintainer is considered as a developer in gitlab + data = {'id': fork_id, + 'name': 'c9s', + 'allowed_to_push': [{'access_level': 40}], + 'allowed_to_merge': [{'access_level': 40}], + } + rv = requests.post('{0}/projects/{1}/protected_branches'.format(api_url, fork_id), json=data, headers=header) + except ConnectionError as error: + error_msg = ('The connection to API failed while trying to reprotect c9s branch' + 'in the fork fork. The error was: {0}'.format(str(error))) + raise rpkgError(error_msg) + base_error_msg = ('The following error occurred while creating a new fork: {0}') if not rv.ok: # fork was already created