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

feat: ui for tracking #819

Merged
merged 7 commits into from
Nov 28, 2023
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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^5.0.3",
"@salesforce/source-deploy-retrieve": "^10.0.2",
"@salesforce/source-tracking": "^5.0.1",
"@salesforce/source-tracking": "^5.1.0",
"chalk": "^5.3.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/project/deploy/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
}

protected catch(error: Error | SfError): Promise<SfCommand.Error> {
if (error instanceof SourceConflictError) {
if (error instanceof SourceConflictError && error.data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ : should this check the length of error.data?

It's a required arg:
https://github.com/forcedotcom/source-tracking/pull/511/files#diff-76b31628824755a528610210e965f349b1c66c2a2ac1e880cf02b4d3b1020a17R76

but STL could do throw new SourceConflictError(${conflicts.length} conflicts detected, []) and make this pass.

if (!this.jsonEnabled()) {
writeConflictTable(error.data);
// set the message and add plugin-specific actions
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 @@ -267,7 +267,7 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
}

protected catch(error: Error | SfError): Promise<SfCommand.Error> {
if (!this.jsonEnabled() && error instanceof SourceConflictError) {
if (!this.jsonEnabled() && error instanceof SourceConflictError && error.data) {
writeConflictTable(error.data);
// set the message and add plugin-specific actions
return super.catch({
Expand Down
36 changes: 27 additions & 9 deletions src/utils/progressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*/
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { envVars as env, EnvironmentVariable, Messages } from '@salesforce/core';
import { envVars as env, EnvironmentVariable, Lifecycle, Messages } from '@salesforce/core';
import { MetadataApiDeploy, MetadataApiDeployStatus } from '@salesforce/source-deploy-retrieve';
import { Progress } from '@salesforce/sf-plugins-core';
import { SourceMemberPollingEvent } from '@salesforce/source-tracking';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const mdTransferMessages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'metadata.transfer');
Expand All @@ -20,21 +21,27 @@ const showBar = Boolean(
export class DeployProgress extends Progress {
private static OPTIONS = {
title: 'Status',
format: `%s: {status} ${showBar ? '| {bar} ' : ''}| {value}/{total} Components (Errors:{errorCount}) {testInfo}`,
format: `%s: {status} ${showBar ? '| {bar} ' : ''}| {value}/{total} Components{errorInfo}{testInfo}{trackingInfo}`,
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
linewrap: true,
// people really like to get text output in CI systems
// they won't get the "bar" but will get the remaining template bits this way
noTTYOutput: true,
};
private lifecycle = Lifecycle.getInstance();

public constructor(private deploy: MetadataApiDeploy, jsonEnabled = false) {
super(!jsonEnabled);
}

public start(): void {
super.start(0, { status: 'Waiting' }, DeployProgress.OPTIONS);
super.start(0, { status: 'Waiting', trackingInfo: '', testInfo: '' }, DeployProgress.OPTIONS);

// for sourceMember polling events
this.lifecycle.on<SourceMemberPollingEvent>('sourceMemberPollingEvent', (event: SourceMemberPollingEvent) =>
Promise.resolve(this.updateTrackingProgress(event))
);

this.deploy.onUpdate((data) => this.updateProgress(data));

Expand All @@ -52,21 +59,32 @@ export class DeployProgress extends Progress {
});
}

private updateTrackingProgress(data: SourceMemberPollingEvent): void {
const { remaining, original } = data;
this.update(0, {
status: 'Polling SourceMembers',
trackingInfo: ` | Tracking: ${original - remaining}/${original}`,
});
}

private updateProgress(data: MetadataApiDeployStatus): void {
// the numCompTot. isn't computed right away, wait to start until we know how many we have
const errorCount = data.numberComponentErrors ?? 0;
const testInfo = `| ${data.numberTestsCompleted ?? 0}/${data.numberTestsTotal ?? 0} Tests (Errors:${
data.numberTestErrors
})`;
const testInfo = data.numberTestsTotal
? ` | ${data.numberTestsCompleted ?? 0}/${data.numberTestsTotal ?? 0} Tests${
data.numberTestErrors ? `(Errors:${data.numberTestErrors})` : ''
}`
: '';
const errorInfo = data.numberComponentErrors > 0 ? ` | Errors: ${data.numberComponentErrors}` : '';

if (data.numberComponentsTotal) {
this.setTotal(data.numberComponentsTotal);
this.update(data.numberComponentsDeployed, {
errorCount,
errorInfo: data.numberComponentErrors > 0 ? ` | Errors: ${data.numberComponentErrors}` : '',
status: mdTransferMessages.getMessage(data.status),
testInfo,
});
} else {
this.update(0, { errorCount, testInfo, status: mdTransferMessages.getMessage(data.status) ?? 'Waiting' });
this.update(0, { errorInfo, testInfo, status: mdTransferMessages.getMessage(data.status) ?? 'Waiting' });
}
}
}
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1200,15 +1200,15 @@
shelljs "^0.8.4"
sinon "^10.0.0"

"@salesforce/source-tracking@^5.0.0", "@salesforce/source-tracking@^5.0.1":
version "5.0.1"
resolved "https://registry.yarnpkg.com/@salesforce/source-tracking/-/source-tracking-5.0.1.tgz#3b54b2ed8eee9c7bc8506ca9b1c0e88f961b435a"
integrity sha512-9ckOvid03/J5Lvq83aW7GIlLm9HtJ9NMLwalppDMvSd4T/lyWe8y4bxh4LKbqTC7fhzHMxet8yYTpzub0t+DPA==
"@salesforce/source-tracking@^5.0.0", "@salesforce/source-tracking@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@salesforce/source-tracking/-/source-tracking-5.1.0.tgz#c0d6336f0002a8c4abeae4ff3392de4adc169fd3"
integrity sha512-FTuDwLjERm1OR/xTy4a5oHThGOQvI0Rqs4ZqClQFUdgUKREcbxvO3UivSekgXA3az6nuSeNRmaTZGTC5gPjtKA==
dependencies:
"@oclif/core" "^3.10.8"
"@salesforce/core" "^6.1.3"
"@salesforce/core" "^6.2.0"
"@salesforce/kit" "^3.0.15"
"@salesforce/source-deploy-retrieve" "^10.0.0"
"@salesforce/source-deploy-retrieve" "^10.0.2"
"@salesforce/ts-types" "^2.0.9"
fast-xml-parser "^4.2.5"
graceful-fs "^4.2.11"
Expand Down
Loading