import requests


def hook_exists(full_name, token):
    """ Return True if a hook for the repository is listed on travis. """

    headers = {
        'Authorization': 'token %s' % token,
    }
    response = requests.get(
        'http://api.travis-ci.org/hooks', headers=headers
    )

    owner, name = full_name.split('/')
    if response.status_code == 200:
        repositories = [
            repo for repo in response.json()
            if repo['name'] == name and repo['owner_name'] == owner
        ]
        hook_exists = len(repositories) > 0

    else:
        hook_exists = False

    return hook_exists