endpoints.trigger: address gitlab PR comments
This commit is contained in:
parent
eb3d88bd92
commit
d21fbb1204
1 changed files with 35 additions and 12 deletions
|
@ -1120,11 +1120,12 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
'value': public_key,
|
||||
},
|
||||
]
|
||||
success = gl_client.adddeploykey(repository['id'], '%s Builder' % app.config['REGISTRY_TITLE'],
|
||||
public_key)
|
||||
if success is False:
|
||||
key = gl_client.adddeploykey(repository['id'], '%s Builder' % app.config['REGISTRY_TITLE'],
|
||||
public_key)
|
||||
if key is False:
|
||||
msg = 'Unable to add deploy key to repository: %s' % new_build_source
|
||||
raise TriggerActivationException(msg)
|
||||
config['key_id'] = key['id']
|
||||
|
||||
# Add the webhook to the GitLab repository.
|
||||
hook = gl_client.addprojecthook(repository['id'], standard_webhook_url, push=True)
|
||||
|
@ -1151,8 +1152,15 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
if success is False:
|
||||
msg = 'Unable to remove hook: %s' % config['hook_id']
|
||||
raise TriggerDeactivationException(msg)
|
||||
|
||||
config.pop('hook_id', None)
|
||||
|
||||
# Remove the key
|
||||
success = gl_client.deletedeploykey(repository['id'], config['key_id'])
|
||||
if success is False:
|
||||
msg = 'Unable to remove deploy key: %s' % config['key_id']
|
||||
raise TriggerDeactivationException(msg)
|
||||
config.pop('key_id', None)
|
||||
|
||||
self.config = config
|
||||
|
||||
return config
|
||||
|
@ -1219,11 +1227,18 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
repository = gl_client.getproject(self.config['build_source'])
|
||||
if repository is False:
|
||||
return None
|
||||
branch = repository['default_branch']
|
||||
|
||||
branches = self.list_field_values('branch_name')
|
||||
branches = find_matching_branches(self.config, branches)
|
||||
if branches == []:
|
||||
return None
|
||||
branch_name = branches[0]
|
||||
if repository['default_branch'] in branches:
|
||||
branch_name = repository['default_branch']
|
||||
|
||||
return '%s/%s/blob/%s/%s' % (gl_client.host,
|
||||
repository['path_with_namespace'],
|
||||
branch,
|
||||
branch_name,
|
||||
path)
|
||||
|
||||
def load_dockerfile_contents(self):
|
||||
|
@ -1235,7 +1250,15 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
if repository is False:
|
||||
return None
|
||||
|
||||
contents = gl_client.getrawfile(repository['id'], repository['default_branch'], path)
|
||||
branches = self.list_field_values('branch_name')
|
||||
branches = find_matching_branches(self.config, branches)
|
||||
if branches == []:
|
||||
return None
|
||||
branch_name = branches[0]
|
||||
if repository['default_branch'] in branches:
|
||||
branch_name = repository['default_branch']
|
||||
|
||||
contents = gl_client.getrawfile(repository['id'], branch_name, path)
|
||||
if contents is False:
|
||||
return None
|
||||
return contents
|
||||
|
@ -1257,13 +1280,13 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
tags = gl_client.getall(gl_client.getrepositorytags(repo['id']))
|
||||
if tags is False:
|
||||
return []
|
||||
return [tag.name for tag in tags]
|
||||
return [tag['name'] for tag in tags]
|
||||
|
||||
if field_name == 'branch_name':
|
||||
branches = gl_client.getbranches(repo['id'])
|
||||
if branches is False:
|
||||
return []
|
||||
return [branch.name for branch in branches]
|
||||
return [branch['name'] for branch in branches]
|
||||
|
||||
return None
|
||||
|
||||
|
@ -1291,7 +1314,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
'default_branch': repo['default_branch'],
|
||||
'git_url': repo['ssh_url_to_repo'],
|
||||
'commit_info': {
|
||||
'url': '',
|
||||
'url': gl_client.host + '/' + repo['path_with_namespace'] + '/commit/' + commit['id'],
|
||||
'message': commit['message'],
|
||||
'date': commit['committed_date'],
|
||||
},
|
||||
|
@ -1327,7 +1350,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
|
||||
logger.debug('GitLab trigger payload %s', payload)
|
||||
|
||||
if not payload.gets('commits'):
|
||||
if not payload.get('commits'):
|
||||
raise SkipRequestException()
|
||||
|
||||
commit = payload['commits'][0]
|
||||
|
@ -1356,7 +1379,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
|
||||
commit = None
|
||||
for branch in branches:
|
||||
if branch['name'] is branch_name:
|
||||
if branch['name'] == branch_name:
|
||||
commit = branch['commit']
|
||||
if commit is None:
|
||||
raise TriggerStartException('Could not find commit')
|
||||
|
|
Reference in a new issue