<commit_before>from argh import arg

import pnc_cli.common as common
import pnc_cli.cli_types as types
import pnc_cli.utils as utils
from pnc_cli.swagger_client import BuildrecordsApi
from pnc_cli.swagger_client import BuildconfigurationsApi
from pnc_cli.swagger_client import ProjectsApi
import pnc_cli.user_config as uc

records_api = BuildrecordsApi(uc.user.get_api_client())
configs_api = BuildconfigurationsApi(uc.user.get_api_client())
projects_api = ProjectsApi(uc.user.get_api_client())


@arg("-p", "--page-size", help="Limit the amount of BuildRecords returned", type=int)
@arg("-s", "--sort", help="Sorting RSQL")
@arg("-q", help="RSQL query")
def list_build_records(page_size=200, sort="", q=""):
    """
    List all BuildRecords
    """
    response = utils.checked_api_call(records_api, 'get_all', page_size=page_size, sort=sort, q=q)
    if response:
        return utils.format_json_list(response.content)


@arg("-i", "--id", help="BuildConfiguration ID to retrieve BuildRecords of.", type=types.existing_bc_id)
@arg("-n", "--name", help="BuildConfiguration name to retrieve BuildRecords of.", type=types.existing_bc_name)
@arg("-p", "--page-size", help="Limit the amount of BuildRecords returned", type=int)
@arg("-s", "--sort", help="Sorting RSQL")
@arg("-q", help="RSQL query")
def list_records_for_build_configuration(id=None, name=None, page_size=200, sort="", q=""):
    """
    List all BuildRecords for a given BuildConfiguration
    """
    config_id = common.set_id(configs_api, id, name)
    response = utils.checked_api_call(records_api, 'get_all_for_build_configuration', configuration_id=config_id,
                                      page_size=page_size, sort=sort, q=q)
    if response:
        return utils.format_json_list(response.content)


@arg("-i", "--id", help="Project ID to retrieve BuildRecords of.")
@arg("-n", "--name", help="Project name to retrieve BuildRecords of.")
@arg("-p", "--page-size", help="Limit the amount of BuildRecords returned")
@arg("-s", "--sort", help="Sorting RSQL")
@arg("-q", help="RSQL query")
def list_records_for_project(id=None, name=None, page_size=200, sort="", q=""):
    """
    List all BuildRecords for a given Project
    """
    project_id = common.set_id(projects_api, id, name)
    response = utils.checked_api_call(records_api, 'get_all_for_project', project_id=project_id, page_size=page_size,
                                      sort=sort, q=q)
    if response:
        return utils.format_json_list(response.content)


@arg("id", help="BuildRecord ID to retrieve.", type=types.existing_build_record)
def get_build_record(id):
    """
    Get a specific BuildRecord by ID
    """
    response = utils.checked_api_call(records_api, 'get_specific', id=id)
    if response:
        return utils.format_json(response.content)


@arg("id", help="BuildRecord ID to retrieve artifacts from.", type=types.existing_build_record)
@arg("-p", "--page-size", help="Limit the amount of Artifacts returned", type=int)
@arg("-s", "--sort", help="Sorting RSQL")
@arg("-q", help="RSQL query")
def list_built_artifacts(id, page_size=200, sort="", q=""):
    """
    List Artifacts associated with a BuildRecord
    """
    response = utils.checked_api_call(records_api, 'get_built_artifacts', id=id, page_size=page_size, sort=sort, q=q)
    if response:
        return utils.format_json_list(response.content)


@arg("id", help="BuildRecord ID to retrieve dependency Artifacts from.", type=types.existing_build_record)
@arg("-p", "--page-size", help="Limit the amount of Artifacts returned", type=int)
@arg("-s", "--sort", help="Sorting RSQL")
@arg("-q", help="RSQL query")
def list_dependency_artifacts(id, page_size=200, sort="", q=""):
    """
    List dependency artifacts associated with a BuildRecord
    """
    response = utils.checked_api_call(records_api, 'get_dependency_artifacts', id=id, page_size=page_size, sort=sort,
                                      q=q)
    if response:
        return utils.format_json_list(response.content)


@arg("id", help="BuildRecord ID to retrieve audited BuildConfiguration from.", type=types.existing_build_record)
def get_audited_configuration_for_record(id):
    """
    Get the BuildConfigurationAudited for a given BuildRecord<commit_msg>Add page index argument to list-built-aritfacts<commit_after>from argh import arg

import pnc_cli.common as common
import pnc_cli.cli_types as types
import pnc_cli.utils as utils
from pnc_cli.swagger_client import BuildrecordsApi
from pnc_cli.swagger_client import BuildconfigurationsApi
from pnc_cli.swagger_client import ProjectsApi
import pnc_cli.user_config as uc

records_api = BuildrecordsApi(uc.user.get_api_client())
configs_api = BuildconfigurationsApi(uc.user.get_api_client())
projects_api = ProjectsApi(uc.user.get_api_client())


@arg("-p", "--page-size", help="Limit the amount of BuildRecords returned", type=int)
@arg("-s", "--sort", help="Sorting RSQL")
@arg("-q", help="RSQL query")
def list_build_records(page_size=200, sort="", q=""):
    """
    List all BuildRecords
    """
    response = utils.checked_api_call(records_api, 'get_all', page_size=page_size, sort=sort, q=q)
    if response:
        return utils.format_json_list(response.content)


@arg("-i", "--id", help="BuildConfiguration ID to retrieve BuildRecords of.", type=types.existing_bc_id)
@arg("-n", "--name", help="BuildConfiguration name to retrieve BuildRecords of.", type=types.existing_bc_name)
@arg("-p", "--page-size", help="Limit the amount of BuildRecords returned", type=int)
@arg("-s", "--sort", help="Sorting RSQL")
@arg("-q", help="RSQL query")
def list_records_for_build_configuration(id=None, name=None, page_size=200, sort="", q=""):
    """
    List all BuildRecords for a given BuildConfiguration
    """
    config_id = common.set_id(configs_api, id, name)
    response = utils.checked_api_call(records_api, 'get_all_for_build_configuration', configuration_id=config_id,
                                      page_size=page_size, sort=sort, q=q)
    if response:
        return utils.format_json_list(response.content)


@arg("-i", "--id", help="Project ID to retrieve BuildRecords of.")
@arg("-n", "--name", help="Project name to retrieve BuildRecords of.")
@arg("-p", "--page-size", help="Limit the amount of BuildRecords returned")
@arg("-s", "--sort", help="Sorting RSQL")
@arg("-q", help="RSQL query")
def list_records_for_project(id=None, name=None, page_size=200, sort="", q=""):
    """
    List all BuildRecords for a given Project
    """
    project_id = common.set_id(projects_api, id, name)
    response = utils.checked_api_call(records_api, 'get_all_for_project', project_id=project_id, page_size=page_size,
                                      sort=sort, q=q)
    if response:
        return utils.format_json_list(response.content)


@arg("id", help="BuildRecord ID to retrieve.", type=types.existing_build_record)
def get_build_record(id):
    """
    Get a specific BuildRecord by ID
    """
    response = utils.checked_api_call(records_api, 'get_specific', id=id)
    if response:
        return utils.format_json(response.content)


@arg("id", help="BuildRecord ID to retrieve artifacts from.", type=types.existing_build_record)
@arg("-p", "--page-size", help="Limit the amount of Artifacts returned", type=int)
@arg("-s", "--sort", help="Sorting RSQL")
@arg("-q", help="RSQL query")
@arg("--page-index", help="Page index")
def list_built_artifacts(id, page_size=200, sort="", q="", page_index=0):
    """
    List Artifacts associated with a BuildRecord
    """
    response = utils.checked_api_call(records_api, 'get_built_artifacts', id=id,
            page_size=page_size, sort=sort, q=q,
            page_index=page_index)
    if response:
        return utils.format_json_list(response.content)


@arg("id", help="BuildRecord ID to retrieve dependency Artifacts from.", type=types.existing_build_record)
@arg("-p", "--page-size", help="Limit the amount of Artifacts returned", type=int)
@arg("-s", "--sort", help="Sorting RSQL")
@arg("-q", help="RSQL query")
def list_dependency_artifacts(id, page_size=200, sort="", q=""):
    """
    List dependency artifacts associated with a BuildRecord
    """
    response = utils.checked_api_call(records_api, 'get_dependency_artifacts', id=id, page_size=page_size, sort=sort,
                                      q=q)
    if response:
        return utils.format_json_list(response.content)


@arg("id", help="BuildRecord ID to retrieve audited BuildConfiguration from.", type=types.existing_build_record)
def get_audited_configuration_for_record(id):
    """
    Get the BuildConfigurationAudited for a given BuildRecord
{'fraction_non_alphanumeric': 0.14178501327791249, 'fraction_numerical': 0.0035792633645075627, 'mean_word_length': 4.538363171355499, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4002908', 'n_tokens_mistral': 2727, 'n_tokens_neox': 2735, 'n_words': 661}