def runtime(request):
    """Get the CumulusCI runtime for the current working directory."""

    # if there is a real orgname, use a real CliRuntime
    # to get access to it
    if sf_pytest_cli_orgname(request):
        return CliRuntime()
    else:
        return BaseCumulusCI()
Esempio n. 2
0
def create_org(
    *,
    repo_owner,
    repo_name,
    repo_url,
    repo_branch,
    user,
    project_path,
    scratch_org,
    org_name,
    originating_user_id,
    sf_username=None,
):
    """Create a new scratch org"""
    devhub_username = sf_username or user.sf_username
    email = user.email  # TODO: check that this is reliably right.

    cci = BaseCumulusCI(
        repo_info={
            "root": project_path,
            "url": repo_url,
            "name": repo_name,
            "owner": repo_owner,
            "commit": repo_branch,
        })
    devhub_api = get_devhub_api(devhub_username=devhub_username,
                                scratch_org=scratch_org)
    scratch_org_config, scratch_org_definition = get_org_details(
        cci=cci, org_name=org_name, project_path=project_path)
    org_result = get_org_result(
        email=email,
        repo_owner=repo_owner,
        repo_name=repo_name,
        repo_branch=repo_branch,
        scratch_org_config=scratch_org_config,
        scratch_org_definition=scratch_org_definition,
        cci=cci,
        devhub_api=devhub_api,
    )
    mutate_scratch_org(scratch_org_config=scratch_org_config,
                       org_result=org_result,
                       email=email)
    get_access_token(org_result=org_result,
                     scratch_org_config=scratch_org_config)
    org_config = deploy_org_settings(
        cci=cci,
        org_name=org_name,
        scratch_org_config=scratch_org_config,
        scratch_org=scratch_org,
        originating_user_id=originating_user_id,
    )

    return (scratch_org_config, cci, org_config)
Esempio n. 3
0
def run_retrieve_task(
    user,
    scratch_org,
    project_path,
    desired_changes,
    target_directory,
    originating_user_id,
):
    repo_id = scratch_org.task.epic.project.get_repo_id()
    org_config = refresh_access_token(
        config=scratch_org.config,
        org_name="dev",
        scratch_org=scratch_org,
        originating_user_id=originating_user_id,
    )
    repository = get_repo_info(user, repo_id=repo_id)
    branch = repository.default_branch
    cci = BaseCumulusCI(
        repo_info={
            "root": project_path,
            "url": repository.html_url,
            "name": repository.name,
            "owner": repository.owner.login,
            "commit": branch,
        }
    )

    valid_directories, sfdx = get_valid_target_directories(
        user, scratch_org, project_path
    )
    md_format = not (sfdx and target_directory in valid_directories["source"])

    if sfdx:
        is_main_project_directory = target_directory == valid_directories["source"][0]
    else:
        is_main_project_directory = target_directory == "src"

    # make sure target directory exists
    pathlib.Path(target_directory).mkdir(parents=True, exist_ok=True)

    if is_main_project_directory:
        package_xml_opts = {
            "package_name": cci.project_config.project__package__name,
            "install_class": cci.project_config.project__package__install_class,
            "uninstall_class": cci.project_config.project__package__uninstall_class,
        }
    else:
        package_xml_opts = {}

    components = []
    for mdtype, members in desired_changes.items():
        for name in members:
            components.append({"MemberName": name, "MemberType": mdtype})
    retrieve_components(
        components,
        org_config,
        os.path.realpath(target_directory),
        md_format,
        extra_package_xml_opts=package_xml_opts,
        namespace_tokenize=False,
        api_version=cci.project_config.project__package__api_version,
    )
Esempio n. 4
0
def create_scratch_org(
    *,
    repo_owner,
    repo_name,
    repo_url,
    repo_branch,
    email,
    project_path,
    scratch_org,
    org_name,
    duration,
):
    """Create a new scratch org

    Expects to be called inside a project checkout, so that it has
    access to the cumulusci.yml.
    """
    cci = BaseCumulusCI(
        repo_info={
            "root": project_path,
            "url": repo_url,
            "name": repo_name,
            "owner": repo_owner,
            "commit": repo_branch,
        }
    )
    devhub_api = _get_devhub_api()
    scratch_org_config, scratch_org_definition = _get_org_details(
        cci=cci, org_name=org_name, project_path=project_path
    )
    org_result = _get_org_result(
        # Passed in to create_scratch_org:
        email=email,
        repo_owner=repo_owner,
        repo_name=repo_name,
        repo_branch=repo_branch,
        duration=duration,
        # Created in create_scratch_org:
        cci=cci,
        # From _get_devhub_api:
        devhub_api=devhub_api,
        # From _get_org_details:
        scratch_org_config=scratch_org_config,
        scratch_org_definition=scratch_org_definition,
    )
    _mutate_scratch_org(
        # Passed in to create_scratch_org:
        email=email,
        duration=duration,
        # From _get_org_details:
        scratch_org_config=scratch_org_config,
        # From _get_org_result:
        org_result=org_result,
    )
    _get_access_token(
        # From _get_org_details:
        scratch_org_config=scratch_org_config,
        # From _get_org_result:
        org_result=org_result,
    )
    org_config = _deploy_org_settings(
        # Passed in to create_scratch_org:
        org_name=org_name,
        # Created in create_scratch_org:
        cci=cci,
        # From _get_org_details:
        scratch_org_config=scratch_org_config,
        scratch_org=scratch_org,
    )

    return (
        # From _get_org_details:
        scratch_org_config,
        # Created in create_scratch_org:
        cci,
        # From _deploy_org_settings:
        org_config,
    )