Disabling pushing to c9s branch in the fork

Signed-off-by: Mohan Boddu <mboddu@bhujji.com>
This commit is contained in:
Mohan Boddu 2021-05-11 15:42:04 -04:00
parent 329e001c49
commit 464a71d87f

View file

@ -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