Skip to content

Commit

Permalink
feat(cli): do not propose to apply a snapshot with no changes (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lakhdar authored Jul 2, 2021
1 parent f50b690 commit f2ec64e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 11 additions & 3 deletions packages/cli/src/commands/org/config/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import {Snapshot} from '../../../lib/snapshot/snapshot';
import {red, green, bold} from 'chalk';
import SnapshotBase from './orgConfigBase';
import {SnapshotReporter} from '../../../lib/snapshot/snapshotReporter';
import dedent from 'ts-dedent';

export interface CustomFile extends ReadStream {
type?: string;
Expand Down Expand Up @@ -39,15 +41,21 @@ export default class Push extends SnapshotBase {
await snapshot.preview();
}
if (reporter.isSuccessReport()) {
await this.handleValidReport(snapshot);
await this.handleValidReport(reporter, snapshot);
await snapshot.delete();
}

project.deleteTemporaryZipFile();
}

private async handleValidReport(snapshot: Snapshot) {
// TODO: CDX-390 return different message if no resources changes
private async handleValidReport(
reporter: SnapshotReporter,
snapshot: Snapshot
) {
if (!reporter.hasChangedResources()) {
return;
}

const {flags} = this.parse(Push);
const canBeApplied = flags.skipPreview || (await this.askForConfirmation());

Expand Down
10 changes: 9 additions & 1 deletion packages/cli/src/lib/snapshot/reportViewer/reportViewer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {cli} from 'cli-ux';
import {red, italic} from 'chalk';
import {red, italic, green} from 'chalk';
import {ReportViewerSection} from './reportViewerSection';
import {ReportViewerStyles} from './reportViewerStyles';
import {SnapshotReporter} from '../snapshotReporter';
import {
ReportViewerOperationName,
ReportViewerResourceReportModel,
} from './reportViewerDataModels';
import dedent from 'ts-dedent';

export class ReportViewer {
public static defaultOperationsToDisplay: ReportViewerOperationName[] = [
Expand Down Expand Up @@ -36,6 +37,13 @@ export class ReportViewer {
if (!this.reporter.isSuccessReport()) {
this.handleReportErrors();
}

if (!this.reporter.hasChangedResources()) {
cli.log(dedent`${green('No resources to change')}.
The target organization already matches the configuration.`);
return;
}
}

private printTable() {
Expand Down

0 comments on commit f2ec64e

Please sign in to comment.