Skip to content

Commit

Permalink
Ensure deployment’s dashboard URL is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
WPprodigy committed May 6, 2024
1 parent de9bf64 commit 10e4898
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
14 changes: 9 additions & 5 deletions __tests__/bin/vip-app-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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 );
Expand Down
14 changes: 3 additions & 11 deletions src/bin/vip-app-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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(
Expand Down
14 changes: 4 additions & 10 deletions src/lib/custom-deploy/custom-deploy.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -18,9 +16,9 @@ type CustomDeployInfo = {
appId: number;
envId: number;
envType: string;
envUniqueLabel: string;
primaryDomainName: string;
launched: boolean;
customDeploysEnabled: boolean;
};

type ValidateMutationPayload = {
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 10e4898

Please sign in to comment.