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
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
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 ''
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'}
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
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)