parent
2f42a4d94d
commit
d9e001b688
2 changed files with 23 additions and 9 deletions
|
@ -159,6 +159,13 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
||||||
source = self.config['build_source']
|
source = self.config['build_source']
|
||||||
return github_trigger.get_public_url(source)
|
return github_trigger.get_public_url(source)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_error_message(ghe, default_msg):
|
||||||
|
if ghe.data.get('errors') and ghe.data['errors'][0].get('message'):
|
||||||
|
return ghe.data['errors'][0]['message']
|
||||||
|
|
||||||
|
return default_msg
|
||||||
|
|
||||||
def activate(self, standard_webhook_url):
|
def activate(self, standard_webhook_url):
|
||||||
config = self.config
|
config = self.config
|
||||||
new_build_source = config['build_source']
|
new_build_source = config['build_source']
|
||||||
|
@ -179,12 +186,14 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
||||||
'value': public_key,
|
'value': public_key,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
deploy_key = gh_repo.create_key('%s Builder' % app.config['REGISTRY_TITLE'],
|
deploy_key = gh_repo.create_key('%s Builder' % app.config['REGISTRY_TITLE'],
|
||||||
public_key)
|
public_key)
|
||||||
config['deploy_key_id'] = deploy_key.id
|
config['deploy_key_id'] = deploy_key.id
|
||||||
except GithubException:
|
except GithubException as ghe:
|
||||||
msg = 'Unable to add deploy key to repository: %s' % new_build_source
|
default_msg = 'Unable to add deploy key to repository: %s' % new_build_source
|
||||||
|
msg = GithubBuildTrigger._get_error_message(ghe, default_msg)
|
||||||
raise TriggerActivationException(msg)
|
raise TriggerActivationException(msg)
|
||||||
|
|
||||||
# Add the webhook to the GitHub repository.
|
# Add the webhook to the GitHub repository.
|
||||||
|
@ -192,12 +201,14 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
||||||
'url': standard_webhook_url,
|
'url': standard_webhook_url,
|
||||||
'content_type': 'json',
|
'content_type': 'json',
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hook = gh_repo.create_hook('web', webhook_config)
|
hook = gh_repo.create_hook('web', webhook_config)
|
||||||
config['hook_id'] = hook.id
|
config['hook_id'] = hook.id
|
||||||
config['master_branch'] = gh_repo.default_branch
|
config['master_branch'] = gh_repo.default_branch
|
||||||
except GithubException:
|
except GithubException:
|
||||||
msg = 'Unable to create webhook on repository: %s' % new_build_source
|
default_msg = 'Unable to create webhook on repository: %s' % new_build_source
|
||||||
|
msg = GithubBuildTrigger._get_error_message(ghe, default_msg)
|
||||||
raise TriggerActivationException(msg)
|
raise TriggerActivationException(msg)
|
||||||
|
|
||||||
return config, {'private_key': private_key}
|
return config, {'private_key': private_key}
|
||||||
|
@ -224,16 +235,18 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# There was no config['deploy_key_id'], thus this is an old trigger without a deploy key.
|
# There was no config['deploy_key_id'], thus this is an old trigger without a deploy key.
|
||||||
pass
|
pass
|
||||||
except GithubException:
|
except GithubException as ghe:
|
||||||
msg = 'Unable to remove deploy key: %s' % config['deploy_key_id']
|
default_msg = 'Unable to remove deploy key: %s' % config['deploy_key_id']
|
||||||
|
msg = GithubBuildTrigger._get_error_message(ghe, default_msg)
|
||||||
raise TriggerDeactivationException(msg)
|
raise TriggerDeactivationException(msg)
|
||||||
|
|
||||||
# Remove the webhook.
|
# Remove the webhook.
|
||||||
try:
|
try:
|
||||||
hook = repo.get_hook(config['hook_id'])
|
hook = repo.get_hook(config['hook_id'])
|
||||||
hook.delete()
|
hook.delete()
|
||||||
except GithubException:
|
except GithubException as ghe:
|
||||||
msg = 'Unable to remove hook: %s' % config['hook_id']
|
default_msg = 'Unable to remove hook: %s' % config['hook_id']
|
||||||
|
msg = GithubBuildTrigger._get_error_message(ghe, default_msg)
|
||||||
raise TriggerDeactivationException(msg)
|
raise TriggerDeactivationException(msg)
|
||||||
|
|
||||||
config.pop('hook_id', None)
|
config.pop('hook_id', None)
|
||||||
|
@ -435,7 +448,8 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
||||||
repo = gh_client.get_repo(source)
|
repo = gh_client.get_repo(source)
|
||||||
default_branch = repo.default_branch
|
default_branch = repo.default_branch
|
||||||
except GithubException as ghe:
|
except GithubException as ghe:
|
||||||
raise TriggerStartException(ghe.data['message'])
|
msg = GithubBuildTrigger._get_error_message(ghe, 'Unable to start build trigger')
|
||||||
|
raise TriggerStartException(msg)
|
||||||
|
|
||||||
def get_branch_sha(branch_name):
|
def get_branch_sha(branch_name):
|
||||||
branch = repo.get_branch(branch_name)
|
branch = repo.get_branch(branch_name)
|
||||||
|
|
|
@ -119,7 +119,7 @@ angular.module('quay').directive('setupTriggerDialog', function () {
|
||||||
$scope.canceled({'trigger': $scope.trigger});
|
$scope.canceled({'trigger': $scope.trigger});
|
||||||
|
|
||||||
return ApiService.getErrorMessage(resp) +
|
return ApiService.getErrorMessage(resp) +
|
||||||
'\n\nThis usually means that you do not have admin access on the repository.';
|
'\n\nNote: Errors can occur if you do not have admin access on the repository.';
|
||||||
});
|
});
|
||||||
|
|
||||||
ApiService.activateBuildTrigger(data, params).then(function(resp) {
|
ApiService.activateBuildTrigger(data, params).then(function(resp) {
|
||||||
|
|
Reference in a new issue