def main(argv): parser = argparse.ArgumentParser( prog="antibody", description=sys.modules['__main__'].__doc__) antibody.add_argparse_options(parser) infra_libs.logs.add_argparse_options(parser) args = parser.parse_args(argv) infra_libs.logs.process_argparse_options(args) if args.cache_path: requests_cache.install_cache(args.cache_path) else: requests_cache.install_cache(os.path.join(DATA_DIR, 'rietveld_cache')) # Do more processing here LOGGER.info('Antibody starting') with open(args.sql_password_file, 'r') as f: password = f.read().strip() connection, cc = csql.connect(password, args.database) checkout = args.git_checkout_path if args.parse_git_rietveld or args.run_antibody: antibody.setup_antibody_db( cc, os.path.join(DATA_DIR, 'ANTIBODY_DB_schema_setup.sql'), args.database) git_commit_parser.upload_to_sql(cc, checkout, args.since) git_commits_with_review_urls = git_commit_parser.get_urls_from_git_commit( cc) for review_url in git_commits_with_review_urls: # cannot get access into chromereview.googleplex.com if not any(host in review_url for host in ('chromereviews.googleplex', )): code_review_parse.add_code_review_data_to_db( review_url, cc, checkout) csql.commit(connection) if args.write_html or args.run_antibody: if not os.path.exists(args.output_dir_path): os.makedirs(args.output_dir_path) gitiles_prefix = antibody.get_gitiles_prefix(checkout) if not gitiles_prefix: gitiles_prefix = '' project_name = antibody.get_project_name(checkout).lower() antibody.generate_antibody_ui( cc, gitiles_prefix, project_name, args.since, args.output_dir_path, code_review_parse.get_tbr_no_lgtm(cc, 'author'), args.repo_list) csql.close(connection, cc)
def main(argv): parser = argparse.ArgumentParser( prog="antibody", description=sys.modules['__main__'].__doc__) antibody.add_argparse_options(parser) infra_libs.logs.add_argparse_options(parser) args = parser.parse_args(argv) infra_libs.logs.process_argparse_options(args) if args.cache_path: requests_cache.install_cache(args.cache_path) else: requests_cache.install_cache(os.path.join(DATA_DIR, 'rietveld_cache')) # Do more processing here LOGGER.info('Antibody starting') with open(args.sql_password_file, 'r') as f: password = f.read().strip() connection, cc = csql.connect(password, args.database) checkout = args.git_checkout_path if args.parse_git_rietveld or args.run_antibody: antibody.setup_antibody_db(cc, os.path.join( DATA_DIR, 'ANTIBODY_DB_schema_setup.sql'), args.database) git_commit_parser.upload_to_sql(cc, checkout, args.since) git_commits_with_review_urls = git_commit_parser.get_urls_from_git_commit( cc) for review_url in git_commits_with_review_urls: # cannot get access into chromereview.googleplex.com if not any(host in review_url for host in ( 'chromereviews.googleplex', )): code_review_parse.add_code_review_data_to_db(review_url, cc, checkout) csql.commit(connection) if args.write_html or args.run_antibody: if not os.path.exists(args.output_dir_path): os.makedirs(args.output_dir_path) gitiles_prefix = antibody.get_gitiles_prefix(checkout) if not gitiles_prefix: gitiles_prefix = '' project_name = antibody.get_project_name(checkout).lower() antibody.generate_antibody_ui(cc, gitiles_prefix, project_name, args.since, args.output_dir_path, code_review_parse.get_tbr_no_lgtm(cc, 'author'), args.repo_list) csql.close(connection, cc)
def test_generate_antibody_ui(self, mock_tbr_by_user, mock_gen_stats, mock_tbr_no_lgtm): #pylint: disable=W0613 fake_cc = None with infra_libs.temporary_directory(prefix='antibody-test') as dirname: commit_data = 'data/sample_suspicious_commits.txt' with open(os.path.join(THIS_DIR, commit_data), 'r') as f: suspicious_commits_data = [ line.rstrip('\n').split(',') for line in f ] temp_data_gitiles = "https://chromium.googlesource.com/infra/infra/+/" sample_monthly_stats = { '7_days': { 'suspicious_to_total_ratio': 1, 'total_commits': 2, 'tbr_no_lgtm': 3, 'no_review_url': 4, 'blank_tbr': 5, 'tbr_no_lgtm_commits': [ [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop" ], [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 2", "123456789abcdefghijklmnop" ], [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop" ], ], 'no_review_url_commits': [ [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop" ], [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop" ], ], 'blank_tbr_commits': [ [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop" ], ], }, '30_days': { 'suspicious_to_total_ratio': 1, 'total_commits': 2, 'tbr_no_lgtm': 3, 'no_review_url': 4, 'blank_tbr': 5, 'tbr_no_lgtm_commits': [ [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop" ], [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 2", "123456789abcdefghijklmnop" ], [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop" ], ], 'no_review_url_commits': [ [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop" ], [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop" ], ], 'blank_tbr_commits': [ [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop" ], ], }, 'all_time': { 'suspicious_to_total_ratio': 1, 'total_commits': 2, 'tbr_no_lgtm': 3, 'no_review_url': 4, 'blank_tbr': 5, 'tbr_no_lgtm_commits': [ [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop" ], [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 2", "123456789abcdefghijklmnop" ], [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop" ], ], 'no_review_url_commits': [ [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop" ], [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop" ], ], 'blank_tbr_commits': [ [ "https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop" ], ], }, } proj_dirname = os.path.join(dirname, 'proj') os.makedirs(proj_dirname) with open(os.path.join(proj_dirname, 'all_monthly_stats.json'), 'w') as f: json.dump(sample_monthly_stats, f) antibody.generate_antibody_ui(fake_cc, temp_data_gitiles, 'proj', '2014', dirname, suspicious_commits_data, ['db 1']) with open( os.path.join(proj_dirname, antibody.ANTIBODY_UI_MAIN_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.SEARCH_BY_USER_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.STATS_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.LEADERBOARD_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.STATS_7_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.STATS_30_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.STATS_ALL_TIME_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) self.assertTrue(os.path.exists(os.path.join(dirname, 'static')))
def test_generate_antibody_ui(self, mock_tbr_by_user, mock_gen_stats, mock_tbr_no_lgtm): #pylint: disable=W0613 fake_cc = None with infra_libs.temporary_directory(prefix='antibody-test') as dirname: commit_data = 'data/sample_suspicious_commits.txt' with open(os.path.join(THIS_DIR, commit_data), 'r') as f: suspicious_commits_data = [line.rstrip('\n').split(',') for line in f] temp_data_gitiles="https://chromium.googlesource.com/infra/infra/+/" sample_monthly_stats = { '7_days': { 'suspicious_to_total_ratio': 1, 'total_commits': 2, 'tbr_no_lgtm': 3, 'no_review_url': 4, 'blank_tbr': 5, 'tbr_no_lgtm_commits': [ ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop"], ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 2", "123456789abcdefghijklmnop"], ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop"], ], 'no_review_url_commits': [ ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop"], ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop"], ], 'blank_tbr_commits': [ ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop"], ], }, '30_days': { 'suspicious_to_total_ratio': 1, 'total_commits': 2, 'tbr_no_lgtm': 3, 'no_review_url': 4, 'blank_tbr': 5, 'tbr_no_lgtm_commits': [ ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop"], ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 2", "123456789abcdefghijklmnop"], ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop"], ], 'no_review_url_commits': [ ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop"], ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop"], ], 'blank_tbr_commits': [ ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop"], ], }, 'all_time': { 'suspicious_to_total_ratio': 1, 'total_commits': 2, 'tbr_no_lgtm': 3, 'no_review_url': 4, 'blank_tbr': 5, 'tbr_no_lgtm_commits': [ ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop"], ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 2", "123456789abcdefghijklmnop"], ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop"], ], 'no_review_url_commits': [ ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 1", "123456789abcdefghijklmnop"], ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop"], ], 'blank_tbr_commits': [ ["https://codereview.chromium.org/", "2015-07-13 11:11:11", "Fake Commit Subject 3", "123456789abcdefghijklmnop"], ], }, } proj_dirname = os.path.join(dirname, 'proj') os.makedirs(proj_dirname) with open(os.path.join(proj_dirname, 'all_monthly_stats.json'), 'w') as f: json.dump(sample_monthly_stats, f) antibody.generate_antibody_ui(fake_cc, temp_data_gitiles, 'proj', '2014', dirname, suspicious_commits_data, ['db 1']) with open( os.path.join(proj_dirname, antibody.ANTIBODY_UI_MAIN_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.SEARCH_BY_USER_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.STATS_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.LEADERBOARD_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.STATS_7_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.STATS_30_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) with open(os.path.join(proj_dirname, antibody.STATS_ALL_TIME_NAME), 'r') as f: file_string = f.read() self.assertTrue(file_string) self.assertFalse('{{' in file_string) self.assertFalse('}}' in file_string) self.assertTrue(os.path.exists(os.path.join(dirname, 'static')))