Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Option resolve_sfdx_package_dirs for dx_convert_from Task #3560

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion cumulusci/tasks/dx_convert_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@


class DxConvertFrom(SFDXBaseTask):
"""Call the sfdx cli to convert sfdx source format to mdapi format"""

task_options = {
"extra": {"description": "Append additional options to the command"},
"resolve_sfdx_package_dirs": {
"description": "If True, will resolve package directory paths in sfdx-project.json and append them to the source:convert command via --sourcepath. If you need to use --sourcepath, use the extra option to pass the --sourcepath argument instead of this option",
},
"src_dir": {
"description": "The path to the src directory where converted contents will be stored. Defaults to src/",
"required": True,
Expand All @@ -16,11 +21,29 @@ class DxConvertFrom(SFDXBaseTask):
def _init_options(self, kwargs):
super()._init_options(kwargs)

# append command -d option to sfdx} force:source:convert
# append command -d option to sfdx force:source:convert
self.options["command"] = f"force:source:convert -d {self.options['src_dir']}"

if self.options["resolve_sfdx_package_dirs"]:
path_string = self._resolve_sfdx_package_dirs()
if path_string:
self.options["command"] += f" --sourcepath {path_string}"

def _run_task(self):
src_dir = Path(self.options["src_dir"])
if src_dir.exists():
shutil.rmtree(src_dir)
super()._run_task()

def _resolve_sfdx_package_dirs(self):
path_string = ",./".join(
[
node["path"]
for node in self.project_config.sfdx_project_config.get(
"packageDirectories", []
)
]
)
if path_string:
return f"./{path_string}"
return ""
27 changes: 23 additions & 4 deletions cumulusci/tasks/tests/test_dx_convert_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,24 @@


@pytest.fixture
def project_config():
def sfdx_project_config():
dx_project_config = {
"packageDirectories": [
{"default": True, "path": "force-app"},
{"path": "libs/helper"},
{"path": "libs/mdapiservice"},
]
}
with mock.patch.object(
BaseProjectConfig,
"sfdx_project_config",
new_callable=mock.PropertyMock(return_value=dx_project_config),
) as sfdx_project_config:
yield sfdx_project_config


@pytest.fixture
def project_config(sfdx_project_config):
universal_config = UniversalConfig()
project_config = BaseProjectConfig(universal_config, config={"no_yaml": True})
project_config.project__name = "TestProject"
Expand All @@ -22,7 +39,9 @@ def project_config():

@pytest.fixture
def task_config():
return TaskConfig({"options": {"src_dir": "src"}})
return TaskConfig(
{"options": {"src_dir": "src", "resolve_sfdx_package_dirs": True}}
)


@pytest.fixture
Expand All @@ -41,7 +60,7 @@ def dx_convert_task(project_config, task_config):

@mock.patch("cumulusci.tasks.command.sarge")
def test_dx_convert_from(sarge, sarge_process, dx_convert_task):
"""Ensure that we clear out the `src/`"""
"""Ensure that we clear out the `src/` dir and that sfdx packageDirectories were resolved"""
with temporary_dir():
src_dir = Path("src")
src_dir.mkdir(exist_ok=True)
Expand All @@ -51,7 +70,7 @@ def test_dx_convert_from(sarge, sarge_process, dx_convert_task):

assert not src_dir.exists()
sarge.Command.assert_called_once_with(
"sfdx force:source:convert -d src",
"sfdx force:source:convert -d src --sourcepath ./force-app,./libs/helper,./libs/mdapiservice",
cwd=".",
env=ANY,
shell=True,
Expand Down