def test_no_module_name_passed_in(self, create_task_mappings_mock):
     mock_evg_api = MagicMock()
     created_task_mock = MagicMock()
     created_task_mock.transform.return_value = ["mock-mappings"]
     create_task_mappings_mock.return_value = (created_task_mock, "most-recent-version-analyzed")
     task_mappings, most_recent_version_analyzed = under_test.generate_task_mappings(
         mock_evg_api,
         "mongodb-mongo-master",
         VersionLimit(stop_at_version_id="my-version"),
         ".*src",
         build_variant_pattern=".*!",
     )
     assert task_mappings == ["mock-mappings"]
     assert most_recent_version_analyzed == "most-recent-version-analyzed"
Пример #2
0
def create(
    ctx: Context,
    evergreen_project: str,
    after: str,
    source_file_regex: str,
    module_name: str,
    module_source_file_regex: str,
    build_variant_regex: str,
    output_file: str,
) -> None:
    """Create the task mappings for a given evergreen project."""
    evg_api = ctx.obj["evg_api"]

    try:
        after_date = datetime.fromisoformat(after)
    except ValueError:
        raise click.ClickException(
            "The after date could not be parsed - make sure it's an iso date"
        )

    if module_name:
        if not module_source_file_regex:
            raise click.ClickException(
                "A module source file regex is required when a module is being analyzed"
            )

    LOGGER.info(f"Creating task mappings for {evergreen_project}")
    mappings, _ = generate_task_mappings(
        evg_api,
        evergreen_project,
        VersionLimit(stop_at_date=after_date),
        source_file_regex,
        module_name,
        module_source_file_regex,
        build_variant_regex,
    )
    json_dump = json.dumps(mappings, indent=4)

    if output_file:
        with open(output_file, "a") as f:
            f.write(json_dump)
    else:
        print(json_dump)

    LOGGER.info("Finished processing task mappings")
def _seed_task_mappings_for_project(
    evg_api: EvergreenApi,
    mongo: MongoWrapper,
    work_item: ProjectTaskMappingWorkItem,
    after_date: datetime,
    log: Any,
) -> bool:
    """
    Generate task mappings for a given work item.

    :param evg_api: An instance of the evg_api client
    :param mongo: An instance of MongoWrapper.
    :param work_item: An instance of ProjectTestMappingWorkItem.
    :param after_date: The date at which to start analyzing commits of the project.
    """
    mappings, most_recent_version_analyzed = generate_task_mappings(
        evg_api,
        work_item.project,
        VersionLimit(stop_at_date=after_date),
        work_item.source_file_regex,
        module_name=work_item.module,
        module_source_file_pattern=work_item.module_source_file_regex,
        build_variant_pattern=work_item.build_variant_regex,
    )

    project_config = ProjectConfig.get(mongo.project_config(), work_item.project)
    project_config.task_config.update(
        most_recent_version_analyzed,
        work_item.source_file_regex,
        work_item.build_variant_regex,
        work_item.module,
        work_item.module_source_file_regex,
    )

    project_config.save(mongo.project_config())

    if mappings:
        update_task_mappings(mappings, mongo)
    else:
        LOGGER.info("No task mappings generated")
    log.info("Finished task mapping work item processing")

    return True
def update_task_mappings_since_last_commit(evg_api: EvergreenApi,
                                           mongo: MongoWrapper) -> None:
    """
    Update task mappings that are being tracked in the task mappings project config collection.

    :param evg_api: An instance of the evg_api client
    :param mongo: An instance of MongoWrapper.
    """
    LOGGER.info("Updating task mappings")
    project_cursor = mongo.project_config().find({})
    for project_config in project_cursor:
        LOGGER.info("Updating task mappings for project",
                    project_config=project_config)
        task_config = project_config["task_config"]

        mappings, most_recent_version_analyzed = generate_task_mappings(
            evg_api,
            project_config["project"],
            VersionLimit(
                stop_at_version_id=task_config["most_recent_version_analyzed"]
            ),
            task_config["source_file_regex"],
            module_name=task_config["module"],
            module_source_file_pattern=task_config["module_source_file_regex"],
            build_variant_pattern=task_config["build_variant_regex"],
        )

        project_config = ProjectConfig.get(mongo.project_config(),
                                           project_config["project"])
        project_config.task_config.update_most_recent_version_analyzed(
            most_recent_version_analyzed)
        project_config.save(mongo.project_config())

        if mappings:
            update_task_mappings(mappings, mongo)
        else:
            LOGGER.info("No task mappings generated")
    LOGGER.info("Finished task mapping updating")