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

fix: always send deploy event and fix telemetry for mdapi deploy #797

Merged
merged 3 commits into from
Dec 13, 2022
Merged
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
2 changes: 2 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ export {
PackageOption,
PackageOptions,
RetrieveOptions,
DeployVersionData,
RetrieveVersionData,
} from './types';
34 changes: 23 additions & 11 deletions src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { basename, dirname, extname, join, posix, sep } from 'path';
import { format } from 'util';
import { isString } from '@salesforce/ts-types';
import { create as createArchive } from 'archiver';
import * as fs from 'graceful-fs';
Expand Down Expand Up @@ -353,14 +354,13 @@ export class MetadataApiDeploy extends MetadataTransfer<MetadataApiDeployStatus,
// SDR modifies what the mdapi expects by adding a rest param
const { rest, ...optionsWithoutRest } = this.options.apiOptions;

// Debug output for API version and source API version used for deploy
if (this.components?.apiVersion) {
const manifestVersion = this.components?.sourceApiVersion ?? apiVersion;
const webService = rest ? 'REST' : 'SOAP';

this.logger.debug(`Deploying metadata source in v${manifestVersion} shape using ${webService} v${apiVersion}`);
await LifecycleInstance.emit('apiVersionDeploy', { webService, manifestVersion, apiVersion });
}
// Event and Debug output for API version and source API version used for deploy
const manifestVersion = this.components?.sourceApiVersion;
const webService = rest ? 'REST' : 'SOAP';
const manifestMsg = manifestVersion ? ` in v${manifestVersion} shape` : '';
const debugMsg = format(`Deploying metadata source%s using ${webService} v${apiVersion}`, manifestMsg);
this.logger.debug(debugMsg);
await LifecycleInstance.emit('apiVersionDeploy', { webService, manifestVersion, apiVersion });

return this.isRestDeploy
? connection.metadata.deployRest(zipBuffer, optionsWithoutRest)
Expand All @@ -371,15 +371,27 @@ export class MetadataApiDeploy extends MetadataTransfer<MetadataApiDeployStatus,
protected async post(result: MetadataApiDeployStatus): Promise<DeployResult> {
const lifecycle = Lifecycle.getInstance();
try {
const connection = await this.getConnection();
const apiVersion = connection.getApiVersion();
// Creates an array of unique metadata types that were deployed, uses Set to avoid duplicates.
const listOfMetadataTypesDeployed = Array.from(new Set(this.options.components.map((c) => c.type.name)));
let listOfMetadataTypesDeployed: string[];
if (this.options.components) {
listOfMetadataTypesDeployed = Array.from(new Set(this.options.components.map((c) => c.type.name)));
} else {
// mdapi deploys don't have a ComponentSet, so using the result
const types = new Set<string>();
const successes = ensureArray(result.details?.componentSuccesses);
const failures = ensureArray(result.details?.componentFailures);
[...successes, ...failures].forEach((c) => c.componentType && types.add(c.componentType));
listOfMetadataTypesDeployed = Array.from(types);
}

void lifecycle.emitTelemetry({
eventName: 'metadata_api_deploy_result',
library: 'SDR',
status: result.status,
apiVersion: this.options.apiVersion,
sourceApiVersion: this.options.components?.sourceApiVersion,
apiVersion,
sourceApiVersion: this.components?.sourceApiVersion,
createdDate: result.createdDate,
startDate: result.startDate,
completedDate: result.completedDate,
Expand Down
11 changes: 11 additions & 0 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,14 @@ export interface ListMetadataQuery {
type: string;
folder?: string;
}

export interface DeployVersionData {
apiVersion: string;
manifestVersion: string | undefined;
webService: 'SOAP' | 'REST';
}

export interface RetrieveVersionData {
apiVersion: string;
manifestVersion: string;
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export {
PackageOption,
PackageOptions,
RetrieveOptions,
DeployVersionData,
RetrieveVersionData,
} from './client';
export {
MetadataConverter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"name": "componentSetCreate",
"duration": 664.222689999995
"duration": 681.3880480000225
},
{
"name": "sourceToMdapi",
"duration": 11668.923317000008
"duration": 10064.488008000015
},
{
"name": "sourceToZip",
"duration": 9924.087503000017
"duration": 9558.054119999986
},
{
"name": "mdapiToSource",
"duration": 8384.765007000009
"duration": 7265.46645700000
}
]