@register_hook
def bitbucket_hook_helper(data):
 if ('push' in data):
  return bitbucket_webhook_helper(data)
 owner = data['repository']['owner']
 slug = data['repository']['slug']
 if data['commits']:
  branch = data['commits'][(-1)]['branch']
 else:
  branch = None
 params = {'owner': owner, 'slug': slug}
 if (data['repository']['scm'] == 'git'):
  repos = [(repo % params) for repo in BITBUCKET_GIT_REPOS]
 elif (data['repository']['scm'] == 'hg'):
  repos = [(repo % params) for repo in BITBUCKET_HG_REPOS]
 else:
  LOGGER.error('unsupported repository: %s', repr(data['repository']))
  raise ValueError('unsupported repository')
 return {'service_long_name': 'Bitbucket', 'repo_url': ''.join([data['canon_url'], data['repository']['absolute_url']]), 'repos': repos, 'branch': branch}

@ register_hook def bitbucket_hook_helper ( data ) : if ( 'push' in data ) : return bitbucket_webhook_helper ( data ) owner = data [ 'repository' ] [ 'owner' ] slug = data [ 'repository' ] [ 'slug' ] if data [ 'commits' ] : branch = data [ 'commits' ] [ ( - 1 ) ] [ 'branch' ] else : branch = None params = { 'owner' : owner , 'slug' : slug } if ( data [ 'repository' ] [ 'scm' ] == 'git' ) : repos = [ ( repo % params ) for repo in BITBUCKET_GIT_REPOS ] elif ( data [ 'repository' ] [ 'scm' ] == 'hg' ) : repos = [ ( repo % params ) for repo in BITBUCKET_HG_REPOS ] else : LOGGER . error ( 'unsupported repository: %s' , repr ( data [ 'repository' ] ) ) raise ValueError ( 'unsupported repository' ) return { 'service_long_name' : 'Bitbucket' , 'repo_url' : '' . join ( [ data [ 'canon_url' ] , data [ 'repository' ] [ 'absolute_url' ] ] ) , 'repos' : repos , 'branch' : branch }
api to handle service hooks from bitbucket .