First stab at implementing token.activate.
This commit is contained in:
parent
d5304f7db0
commit
a6400171b3
3 changed files with 28 additions and 7 deletions
|
@ -1387,7 +1387,13 @@ def activate_build_trigger(namespace, repository, trigger_uuid):
|
||||||
new_config_dict = request.get_json()
|
new_config_dict = request.get_json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handler.activate(trigger.auth_token, new_config_dict)
|
repository = '%s/%s' % (trigger.repository.namespace,
|
||||||
|
trigger.repository.name)
|
||||||
|
webhook_url = url_for('webhooks.build_trigger_webhook',
|
||||||
|
repository=repository, trigger_uuid=trigger.uuid,
|
||||||
|
_external=True)
|
||||||
|
handler.activate(trigger.uuid, webhook_url, trigger.auth_token,
|
||||||
|
new_config_dict)
|
||||||
except TriggerActivationException as e:
|
except TriggerActivationException as e:
|
||||||
abort(400, message = e.msg)
|
abort(400, message = e.msg)
|
||||||
return
|
return
|
||||||
|
|
|
@ -47,11 +47,12 @@ class BuildTrigger(object):
|
||||||
|
|
||||||
def is_active(self, config):
|
def is_active(self, config):
|
||||||
"""
|
"""
|
||||||
Returns True if the current build trigger is active. Inactive means further setup is needed.
|
Returns True if the current build trigger is active. Inactive means further
|
||||||
|
setup is needed.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def activate(self, auth_token, config):
|
def activate(self, trigger_uuid, standard_webhook_url, auth_token, config):
|
||||||
"""
|
"""
|
||||||
Activates the trigger for the service, with the given new configuration.
|
Activates the trigger for the service, with the given new configuration.
|
||||||
"""
|
"""
|
||||||
|
@ -90,8 +91,22 @@ class GithubBuildTrigger(BuildTrigger):
|
||||||
def is_active(self, config):
|
def is_active(self, config):
|
||||||
return 'build_source' in config and len(config['build_source']) > 0
|
return 'build_source' in config and len(config['build_source']) > 0
|
||||||
|
|
||||||
def activate(self, auth_token, config):
|
def activate(self, trigger_uuid, standard_webhook_url, auth_token, config):
|
||||||
# TODO: Add the callback web hook to the github repository.
|
new_build_source = config['build_source']
|
||||||
|
gh_client = self._get_client(auth_token)
|
||||||
|
|
||||||
|
try:
|
||||||
|
to_add_webhook = gh_client.get_repo(new_build_source)
|
||||||
|
|
||||||
|
webhook_config = {
|
||||||
|
'url': standard_webhook_url,
|
||||||
|
'content_type': 'json',
|
||||||
|
}
|
||||||
|
|
||||||
|
to_add_webhook.create_hook('web', webhook_config)
|
||||||
|
|
||||||
|
|
||||||
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def list_build_sources(self, auth_token):
|
def list_build_sources(self, auth_token):
|
||||||
|
|
|
@ -48,7 +48,7 @@ def stripe_webhook():
|
||||||
methods=['POST'])
|
methods=['POST'])
|
||||||
@process_auth
|
@process_auth
|
||||||
@parse_repository_name
|
@parse_repository_name
|
||||||
def github_push_webhook(namespace, repository, trigger_uuid):
|
def build_trigger_webhook(namespace, repository, trigger_uuid):
|
||||||
logger.debug('Webhook received for %s/%s with uuid %s', namespace,
|
logger.debug('Webhook received for %s/%s with uuid %s', namespace,
|
||||||
repository, trigger_uuid)
|
repository, trigger_uuid)
|
||||||
permission = ModifyRepositoryPermission(namespace, repository)
|
permission = ModifyRepositoryPermission(namespace, repository)
|
||||||
|
|
Reference in a new issue