Merge pull request #142 from coreos-inc/githubdelfix
Allow GitHub triggers to be removed if OAuth token is invalid
This commit is contained in:
commit
2d6c0eadb1
1 changed files with 22 additions and 14 deletions
|
@ -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):
|
||||
|
|
Reference in a new issue