def get_features(repository, begin, end):
    """
        For a given repository, get all files impacted by the modifications
        of the code between 2 releases/tags.
    """
    modified_files, success = get_modified_files(repository, begin, end)
    if not success:
        return json.dumps({
            'error':
            f'couldn\'t get files modified between {begin} and {end}.'
        })
    query = f"MATCH (repo:Repository)-[:FILE]->(startFile:File) \
                WHERE repo.name = '{repository}' \
                AND startFile.path IN {str(modified_files)} \
                \
                MATCH (startFile)<-[:IS_DECLARED_BY|:USES|:INCLUDES|:REQUIRES*0..10]-(endFile:File) \
                RETURN DISTINCT endFile.path AS impacted_file \
                ORDER BY impacted_file ASC"

    driver = build_driver()
    result, success = run_query(driver, query)
    driver.close()
    if not success:
        return json.dumps(result)

    output = list()
    for record in result.records():
        output.append(record['impacted_file'])

    return json.dumps('\n'.join(output))
Beispiel #2
0
def upload_repo(data):
    """
        Uploads a repository into the database.
        !!! If the repository already exists, it will not be first deleted !!!
        @data is a hashmap, it has to contains:
            - repository_name (str)
            - extensions (list)
            - no_extension_files (0 or 1)
            - directories_to_ignore (list)
            - files_to_ignore (list)
    """
    try:
        repo_name = data['repository_name']
        extensions = prepare_list_arguments(data['extensions'])
        no_extension_files = bool(data['no_extension_files'])
        directories_to_ignore = prepare_list_arguments(
            data['directories_to_ignore'])
        files_to_ignore = prepare_list_arguments(data['files_to_ignore'])
    except KeyError as e:
        return str(e), False

    repo_path = os.path.abspath(os.path.join(STORAGE_DIRECTORY, repo_name))
    if not os.path.isdir(repo_path):
        return f"Repository {repo_name} doesn't exists in storage directory.", False

    repo = repository.Repository(path=repo_path,
                                 extensions=extensions,
                                 no_extension_files=no_extension_files,
                                 directories_to_ignore=directories_to_ignore,
                                 files_to_ignore=files_to_ignore)
    repo.build_filepath_list()
    repo.parse()

    driver = database.build_driver()

    print("Uploading files...")
    result, success = repo.upload_files(driver)
    if not success:
        driver.close()
        print(json.dumps(result))
        return json.dumps(result), False

    print("Building map...")
    result, success = repo.build_map(driver)
    driver.close()
    if not success:
        print(json.dumps(result))
        return json.dumps(result), False

    return '\n'.join(repo.logs), True
def get_repos():
    """Return the list of the repositories modelled in the db"""
    query = "MATCH (repo:Repository) RETURN repo.name AS repo"
    driver = build_driver()
    result, success = run_query(driver, query)
    driver.close()
    if not success:
        return json.dumps(result)

    output = list()
    for record in result.records():
        output.append(record['repo'])

    return json.dumps(output)
Beispiel #4
0
def delete_repo_from_db(repository_name):
    """
        Fully deletes a repository, all its files and classes from the database
        @param repository_name is the name of the repository
    """
    repo_path = os.path.abspath(
        os.path.join(STORAGE_DIRECTORY, repository_name))

    repo = repository.Repository(path=repo_path)
    driver = database.build_driver()
    print("Deleting repo from db...")
    result, success = repo.delete_from_db(driver)
    driver.close()

    if not success:
        return result, False
    return f"Repository {repository_name} was successfully deleted from db.", True
Beispiel #5
0
def main():

    repo_path = "/var/www/html/Pricer2016Q2"
    #repo_path = "/var/www/html/X"
    #repo_path = "/var/www/html/type_test_repo"
    repo = Repository(path=repo_path, extensions=['php', 'inc'], directories_to_ignore=[".git", "tests", "TOOLS", "vendor"], files_to_ignore=[])
    repo.build_filepath_list()
    repo.parse()


    driver = database.build_driver()
    repo.upload_files(driver)

    result, success = repo.build_map(driver)
    if not success:
        print(json.dumps(result, indent=4))
    driver.close()

    """