Skip to content

Commit

Permalink
Made requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-balachander committed Dec 19, 2023
1 parent 7c0b3ae commit c6fb60f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
59 changes: 32 additions & 27 deletions cumulusci/tasks/salesforce/sourcetracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,27 +132,6 @@ def _filter_changes(self, changes):
filtered.append(change)
return filtered, ignored

def _filter_changes_with_profiles(self, changes):
"""Filter changes using the include/exclude options along with profiles"""
filtered = []
ignored = []
profiles = []
for change in changes:
mdtype = change["MemberType"]
name = change["MemberName"]
full_name = f"{mdtype}: {name}"
if (
self._include
and not any(re.search(s, full_name) for s in self._include)
) or any(re.search(s, full_name) for s in self._exclude):
ignored.append(change)
else:
if mdtype == "Profile":
profiles.append(name)
else:
filtered.append(change)
return filtered, ignored, profiles

def _store_snapshot(self, changes):
"""Update the snapshot of which component revisions have been retrieved."""
for change in changes:
Expand Down Expand Up @@ -189,6 +168,12 @@ def _reset_sfdx_snapshot(self):
+ " Defaults to project__package__api_version"
)
}
retrieve_changes_task_options["ret_profile"] = {
"description": (
"If set to True, will use RetrieveProfile to retrieve"
+ " the complete profile. Default is set to False"
)
}
retrieve_changes_task_options["namespace_tokenize"] = BaseRetrieveMetadata.task_options[
"namespace_tokenize"
]
Expand Down Expand Up @@ -216,16 +201,29 @@ def _write_manifest(changes, path, api_version):
f.write(package_xml)


def separate_profiles(components):
"""Separate the profiles from components"""
updated_components = []
profiles = []
for comp in components:
if comp["MemberType"] == "Profile":
profiles.append(comp["MemberName"])
else:
updated_components.append(comp)

return updated_components, profiles


def retrieve_components(
components,
profiles,
org_config,
project_config,
target: str,
md_format: bool,
extra_package_xml_opts: dict,
namespace_tokenize: str,
api_version: str,
ret_profile: bool = False,
):
"""Retrieve specified components from an org into a target folder.
Expand All @@ -239,6 +237,7 @@ def retrieve_components(
"""

target = os.path.realpath(target)
profiles = []
with contextlib.ExitStack() as stack:
if md_format:
# Create target if it doesn't exist
Expand Down Expand Up @@ -271,6 +270,11 @@ def retrieve_components(
check_return=True,
)

# If ret_profile is True, separate the profiles from
# components to retrieve complete profile
if ret_profile:
components, profiles = separate_profiles(components)

if components:
# Construct package.xml with components to retrieve, in its own tempdir
package_xml_path = stack.enter_context(temporary_dir(chdir=False))
Expand Down Expand Up @@ -343,6 +347,9 @@ class RetrieveChanges(ListChanges, BaseSalesforceApiTask):
def _init_options(self, kwargs):
super(RetrieveChanges, self)._init_options(kwargs)
self.options["snapshot"] = process_bool_arg(kwargs.get("snapshot", True))
self.options["ret_profile"] = process_bool_arg(
self.options.get("ret_profile", False)
)

# Check which directories are configured as dx packages
package_directories = []
Expand Down Expand Up @@ -382,14 +389,12 @@ def _run_task(self):
self._load_snapshot()
self.logger.info("Querying Salesforce for changed source members")
changes = self._get_changes()
filtered, ignored, profiles = self._filter_changes_with_profiles(changes)
if not filtered and not profiles:
filtered, ignored = self._filter_changes(changes)
if not filtered:
self.logger.info("No changes to retrieve")
return
for change in filtered:
self.logger.info("{MemberType}: {MemberName}".format(**change))
for profile in profiles:
self.logger.info(f"Profile: {profile}")

target = os.path.realpath(self.options["path"])
package_xml_opts = {}
Expand All @@ -404,14 +409,14 @@ def _run_task(self):

retrieve_components(
filtered,
profiles,
self.org_config,
self.project_config,
target,
md_format=self.md_format,
namespace_tokenize=self.options.get("namespace_tokenize"),
api_version=self.options["api_version"],
extra_package_xml_opts=package_xml_opts,
ret_profile=self.options["ret_profile"],
)

if self.options["snapshot"]:
Expand Down
3 changes: 2 additions & 1 deletion cumulusci/tasks/salesforce/tests/test_sourcetracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def test_run_task(self, sfdx, create_task_fixture):

with temporary_dir():
task = create_task_fixture(
RetrieveChanges, {"include": "Test", "namespace_tokenize": "ns"}
RetrieveChanges,
{"include": "Test", "namespace_tokenize": "ns", "ret_profile": True},
)
task._init_task()
task.tooling = mock.Mock()
Expand Down
Empty file added src/package.xml
Empty file.

0 comments on commit c6fb60f

Please sign in to comment.