Skip to content

Commit

Permalink
Merge pull request #769 from salesforcecli/sm/api-version-on-mdapi-de…
Browse files Browse the repository at this point in the history
…ploy

fix: api version for mdapi deploys
  • Loading branch information
shetzel authored Oct 2, 2023
2 parents 94bcf1b + 77671bf commit 98edbd4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions messages/deploy.metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Overrides your default org.

# flags.metadata.summary

Metadata component names to deploy. Wildcards ( * ) supported as long as you use quotes, such as 'ApexClass:MyClass*'
Metadata component names to deploy. Wildcards ( `*` ) supported as long as you use quotes, such as `ApexClass:MyClass*`

# flags.test-level.summary

Expand Down Expand Up @@ -246,4 +246,4 @@ The `pushPackageDirectoriesSequentially` property is not respected by this comma

# apiVersionMsgDetailed

%s v%s metadata to %s using the v%s %s API.
%s %s metadata to %s using the v%s %s API.
2 changes: 1 addition & 1 deletion src/commands/project/deploy/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
this.log(
messages.getMessage('apiVersionMsgDetailed', [
action,
apiData.manifestVersion,
flags['metadata-dir'] ? '<version specified in manifest>' : `v${apiData.manifestVersion}`,
username,
apiData.apiVersion,
apiData.webService,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/project/deploy/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
this.log(
deployMessages.getMessage('apiVersionMsgDetailed', [
'Validating Deployment of',
apiData.manifestVersion,
flags['metadata-dir'] ? '<version specified in manifest>' : `v${apiData.manifestVersion}`,
username,
apiData.apiVersion,
apiData.webService,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/project/retrieve/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
this.log(
messages.getMessage('apiVersionMsgDetailed', [
'Retrieving',
apiData.manifestVersion,
`v${apiData.manifestVersion}`,
flags['target-org'].getUsername(),
apiData.apiVersion,
])
Expand Down
25 changes: 15 additions & 10 deletions src/utils/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ComponentSetBuilder,
DeployResult,
MetadataApiDeploy,
MetadataApiDeployOptions,
RequestStatus,
} from '@salesforce/source-deploy-retrieve';
import { SourceTracking } from '@salesforce/source-tracking';
Expand Down Expand Up @@ -119,21 +120,14 @@ export async function executeDeploy(
id?: string,
throwOnEmpty = false
): Promise<{ deploy?: MetadataApiDeploy; componentSet?: ComponentSet }> {
const apiOptions = {
checkOnly: opts['dry-run'] ?? false,
ignoreWarnings: opts['ignore-warnings'] ?? false,
rest: opts.api === 'REST',
rollbackOnError: !opts['ignore-errors'] || false,
...(opts.tests ? { runTests: opts.tests } : {}),
...(opts['test-level'] ? { testLevel: opts['test-level'] } : {}),
purgeOnDelete: opts['purge-on-delete'] ?? false,
};
const apiOptions = buildApiOptions(opts);

let deploy: MetadataApiDeploy | undefined;
let componentSet: ComponentSet | undefined;

const org = await Org.create({ aliasOrUsername: opts['target-org'] });
const usernameOrConnection = org.getConnection();
// for mdapi deploys, use the passed in api-version.
const usernameOrConnection = org.getConnection(opts['metadata-dir'] ? opts['api-version'] : undefined);

if (opts['metadata-dir']) {
if (id) {
Expand Down Expand Up @@ -233,3 +227,14 @@ export const isNotResumable = (status?: RequestStatus): boolean =>
[RequestStatus.Succeeded, RequestStatus.Failed, RequestStatus.SucceededPartial, RequestStatus.Canceled].includes(
status
);

/** apply some defaults to the DeployOptions object */
const buildApiOptions = (opts: Partial<DeployOptions>): MetadataApiDeployOptions['apiOptions'] => ({
checkOnly: opts['dry-run'] ?? false,
ignoreWarnings: opts['ignore-warnings'] ?? false,
rest: opts.api === 'REST',
rollbackOnError: !opts['ignore-errors'] || false,
...(opts.tests ? { runTests: opts.tests } : {}),
...(opts['test-level'] ? { testLevel: opts['test-level'] } : {}),
purgeOnDelete: opts['purge-on-delete'] ?? false,
});

0 comments on commit 98edbd4

Please sign in to comment.