def fetch_file_list(pull, renew=False): repo, num = pull["base"]["repo"]["full_name"], str(pull["number"]) save_path = LOCAL_DATA_PATH + '/pr_data/' + repo + '/' + num + '/raw_diff.json' if os.path.exists(save_path) and (not renew): try: return localfile.get_file(save_path) except: pass t = api.get('repos/%s/pulls/%s/files?page=3' % (repo, num)) file_list = [] if len(t) > 0: raise Exception('too big', pull['html_url']) else: li = api.request('GET', 'repos/%s/pulls/%s/files' % (repo, num), True) time.sleep(0.8) for f in li: if f.get('changes', 0) <= 5000 and ('filename' in f) and ('patch' in f): file_list.append( fetch_raw_diff.parse_diff(f['filename'], f['patch'])) localfile.write_to_file(save_path, file_list) return file_list
def fetch_commit(url, renew=False): api = GitHubAPI() save_path = LOCAL_DATA_PATH + '/pr_data/%s.json' % url.replace('https://api.github.com/repos/', '') if os.path.exists(save_path) and (not renew): try: return localfile.get_file(save_path) except: pass c = api.request(url) time.sleep(0.7) file_list = [] for f in c['files']: if 'patch' in f: file_list.append(fetch_raw_diff.parse_diff(f['filename'], f['patch'])) localfile.write_to_file(save_path, file_list) return file_list
def fetch_file_list(repo, num, renew=False): api = GitHubAPI() # repo, num = pull["base"]["repo"]["full_name"], str(pull["number"]) outfile_prefix = init.local_pr_data_dir + repo + "/" + str(num) save_path = outfile_prefix + '/raw_diff.json' if os.path.exists(save_path) and (not renew): try: return localfile.get_file(save_path) except: pass file_list = [] li = api.request('repos/%s/pulls/%s/files' % (repo, num), paginate=True) time.sleep(0.8) for f in li: if f.get('changes', 0) <= 5000 and ('filename' in f) and ('patch' in f): file_list.append(fetch_raw_diff.parse_diff(f['filename'], f['patch'])) localfile.write_to_file(save_path, file_list) return file_list