def delete_command(src_path: str): ''' Entry-point for the "bugbuddy generate" command @param src_path: path to the repository ''' url = get_repository_url_from_path(src_path) with session_manager() as session: repository = get(session, Repository, url=url) # make sure you cannot delete the bug_buddy branch if repository.name not in ['bug_buddy', 'BugBuddy']: msg = ('Would you like to delete the bug_buddy branch for {}?\n' '(y/n)\n'.format(repository)) should_delete = input(msg) if is_affirmative(should_delete): logger.info('Deleting bug_buddy branch') delete_bug_buddy_branch(repository or Mock(src_path=src_path)) if repository: logger.info('Deleting data from the database') delete(session, repository) else: logger.info('No matching repo found in the database')
def watch_command(src_path: str, commit_only: bool): ''' Watches a repository and records any changes ''' with session_manager() as session: repository = _get_repository_from_src_path(session, src_path) watch(repository, commit_only)
def do_command(src_path: str): ''' dos a neural network on the available data ''' with session_manager() as session: repository = _get_repository_from_src_path(session, src_path) logger.info('Doing stuff to repository: "{}"'.format(repository)) cache_test_results(repository)
def train_command(src_path: str): ''' Trains a neural network on the available data ''' with session_manager() as session: repository = _get_repository_from_src_path(session, src_path) logger.info('Training repository: "{}"'.format(repository)) train(repository)
def initialize_command(src_path: str, initialize_commands: str = None, test_commands: str = None, src_directory: str = None, commit_only: bool = False, ignored_files: str = ''): ''' Initializes a repository ''' with session_manager() as session: _initialize_repository(session, src_path, initialize_commands, test_commands, src_directory, commit_only, ignored_files)
def generate_command(src_path: str, run_limit: int = None): ''' Entry-point for the "bugbuddy generate" command @param src_path: path to the repository ''' with session_manager() as session: repository = _get_repository_from_src_path(session, src_path) _check_repo_is_clean(repository) db_and_git_match(repository) logger.info('Creating synthetic results for: {}'.format(repository)) generate_synthetic_test_results(repository, run_limit)
def on_any_event(self, event): ''' Catches all events ''' if '/.' in event.src_path: return updated_file = os.path.relpath(event.src_path, self.repository.original_path) if (not updated_file or updated_file in self.repository.ignored_files or not updated_file.endswith('.py')): return # we have to recreate the repository in this thread for Sqlite with session_manager() as session: repository = get(session, Repository, id=self.repository.id) # logger.info('Syncing updates') # Copy the change over to the mirror repository sync_mirror_repo(repository) if not is_repo_clean(self.repository): logger.info('Valid change event: {}'.format(event)) # make sure the repository is on the bug_buddy branch start = time.time() commit = snapshot(repository, commit_only=self.commit_only) total_time = time.time() - start logger.info( 'Completed snapshot of {commit} in {m}m {s}s'.format( commit=commit, m=total_time / 60, s=total_time % 60)) session.commit() if not self.commit_only: run_all_tests(commit) for test_failure in commit.failed_test_results: predict_blame(test_failure) # display the results in the cli output # self.score_card.render(commit) commit.summary() else: logger.info('Nothing was changed')
def commit_generator(repository_id: int, batch_size: int): ''' Returns augmented commit data for training ''' with session_manager() as session: repository = get(session, Repository, id=repository_id) while True: features = [] labels = [] commits = get_commits(repository, num_commits=batch_size, synthetic=True) for commit in commits: feature = commit_to_state(commit) set_functions_altered_noise(feature) set_tests_not_run_noise(feature) label = commit_to_test_failure_label(commit) features.append(feature) labels.append(label) yield numpy.stack(features), numpy.stack(labels)
#!/usr/bin/env python3 ''' I use this file for quick scripting. For example, updating the database. ''' import argparse from collections import defaultdict import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from bug_buddy.db import get_all, session_manager, delete from bug_buddy.logger import logger from bug_buddy.schema import Commit if __name__ == '__main__': with session_manager() as session: commits = get_all(session, Commit) i = 1 for blame in blames: print('On {} of {}'.format(i, len(blames))) blame.test = blame.test_result.test blame.function = blame.diff.function i += 1