diff --git a/messages/deploy.metadata.report.md b/messages/deploy.metadata.report.md index 427385ab..9833e0e0 100644 --- a/messages/deploy.metadata.report.md +++ b/messages/deploy.metadata.report.md @@ -6,9 +6,9 @@ Check or poll for the status of a deploy operation. Deploy operations include standard deploys, quick deploys, deploy validations, and deploy cancellations. -Run this command by either passing it a job ID or specifying the --use-most-recent flag to use the job ID of the most recent deploy operation. If you specify the --wait flag, the command polls for the status every second until the timeout of --wait minutes. If you don't specify the --wait flag, the command simply checks and displays the status of the deploy; the command doesn't poll for the status. +Run this command by either passing it a job ID or specifying the --use-most-recent flag to use the job ID of the most recent deploy operation. If you specify the --wait flag, the command polls for the status every second until the timeout of --wait minutes. If you don't specify the --wait flag, the command simply checks and displays the status of the deploy; the command doesn't poll for the status. -You typically don't specify the --target-org flag because the cached job already references the org to which you deployed. But if you run this command on a computer different than the one from which you deployed, then you must specify the --target-org and it must point to the same org. +You typically don't specify the --target-org flag because the cached job already references the org to which you deployed. But if you run this command on a computer different than the one from which you deployed, then you must specify the --target-org and it must point to the same org. This command doesn't update source tracking information. @@ -56,3 +56,7 @@ Output JUnit test results. # flags.results-dir.summary Output directory for code coverage and JUnit results; defaults to the deploy ID. + +# noOrgError + +No environment found. Use -o or --target-org to specify an environment diff --git a/src/commands/project/deploy/report.ts b/src/commands/project/deploy/report.ts index cde43b68..4b914c08 100644 --- a/src/commands/project/deploy/report.ts +++ b/src/commands/project/deploy/report.ts @@ -7,7 +7,7 @@ import { Messages, Org, SfProject } from '@salesforce/core'; import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; -import { ComponentSet, DeployResult, MetadataApiDeploy } from '@salesforce/source-deploy-retrieve'; +import { ComponentSet, DeployResult, MetadataApiDeploy, RequestStatus } from '@salesforce/source-deploy-retrieve'; import { buildComponentSet } from '../../../utils/deploy.js'; import { DeployProgress } from '../../../utils/progressBar.js'; import { DeployCache } from '../../../utils/deployCache.js'; @@ -79,10 +79,15 @@ export default class DeployMetadataReport extends SfCommand { ? await Org.create({ aliasOrUsername: deployOpts['target-org'] }) : flags['target-org']; + if (!org) { + // if we don't find an org from flags, config, or the cache, throw an error + throw messages.createError('noOrgError'); + } + // if we're using mdapi we won't have a component set let componentSet = new ComponentSet(); if (!deployOpts?.isMdapi) { - if (!cache.maybeGet(jobId)) { + if (!deployOpts) { // If the cache file isn't there, use the project package directories for the CompSet try { this.project = await SfProject.resolve(); @@ -91,7 +96,8 @@ export default class DeployMetadataReport extends SfCommand { } catch (err) { // ignore the error. this was just to get improved command output. } - } else { + } else if (deployOpts.status !== RequestStatus.Succeeded) { + // if it's succeeded, the deployOpts can't be used to build a CS - nor do we need one componentSet = await buildComponentSet({ ...deployOpts, wait }); } } diff --git a/test/nuts/deploy/report.nut.ts b/test/nuts/deploy/report.nut.ts new file mode 100644 index 00000000..41382764 --- /dev/null +++ b/test/nuts/deploy/report.nut.ts @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +import * as path from 'node:path'; +import { assert, expect } from 'chai'; +import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; +import { DeployResultJson } from '../../../src/utils/types.js'; + +describe('project deploy report', () => { + let testkit: TestSession; + + before(async () => { + testkit = await TestSession.create({ + project: { gitClone: 'https://github.com/trailheadapps/dreamhouse-lwc' }, + scratchOrgs: [{ setDefault: true, config: path.join('config', 'project-scratch-def.json') }], + devhubAuthStrategy: 'AUTO', + }); + execCmd('project deploy start', { + ensureExitCode: 0, + }); + }); + + after(async () => { + await testkit?.clean(); + }); + + it('can validate / deploy quick / report', () => { + const validate = execCmd('project deploy validate --metadata ApexClass --json', { + ensureExitCode: 0, + }).jsonOutput; + assert(validate); + expect(validate.result.checkOnly).to.be.true; + expect(validate.result.done).to.be.true; + expect(validate.result.success).to.be.true; + const validateId = validate.result.id; + + const quick = execCmd(`project deploy quick --job-id ${validateId} --json`, { + ensureExitCode: 0, + }).jsonOutput; + assert(quick); + expect(quick.result.checkOnly).to.be.false; + expect(quick.result.done).to.be.true; + expect(quick.result.success).to.be.true; + const quickId = quick.result.id; + + const report = execCmd(`project deploy report --job-id ${quickId} --json`, { + ensureExitCode: 0, + }).jsonOutput; + assert(report); + expect(report.result.checkOnly).to.be.false; + expect(report.result.done).to.be.true; + expect(report.result.success).to.be.true; + }); +});