Skip to content

Commit 2c245e0

Browse files
committed
feat: add Vlocode command to deploy a recent validation
1 parent 33a340c commit 2c245e0

File tree

4 files changed

+79
-43
lines changed

4 files changed

+79
-43
lines changed

packages/vscode-extension/commands.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ vlocode.removeFromProfile:
240240
title: 'Salesforce: Remove from profiles'
241241
group: v_salesforce_profile
242242
menus: *profileCmdMenuConfig
243+
vlocode.deployRecentValidation:
244+
title: 'Salesforce: Deploy Recent Validation'
245+
group: v_salesforce
246+
when: config.vlocity.salesforce.enabled
247+
menus:
248+
- menu: commandPalette
243249

244250
# Data datapackExplorer commands
245251
vlocode.datapackExplorer.export:

packages/vscode-extension/src/commands/metadata/deployMetadataCommand.ts

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import open from 'open';
33

44
import { forEachAsyncParallel } from '@vlocode/util';
5-
import { DeployResult, DeployStatus, RetrieveDeltaStrategy, SalesforceDeployment, SalesforcePackage, SalesforcePackageBuilder, SalesforcePackageType } from '@vlocode/salesforce';
5+
import { DeployResult, RetrieveDeltaStrategy, SalesforceDeployment, SalesforcePackage, SalesforcePackageBuilder, SalesforcePackageType } from '@vlocode/salesforce';
66

77
import { VlocodeCommand } from '../../constants';
88
import { ActivityProgress } from '../../lib/vlocodeActivity';
@@ -17,6 +17,11 @@ import { container } from '@vlocode/core';
1717
@vscodeCommand(VlocodeCommand.deployDeltaMetadata, { focusLog: true, showProductionWarning: true, executeParams: [ VlocodeCommand.deployDeltaMetadata ] })
1818
export default class DeployMetadataCommand extends MetadataCommand {
1919

20+
protected deployStatusLabels = {
21+
'InProgress': 'In Progress',
22+
'SucceededPartial': 'Partially Deployed'
23+
};
24+
2025
/**
2126
* In order to prevent double deployment keep a list of pending deploy ops
2227
*/
@@ -132,12 +137,15 @@ export default class DeployMetadataCommand extends MetadataCommand {
132137
if (!deployPackage) {
133138
break;
134139
}
140+
const deployment = new SalesforceDeployment(deployPackage);
135141
await this.vlocode.withActivity({
136142
progressTitle: `Deploy ${deployPackage.componentsDescription}`,
137143
location: vscode.ProgressLocation.Notification,
138144
propagateExceptions: false,
139145
cancellable: true
140-
}, this.getDeploymentActivity(deployPackage));
146+
}, async (progress: ActivityProgress, token: vscode.CancellationToken) => {
147+
await this.monitorDeployment(deployment, progress, token);
148+
});
141149
}
142150
} finally {
143151
this.deploymentRunning = false;
@@ -146,51 +154,39 @@ export default class DeployMetadataCommand extends MetadataCommand {
146154
}, 250);
147155
}
148156

149-
private getDeploymentActivity(sfPackage: SalesforcePackage) {
150-
return async (progress: ActivityProgress, token: vscode.CancellationToken) => {
151-
progress.report({ message: `scheduling` });
152-
153-
// start deployment
154-
const deployment = new SalesforceDeployment(sfPackage);
155-
const progressReporter = deployment.on('progress', result => {
156-
if (deployment.isServerSideCancelled) {
157-
progress.report({ message: 'Server-side cancellation requested' });
158-
progressReporter.dispose();
159-
} else {
160-
progress.report({
161-
message: `${this.getStatusLabel(result.status)} ${result.total ? `${result.deployed}/${result.total}` : ''}`,
162-
progress: result.deployed,
163-
total: result.total
164-
});
165-
}
166-
});
157+
protected async monitorDeployment(deployment: SalesforceDeployment, progress: ActivityProgress, token: vscode.CancellationToken) {
158+
progress.report({ message: `scheduling` });
167159

168-
token.onCancellationRequested(() => {
169-
progress.report({ message: 'Cancellation in progress' });
160+
// start deployment
161+
const progressReporter = deployment.on('progress', result => {
162+
if (deployment.isServerSideCancelled) {
163+
progress.report({ message: 'Server-side cancellation requested' });
170164
progressReporter.dispose();
171-
deployment.cancel();
172-
});
173-
174-
await deployment.start({ ignoreWarnings: true });
175-
this.logger.info(`Deployment details: ${await this.vlocode.salesforceService.getPageUrl(deployment.setupUrl)}`);
176-
const result = await deployment.getResult();
177-
178-
if (deployment.isCancelled) {
179-
return;
165+
} else {
166+
progress.report({
167+
message: `${this.deployStatusLabels[result.status] ?? result.status} ${result.total ? `${result.deployed}/${result.total}` : ''}`,
168+
progress: result.deployed,
169+
total: result.total
170+
});
180171
}
172+
});
181173

182-
this.outputDeployResult(sfPackage.components(), result);
183-
return this.onDeploymentComplete(deployment, result);
184-
};
185-
}
174+
token.onCancellationRequested(() => {
175+
progress.report({ message: 'Cancellation in progress' });
176+
progressReporter.dispose();
177+
deployment.cancel();
178+
});
179+
180+
await deployment.start({ ignoreWarnings: true });
181+
this.logger.info(`Deployment details: ${await this.vlocode.salesforceService.getPageUrl(deployment.setupUrl)}`);
182+
const result = await deployment.getResult();
186183

187-
private getStatusLabel(status: DeployStatus) {
188-
if (status === 'InProgress') {
189-
return 'In Progress';
190-
} else if (status === 'SucceededPartial') {
191-
return 'Partially Deployed';
184+
if (deployment.isCancelled) {
185+
return;
192186
}
193-
return status;
187+
188+
this.outputDeployResult(deployment.deploymentPackage.components(), result);
189+
return this.onDeploymentComplete(deployment, result);
194190
}
195191

196192
private onDeploymentComplete(deployment: SalesforceDeployment, result: DeployResult) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as vscode from 'vscode';
2+
3+
import { VlocodeCommand } from '../../constants';
4+
import { ActivityProgress } from '../../lib/vlocodeActivity';
5+
import { vscodeCommand } from '../../lib/commandRouter';
6+
import { SalesforceDeployment } from '@vlocode/salesforce';
7+
import DeployMetadataCommand from './deployMetadataCommand';
8+
9+
@vscodeCommand(VlocodeCommand.deployRecentValidation, {
10+
focusLog: true,
11+
showProductionWarning: true,
12+
executeParams: [ VlocodeCommand.deployRecentValidation ]
13+
})
14+
export default class DeployRecentValidationCommand extends DeployMetadataCommand {
15+
16+
public async execute(): Promise<void> {
17+
// Retrieve recent deployments
18+
const connection = await this.salesforce.getJsForceConnection();
19+
const recentValidation = await connection.metadata.getDeployableRecentValidation();
20+
if (!recentValidation) {
21+
vscode.window.showWarningMessage('No deployable recent validation found.');
22+
return;
23+
}
24+
25+
await this.vlocode.withActivity({
26+
progressTitle: `Deploy Recent Validation: ${recentValidation.id}`,
27+
location: vscode.ProgressLocation.Notification,
28+
cancellable: true
29+
}, async (progress: ActivityProgress, token: vscode.CancellationToken) => {
30+
const result = await connection.metadata.deployRecentValidation(recentValidation.id);
31+
const deployment = SalesforceDeployment.fromId(result.id);
32+
await this.monitorDeployment(deployment, progress, token);
33+
});
34+
}
35+
}

packages/vscode-extension/src/constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
/**
42
* Default constants used in this extensipn
53
*/
@@ -73,4 +71,5 @@ export enum VlocodeCommand {
7371
omniScriptDeployLwc = 'vlocode.omniScript.deployLwc',
7472
omniScriptActivate = 'vlocode.omniScript.activate',
7573
apexToggleCoverage = 'vlocode.apex.toggleCoverage',
74+
deployRecentValidation = 'vlocode.deployRecentValidation',
7675
}

0 commit comments

Comments
 (0)