def add_org_repo(models): """Populate the org and repo fields in the model""" for i in models: org, repo = get_org_repo(models[i]['url']) if org is not None and repo is not None: models[i]['github_org'] = org models[i]['github_repo'] = repo return models
def put_all(reports, key, testing=False): """Iterate through all reports and store them in GitHub""" # Review the iteration to check for errors -- Looks like there's no issue if wait between two PUTs git_urls = {} pubs_to_check = reports.keys() retry = 0 while len(pubs_to_check) > 0 and retry < 5: retry += 1 for pub in reports: if pub in pubs_to_check: pubs_to_check.pop(pubs_to_check.index(pub)) report = reports[pub] org, repo = get_org_repo(report['url']) # Testing values if testing is True: org = 'jotegui' repo = 'statReports' path_txt, sha_txt, git_url_txt, path_html, sha_html, git_url_html = put_report(report, pub, org, repo, key) if sha_txt == '' and sha_html != '': logging.warning('File {0} failed to upload, deleting {1}'.format(path_txt, path_html)) del_github_file(org, repo, path_html, sha_html, key) pubs_to_check.append(pub) elif sha_html == '' and sha_txt != '': pubs_to_check.append(pub) logging.warning('File {0} failed to upload, deleting {1}'.format(path_html, path_txt)) del_github_file(org, repo, path_txt, sha_txt, key) elif sha_txt == '' and sha_html == '': logging.warning('Both files {0} and {1} failed to upload'.format(path_txt, path_html)) pubs_to_check.append(pub) else: git_urls[pub] = { 'org': org, 'repo': repo, 'path_txt': path_txt, 'sha_txt': sha_txt, 'git_url_txt': git_url_txt, 'path_html': path_html, 'sha_html': sha_html, 'git_url_html': git_url_html } logging.info('Finished putting stats in github repos') return git_urls