Allow GitHub triggers to be removed if OAuth token is invalid

This commit is contained in:
Joseph Schorr 2015-06-17 13:25:01 -04:00
parent 7315736c1f
commit fe70139daa

View file

@ -333,23 +333,31 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
def deactivate(self):
config = self.config
repository = self._get_repository_client()
# Remove the webhook link.
(result, _, err_msg) = repository.services().delete(config['hook_id'])
if not result:
msg = 'Unable to remove webhook from repository: %s' % err_msg
hook_id = config.pop('hook_id', None)
deploy_key_id = config.pop('deploy_key_id', None)
try:
repository = self._get_repository_client()
# Remove the webhook link.
if hook_id is not None:
(result, _, err_msg) = repository.services().delete(hook_id)
if not result:
msg = 'Unable to remove webhook from repository: %s' % err_msg
raise TriggerDeactivationException(msg)
# Remove the public key.
if deploy_key_id is not None:
(result, _, err_msg) = repository.deploykeys().delete(deploy_key_id)
if not result:
msg = 'Unable to remove deploy key from repository: %s' % err_msg
raise TriggerDeactivationException(msg)
except GitHubBadCredentialsException:
msg = ('Unable to remove trigger as credentials are invalid. ' +
'Please manually remove the webhook and deploy key.')
raise TriggerDeactivationException(msg)
# Remove the public key.
(result, _, err_msg) = repository.deploykeys().delete(config['deploy_key_id'])
if not result:
msg = 'Unable to remove deploy key from repository: %s' % err_msg
raise TriggerDeactivationException(msg)
config.pop('hook_id', None)
config.pop('deploy_key_id', None)
return config
def list_build_sources(self):