First stab at implementing token.activate.

This commit is contained in:
jakedt 2014-02-21 16:02:31 -05:00
parent d5304f7db0
commit a6400171b3
3 changed files with 28 additions and 7 deletions

View file

@ -1387,7 +1387,13 @@ def activate_build_trigger(namespace, repository, trigger_uuid):
new_config_dict = request.get_json()
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:
abort(400, message = e.msg)
return

View file

@ -47,11 +47,12 @@ class BuildTrigger(object):
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
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.
"""
@ -90,9 +91,23 @@ class GithubBuildTrigger(BuildTrigger):
def is_active(self, config):
return 'build_source' in config and len(config['build_source']) > 0
def activate(self, auth_token, config):
# TODO: Add the callback web hook to the github repository.
pass
def activate(self, trigger_uuid, standard_webhook_url, auth_token, config):
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
def list_build_sources(self, auth_token):
gh_client = self._get_client(auth_token)

View file

@ -48,7 +48,7 @@ def stripe_webhook():
methods=['POST'])
@process_auth
@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,
repository, trigger_uuid)
permission = ModifyRepositoryPermission(namespace, repository)