コード例 #1
0
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')
コード例 #2
0
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)
コード例 #3
0
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)
コード例 #4
0
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)
コード例 #5
0
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)
コード例 #6
0
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)
コード例 #7
0
    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')
コード例 #8
0
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)
コード例 #9
0
#!/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