From 10e489836f473889e1814786196056b25e9cc457 Mon Sep 17 00:00:00 2001 From: Caleb Burks <19caleb95@gmail.com> Date: Mon, 6 May 2024 18:33:35 -0500 Subject: [PATCH] =?UTF-8?q?Ensure=20deployment=E2=80=99s=20dashboard=20URL?= =?UTF-8?q?=20is=20valid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/bin/vip-app-deploy.js | 14 +++++++++----- src/bin/vip-app-deploy.ts | 14 +++----------- src/lib/custom-deploy/custom-deploy.ts | 14 ++++---------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/__tests__/bin/vip-app-deploy.js b/__tests__/bin/vip-app-deploy.js index 04fcf9bdf..d6d2c085c 100644 --- a/__tests__/bin/vip-app-deploy.js +++ b/__tests__/bin/vip-app-deploy.js @@ -4,7 +4,6 @@ import { uploadImportSqlFileToS3 } from '../../src/lib/client-file-uploader'; import { validateFile, promptToContinue, - isSupportedApp, validateCustomDeployKey, } from '../../src/lib/custom-deploy/custom-deploy'; import { validateDeployFileExt, validateFilename } from '../../src/lib/validations/custom-deploy'; @@ -21,8 +20,15 @@ jest.mock( '../../src/lib/custom-deploy/custom-deploy', () => ( { validateFile: jest.fn(), renameFile: jest.fn(), promptToContinue: jest.fn().mockResolvedValue( true ), - isSupportedApp: jest.fn().mockResolvedValue( true ), - validateCustomDeployKey: jest.fn(), + validateCustomDeployKey: jest.fn().mockResolvedValue( { + success: true, + appId: 123, + envId: 124, + envType: 'develop', + envUniqueLabel: 'develop', + primaryDomainName: 'example.com/develop', + launched: false, + } ), } ) ); jest.mock( '../../src/lib/cli/command', () => { @@ -92,8 +98,6 @@ describe( 'vip-app-deploy', () => { it( 'should call expected functions', async () => { await appDeployCmd( args, opts ); - expect( isSupportedApp ).toHaveBeenCalledTimes( 1 ); - expect( validateCustomDeployKey ).toHaveBeenCalledTimes( 1 ); expect( validateFile ).toHaveBeenCalledTimes( 1 ); diff --git a/src/bin/vip-app-deploy.ts b/src/bin/vip-app-deploy.ts index a50601040..763c3b37d 100755 --- a/src/bin/vip-app-deploy.ts +++ b/src/bin/vip-app-deploy.ts @@ -85,24 +85,16 @@ export async function appDeployCmd( arg: string[] = [], opts: Record< string, un const [ fileName ] = arg; const fileMeta = await getFileMeta( fileName ); - const fileInputBasename = fileMeta.basename; debug( 'Options: ', opts ); debug( 'Args: ', arg ); debug( 'Validating custom deploy key...' ); const { appId, envId, ...validatedArgs } = await validateCustomDeployKey( app, env ); - console.log( { appId, envId, validatedArgs } ); + debug( 'Validated environment data: ', { appId, envId, validatedArgs } ); const track = trackEventWithEnv.bind( null, appId, envId ); - if ( ! validatedArgs.customDeploysEnabled ) { - await track( 'deploy_app_command_error', { error_type: 'unsupported-app' } ); - exit.withError( - 'The type of application you specified does not currently support custom deploys.' - ); - } - debug( 'Validating file...' ); await validateFile( appId, envId, fileMeta ); @@ -248,10 +240,10 @@ Processing the file for deployment to your environment... progressTracker.suffix = ''; progressTracker.print( { clearAfter: true } ); - const deploymentsUrl = `https://dashboard.wpvip.com/apps/${ appId }/${ validatedArgs.envType }/code/deployments`; + const deploymentsUrl = `https://dashboard.wpvip.com/apps/${ appId }/${ validatedArgs.envUniqueLabel }/code/deployments`; console.log( `\n✅ ${ chalk.bold( - chalk.underline( chalk.magenta( fileInputBasename ) ) + chalk.underline( chalk.magenta( fileMeta.basename ) ) ) } has been sent for deployment to ${ chalk.bold( chalk.blue( validatedArgs.primaryDomainName ) ) }. \nTo check deployment status, go to ${ chalk.bold( diff --git a/src/lib/custom-deploy/custom-deploy.ts b/src/lib/custom-deploy/custom-deploy.ts index 12107b399..595b2b155 100644 --- a/src/lib/custom-deploy/custom-deploy.ts +++ b/src/lib/custom-deploy/custom-deploy.ts @@ -1,12 +1,10 @@ import fs from 'fs'; import gql from 'graphql-tag'; -import { App } from '../../graphqlTypes'; import API from '../../lib/api'; import * as exit from '../../lib/cli/exit'; import { checkFileAccess, getFileSize, isFile, FileMeta } from '../../lib/client-file-uploader'; import { GB_IN_BYTES } from '../../lib/constants/file-size'; -import { WORDPRESS_SITE_TYPE_IDS } from '../../lib/constants/vipgo'; import { trackEventWithEnv } from '../../lib/tracker'; import { validateDeployFileExt, validateFilename } from '../../lib/validations/custom-deploy'; @@ -18,9 +16,9 @@ type CustomDeployInfo = { appId: number; envId: number; envType: string; + envUniqueLabel: string; primaryDomainName: string; launched: boolean; - customDeploysEnabled: boolean; }; type ValidateMutationPayload = { @@ -29,10 +27,6 @@ type ValidateMutationPayload = { } | null; }; -export function isSupportedApp( app: App ): boolean { - return WORDPRESS_SITE_TYPE_IDS.includes( app.typeId as number ); -} - export async function validateCustomDeployKey( app: string | number, env: string | number @@ -48,14 +42,14 @@ export async function validateCustomDeployKey( appId, envId, envType, + envUniqueLabel, primaryDomainName, - launched, - customDeploysEnabled + launched } } `; - const api = API(); + const api = API( { exitOnError: true } ); try { const result: ValidateMutationPayload = await api.mutate( { mutation: VALIDATE_CUSTOM_DEPLOY_ACCESS_MUTATION,