Exemple #1
0
def post(
        work_item_params: TestMappingsWorkItem,
        project: str,
        evg_api: EvergreenApi = Depends(get_evg),
        db: MongoWrapper = Depends(get_db),
) -> CustomResponse:
    """
    Enqueue a project test mapping work item.

    :param evg_api: Evergreen API.
    :param db: The database
    :param work_item_params: The work items to enqueue.
    :param project: The evergreen project.
    """
    LOGGER.info("Adding a test mapping work item to queue for project",
                project=project)
    evg_project = try_retrieve_evergreen_project(project, evg_api)
    module = work_item_params.module
    module_source_file_regex = work_item_params.module_source_file_regex
    module_test_file_regex = work_item_params.module_test_file_regex
    if module and (not module_source_file_regex or not module_test_file_regex):
        raise HTTPException(
            status_code=400,
            detail="The module_source_file_regex and module_test_file_regex"
            " params are required if a module name is passed in",
        )

    work_item = ProjectTestMappingWorkItem.new_test_mappings(
        evg_project.identifier,
        work_item_params.source_file_regex,
        work_item_params.test_file_regex,
        module,
        module_source_file_regex,
        module_test_file_regex,
    )
    if work_item.insert(db.test_mappings_queue()):
        return CustomResponse(
            custom=f"Work item added for project '{evg_project.identifier}'")
    else:
        raise HTTPException(
            status_code=422,
            detail=
            f"Work item already exists for project '{evg_project.identifier}'",
        )
def post(
        work_item_params: TaskMappingsWorkItem,
        project: str,
        evg_api: EvergreenApi = Depends(get_evg),
        db: MongoWrapper = Depends(get_db),
) -> CustomResponse:
    """
    Enqueue a project task mapping work item.

    :param evg_api: Evergreen API.
    :param db: The database.
    :param work_item_params: The work items to enqueue.
    :param project: The evergreen project identifier.
    """
    evg_project = try_retrieve_evergreen_project(project, evg_api)
    module = work_item_params.module
    module_source_file_regex = work_item_params.module_source_file_regex
    if module and not module_source_file_regex:
        raise HTTPException(
            status_code=400,
            detail="The module_source_file_regex param is required if "
            "a module name is passed in",
        )

    work_item = ProjectTaskMappingWorkItem.new_task_mappings(
        evg_project.identifier,
        work_item_params.source_file_regex,
        module,
        module_source_file_regex,
        work_item_params.build_variant_regex,
    )

    if work_item.insert(db.task_mappings_queue()):
        return CustomResponse(
            custom=f"Work item added for project '{evg_project.identifier}'")
    else:
        raise HTTPException(
            status_code=422,
            detail=
            f"Work item already exists for project '{evg_project.identifier}'",
        )
def get(
        project: str,
        changed_files: str,
        threshold: Decimal = Decimal(0),
        evg_api: EvergreenApi = Depends(get_evg),
        db: MongoWrapper = Depends(get_db),
) -> TestMappingsResponse:
    """
    Get a list of correlated test mappings for an input list of changed source files.

    :param evg_api: The evergreen API.
    :param db: The database.
    :param project: The evergreen project.
    :param changed_files: List of source files to calculate correlated tasks for.
    :param threshold: Minimum threshold desired for flip_count / source_file_seen_count ratio
    """
    evg_project = try_retrieve_evergreen_project(project, evg_api)
    test_mappings = get_correlated_test_mappings(
        db.test_mappings(), parse_changed_files(changed_files),
        evg_project.identifier, threshold)
    return TestMappingsResponse(test_mappings=test_mappings)
def get(
    changed_files: str,
    project: str,
    threshold: Decimal = Decimal(0),
    evg_api: EvergreenApi = Depends(get_evg),
    db: MongoWrapper = Depends(get_db),
) -> TaskMappingsResponse:
    """
    Get a list of correlated task mappings for an input list of changed source files.

    :param evg_api: Evergreen API client.
    :param db: The database.
    :param project: The evergreen project.
    :param changed_files: List of source files to calculate correlated tasks for.
    :param threshold: Minimum threshold desired for flip_count / source_file_seen_count ratio
    """
    LOGGER.info("Starting fetching task_mappings for project", project=project)
    evg_project = try_retrieve_evergreen_project(project, evg_api)
    LOGGER.info("Retrieved evergreen project information", evergreen_project=evg_project.identifier)
    task_mappings = get_correlated_task_mappings(
        db.task_mappings(), parse_changed_files(changed_files), evg_project.identifier, threshold
    )
    return TaskMappingsResponse(task_mappings=task_mappings)