Skip to content

Commit

Permalink
feat(analytics): add analytics hook on org:config commands (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
olamothe authored Jul 13, 2021
1 parent f7cf23d commit d753b97
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/cli/src/commands/org/config/monitor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {ResourceSnapshotsReportModel} from '@coveord/platform-client';
import {flags, Command} from '@oclif/command';
import {cli} from 'cli-ux';
import {
buildAnalyticsFailureHook,
buildAnalyticsSuccessHook,
} from '../../../hooks/analytics/analytics';
import {Config} from '../../../lib/config/config';
import {
IsAuthenticated,
Expand Down Expand Up @@ -41,6 +45,16 @@ export default class Monitor extends Command {
this.printHeader(snapshot.id);

await this.monitorSnapshot(snapshot);
this.config.runHook('analytics', buildAnalyticsSuccessHook(this, flags));
}

public async catch(err?: Error) {
const {flags} = this.parse(Monitor);
await this.config.runHook(
'analytics',
buildAnalyticsFailureHook(this, flags, err)
);
throw err;
}

private async monitorSnapshot(snapshot: Snapshot) {
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/src/commands/org/config/preview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {DryRunOptions} from '@coveord/platform-client';
import {Command, flags} from '@oclif/command';
import {cwd} from 'process';
import {
buildAnalyticsFailureHook,
buildAnalyticsSuccessHook,
} from '../../../hooks/analytics/analytics';
import {Config} from '../../../lib/config/config';
import {
IsAuthenticated,
Expand Down Expand Up @@ -57,6 +61,17 @@ export default class Preview extends Command {
}

project.deleteTemporaryZipFile();

this.config.runHook('analytics', buildAnalyticsSuccessHook(this, flags));
}

public async catch(err?: Error) {
const {flags} = this.parse(Preview);
await this.config.runHook(
'analytics',
buildAnalyticsFailureHook(this, flags, err)
);
throw err;
}

private async handleReportWithErrors(snapshot: Snapshot) {
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/src/commands/org/config/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
import {Config} from '../../../lib/config/config';
import {DryRunOptions} from '@coveord/platform-client';
import {cwd} from 'process';
import {
buildAnalyticsFailureHook,
buildAnalyticsSuccessHook,
} from '../../../hooks/analytics/analytics';

export default class Push extends Command {
public static description =
Expand Down Expand Up @@ -71,6 +75,17 @@ export default class Push extends Command {
}

project.deleteTemporaryZipFile();

this.config.runHook('analytics', buildAnalyticsSuccessHook(this, flags));
}

public async catch(err?: Error) {
const {flags} = this.parse(Push);
await this.config.runHook(
'analytics',
buildAnalyticsFailureHook(this, flags, err)
);
throw err;
}

private async handleValidReport(
Expand Down

0 comments on commit d753b97

Please sign in to comment.