示例#1
0
def get_user_orgs(user):
    url = 'https://api.github.com/user/orgs'
    headers = get_auth_header(user)
    result = make_rest_get_call(url, headers)
    if status.is_success(result.status_code):
        return result.json()
    return None
示例#2
0
def get_user_orgs(user):
    url = 'https://api.github.com/user/orgs'
    headers = get_auth_header(user)
    result = make_rest_get_call(url, headers)
    if status.is_success(result.status_code):
        return result.json()
    return None
示例#3
0
def get_franklin_config(site, user):
    url = build_repos_url(site.owner.name, site.name, 'contents/.franklin.yml')
    # TODO - This will fetch the file from the default master branch
    headers = get_auth_header(user)
    config_metadata = make_rest_get_call(url, headers)

    if status.is_success(config_metadata.status_code):
        download_url = config_metadata.json().get('download_url', None)
        config_payload = make_rest_get_call(download_url, None)
        if status.is_success(config_payload.status_code):
            # TODO - validation and cleanup needed here similar to:
            # http://stackoverflow.com/a/22231372
            franklin_config = yaml.load(config_payload.text)
            return franklin_config
        else:
            return config_payload
    return config_metadata
示例#4
0
def get_branch_details(site, user, branch):
    url = build_repos_url(site.owner.name, site.name, 'branches/' + branch)
    headers = get_auth_header(user)
    result = make_rest_get_call(url, headers)
    if (status.is_success(result.status_code)
            and result.json().get('commit', None)):
        return result.json()['commit'].get('sha', None)
    return ''
示例#5
0
def get_franklin_config(site, user):
    url = build_repos_url(site.owner.name, site.name, 'contents/.franklin.yml')
    # TODO - This will fetch the file from the default master branch
    headers = get_auth_header(user)
    config_metadata = make_rest_get_call(url, headers)

    if status.is_success(config_metadata.status_code):
        download_url = config_metadata.json().get('download_url', None)
        config_payload = make_rest_get_call(download_url, None)
        if status.is_success(config_payload.status_code):
            # TODO - validation and cleanup needed here similar to:
            # http://stackoverflow.com/a/22231372
            franklin_config = yaml.load(config_payload.text)
            return franklin_config
        else:
            return config_payload
    return config_metadata
示例#6
0
def get_branch_details(site, user, branch):
    url = build_repos_url(site.owner.name, site.name, 'branches/' + branch)
    headers = get_auth_header(user)
    result = make_rest_get_call(url, headers)
    if (status.is_success(result.status_code) and
            result.json().get('commit', None)):
        return result.json()['commit'].get('sha', None)
    return ''
示例#7
0
def check_api_health(url):
    try:
        response = make_rest_get_call(url, '')
        if status.is_success(response.status_code):
            return response.json()
    except:
        pass

    return {'status': 'unreachable'}
示例#8
0
def check_api_health(url):
    try:
        response = make_rest_get_call(url, '')
        if status.is_success(response.status_code):
            return response.json()
    except:
        pass

    return {'status': 'unreachable'}
示例#9
0
def get_all_repos(user):
    url = 'https://api.github.com/user/repos?per_page=100'
    headers = get_auth_header(user)
    have_next_page = True
    repos = []
    whitelist = os.environ.get('OWNER_WHITELIST', None)

    while have_next_page:
        result = None
        have_next_page = False  # when in doubt, leave the loop after 1
        result = make_rest_get_call(url, headers)
        if status.is_success(result.status_code):
            # Add all of the repos to our list
            for repo in result.json():
                owner = repo.get('owner', {}).get('login', '')
                if not whitelist or owner in whitelist.split(','):
                    repos.append(repo)

            # If the header has a paging link called 'next', update our url
            # and continue with the while loop
            if result.links and result.links.get('next', None):
                url = result.links['next']['url']
                have_next_page = True
    return repos
示例#10
0
def get_all_repos(user):
    url = 'https://api.github.com/user/repos?per_page=100'
    headers = get_auth_header(user)
    have_next_page = True
    repos = []
    whitelist = os.environ.get('OWNER_WHITELIST', None)

    while have_next_page:
        result = None
        have_next_page = False  # when in doubt, leave the loop after 1
        result = make_rest_get_call(url, headers)
        if status.is_success(result.status_code):
            # Add all of the repos to our list
            for repo in result.json():
                owner = repo.get('owner', {}).get('login', '')
                if not whitelist or owner in whitelist.split(','):
                    repos.append(repo)

            # If the header has a paging link called 'next', update our url
            # and continue with the while loop
            if result.links and result.links.get('next', None):
                url = result.links['next']['url']
                have_next_page = True
    return repos
示例#11
0
def get_repo(owner, repo, user):
    url = build_repos_root_url(owner, repo)
    headers = get_auth_header(user)
    return make_rest_get_call(url, headers)
示例#12
0
def get_repo(owner, repo, user):
    url = build_repos_root_url(owner, repo)
    headers = get_auth_header(user)
    return make_rest_get_call(url, headers)