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

chore: refactor long fn out #830

Merged
merged 2 commits into from
Dec 5, 2023
Merged
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
21 changes: 8 additions & 13 deletions src/commands/project/retrieve/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,7 @@ const buildRetrieveAndDeleteTargets = async (
}
return result;
} else {
// check if we're retrieving metadata based on a pattern ...
let retrieveFromOrg: string | undefined;
if (flags.metadata) {
flags.metadata.some((mdEntry) => {
const mdName = mdEntry.split(':')[1];
if (mdName?.includes('*') && mdName?.length > 1 && !mdName?.includes('.*')) {
retrieveFromOrg = flags['target-org'].getUsername();
return true;
}
return false;
});
}
const retrieveFromOrg = flags.metadata?.some(isRegexMatch) ? flags['target-org'].getUsername() : undefined;

return {
componentSetFromNonDeletes: await ComponentSetBuilder.build({
Expand Down Expand Up @@ -412,7 +401,7 @@ const buildRetrieveAndDeleteTargets = async (
},
}
: {}),
org: retrieveFromOrg ? { username: retrieveFromOrg, exclude: [] } : undefined,
...(retrieveFromOrg ? { org: { username: retrieveFromOrg, exclude: [] } } : {}),
}),
};
}
Expand Down Expand Up @@ -449,3 +438,9 @@ const buildRetrieveOptions = async (
output: output ?? (await SfProject.resolve()).getDefaultPackage().fullPath,
}),
});

// check if we're retrieving metadata based on a pattern ...
const isRegexMatch = (mdEntry: string): boolean => {
const mdName = mdEntry.split(':')[1];
return mdName?.includes('*') && mdName?.length > 1 && !mdName?.includes('.*');
};