Skip to content

Commit

Permalink
checkpoint for using new endpoint before promotion/migration
Browse files Browse the repository at this point in the history
  • Loading branch information
rnegron committed Jan 16, 2025
1 parent 44d599e commit a80396d
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/cli/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ You cannot pass both `--user` and `--account`.
**Flags**
* `--user` | Migrates all of a users' Private Zaps within all accounts for which the specified user is a member
* `--account` | Migrates all of a users' Zaps, Private & Shared, within all accounts for which the specified user is a member
* `-y, --yes` | Automatically answer "yes" to any prompts. Useful if you want to avoid interactive prompts to run this command in CI.
* `-d, --debug` | Show extra debugging output.

**Examples**
Expand Down
60 changes: 60 additions & 0 deletions packages/cli/src/oclif/commands/migrate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const _ = require('lodash');
const { Args, Flags } = require('@oclif/core');

const BaseCommand = require('../ZapierBaseCommand');
Expand All @@ -6,6 +7,41 @@ const { callAPI } = require('../../utils/api');
const { buildFlags } = require('../buildFlags');

class MigrateCommand extends BaseCommand {
async run_migration_pre_checks(app, requestBody) {
const assumeYes = 'yes' in this.flags;
const url = `/apps/${app.id}/migrations/pre-checks`;

try {
await callAPI(
url,
{
method: 'POST',
body: requestBody,
},
true,
);
} catch (response) {
// 409 from the backend specifically signals pre-checks failed
if (response.status === 409) {
const softCheckErrors = _.get(response, 'json.errors');

this.log('Non-blocking checks prior to migration returned warnings:');
this.log(softCheckErrors);
this.log();

const shouldContinuePreChecks =
assumeYes ||
(await this.confirm(
'Would you like to continue with the migration regardless?',
));

if (!shouldContinuePreChecks) {
this.error('Cancelled migration.');
}
}
}
}

async perform() {
const percent = this.args.percent;
if (isNaN(percent) || percent < 1 || percent > 100) {
Expand All @@ -14,6 +50,7 @@ class MigrateCommand extends BaseCommand {

const account = this.flags.account;
const user = this.flags.user;

const fromVersion = this.args.fromVersion;
const toVersion = this.args.toVersion;
let flagType;
Expand Down Expand Up @@ -67,6 +104,11 @@ class MigrateCommand extends BaseCommand {
email_type: flagType,
},
};

this.startSpinner(`Running pre-checks before migration`);
await this.run_migration_pre_checks(app, body);
this.stopSpinner();

if (user || account) {
this.startSpinner(
`Starting migration from ${fromVersion} to ${toVersion} for ${
Expand All @@ -86,6 +128,19 @@ class MigrateCommand extends BaseCommand {

try {
await callAPI(url, { method: 'POST', body });
} catch (errorResponse) {
// Verify if this error is something we can retry with confirmation
const requiresConfirmation = errorResponse.status === 409;
if (requiresConfirmation) {
this.stopSpinner();

this.log('');

this.log();
} else {
// Unhandled error
throw errorResponse;
}
} finally {
this.stopSpinner();
}
Expand All @@ -106,6 +161,11 @@ MigrateCommand.flags = buildFlags({
description:
"Migrates all of a users' Zaps, Private & Shared, within all accounts for which the specified user is a member",
}),
yes: Flags.boolean({
char: 'y',
description:
'Automatically answer "yes" to any prompts. Useful if you want to avoid interactive prompts to run this command in CI.',
}),
},
});

Expand Down
52 changes: 47 additions & 5 deletions packages/cli/src/oclif/commands/promote.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,43 @@ const hasAppChangeType = (metadata, changeType) => {
};

class PromoteCommand extends BaseCommand {
async run_promotion_pre_checks(app, requestBody) {
const assumeYes = 'yes' in this.flags;
const url = `/apps/${app.id}/migrations/pre-checks`;

try {
await callAPI(
url,
{
method: 'POST',
body: requestBody,
},
true,
);
} catch (response) {
// 409 from the backend specifically signals pre-checks failed
if (response.status === 409) {
const softCheckErrors = _.get(response, 'json.errors');

this.log(
'Non-blocking checks prior to promoting the integration returned warnings:',
);
this.log(softCheckErrors);
this.log();

const shouldContinuePreChecks =
assumeYes ||
(await this.confirm(
'Would you like to continue with the promotion process regardless?',
));

if (!shouldContinuePreChecks) {
this.error('Cancelled promote.');
}
}
}
}

async perform() {
const app = await this.getWritableApp();

Expand All @@ -51,7 +88,8 @@ class PromoteCommand extends BaseCommand {
const version = this.args.version;
const assumeYes = 'yes' in this.flags;

let shouldContinue;
let shouldContinueChangelog;

const { changelog, appMetadata, issueMetadata } =
await getVersionChangelog(version);

Expand Down Expand Up @@ -133,15 +171,15 @@ ${metadataPromptHelper}`);
this.log();
/* eslint-enable camelcase */

shouldContinue =
shouldContinueChangelog =
assumeYes ||
(await this.confirm(
'Would you like to continue promoting with this changelog?',
));
}

if (!shouldContinue) {
this.error('Cancelled promote.');
if (!shouldContinueChangelog) {
this.error('Cancelled promote.');
}
}

this.log(
Expand All @@ -167,6 +205,10 @@ ${metadataPromptHelper}`);
},
};

this.startSpinner(`Running pre-checks before promoting ${version}`);
await this.run_promotion_pre_checks(app, body);
this.stopSpinner();

this.startSpinner(`Verifying and promoting ${version}`);

const url = `/apps/${app.id}/migrations`;
Expand Down

0 comments on commit a80396d

Please sign in to comment.