generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 20
fix: add mdapi:deploy:cancel command, refactor base classes to support MDAPI and SOURCE stash keys #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix: add mdapi:deploy:cancel command, refactor base classes to support MDAPI and SOURCE stash keys #301
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "description": "cancel a metadata deployment \n Use this command to cancel a specified asynchronous metadata deployment. You can also specify a wait time (in minutes) to check for updates to the canceled deploy status.", | ||
| "longDescription": "Cancels an asynchronous metadata deployment.", | ||
| "flags": { | ||
| "wait": "wait time for command to finish in minutes", | ||
| "waitLong": "Number of minutes to wait for the command to complete and display results to the terminal window. If the command continues to run after the wait period, the CLI returns control of the terminal window to you. The default is 33 minutes.", | ||
| "jobid": "job ID of the deployment you want to cancel; defaults to your most recent CLI deployment if not specified" | ||
| }, | ||
|
|
||
| "examples": [ | ||
| "Deploy a directory of files to the org", | ||
| " $ sfdx force:mdapi:deploy -d <directory>", | ||
| "Now cancel this deployment and wait two minutes", | ||
| " $ sfdx force:mdapi:deploy:cancel -w 2", | ||
| "If you have multiple deployments in progress and want to cancel a specific one, specify the job ID", | ||
| " $ sfdx force:mdapi:deploy:cancel -i <jobid>", | ||
| "Check the status of the cancel job", | ||
| " $ sfdx force:mdapi:deploy:report" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Copyright (c) 2020, 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 os from 'os'; | ||
| import { flags, FlagsConfig } from '@salesforce/command'; | ||
| import { Messages, SfdxError } from '@salesforce/core'; | ||
| import { Duration } from '@salesforce/kit'; | ||
| import { RequestStatus } from '@salesforce/source-deploy-retrieve'; | ||
| import { DeployCommand } from '../../../../deployCommand'; | ||
| import { | ||
| DeployCancelCommandResult, | ||
| DeployCancelResultFormatter, | ||
| } from '../../../../formatters/deployCancelResultFormatter'; | ||
|
|
||
| Messages.importMessagesDirectory(__dirname); | ||
| const messages = Messages.loadMessages('@salesforce/plugin-source', 'md.cancel'); | ||
|
|
||
| export class Cancel extends DeployCommand { | ||
| public static readonly description = messages.getMessage('description'); | ||
| public static readonly examples = messages.getMessage('examples').split(os.EOL); | ||
| public static readonly requiresUsername = true; | ||
| public static readonly flagsConfig: FlagsConfig = { | ||
| wait: flags.minutes({ | ||
| char: 'w', | ||
| default: Duration.minutes(DeployCommand.DEFAULT_WAIT_MINUTES), | ||
| min: Duration.minutes(1), | ||
| description: messages.getMessage('flags.wait'), | ||
| longDescription: messages.getMessage('flags.waitLong'), | ||
| }), | ||
| jobid: flags.id({ | ||
| char: 'i', | ||
| description: messages.getMessage('flags.jobid'), | ||
| validate: (val) => { | ||
| if (val.startsWith('0Af')) { | ||
| return true; | ||
| } else { | ||
| throw SfdxError.create('@salesforce/plugin-source', 'deploy', 'invalidDeployId'); | ||
| } | ||
| }, | ||
| }), | ||
| }; | ||
| // The most important difference between this and source:deploy:cancel | ||
| public isSourceStash = false; | ||
|
|
||
| public async run(): Promise<DeployCancelCommandResult> { | ||
| await this.cancel(); | ||
| this.resolveSuccess(); | ||
| return this.formatResult(); | ||
| } | ||
|
|
||
| protected async cancel(): Promise<void> { | ||
| const deployId = this.resolveDeployId(this.getFlag<string>('jobid')); | ||
| try { | ||
| const deploy = this.createDeploy(deployId); | ||
| await deploy.cancel(); | ||
|
|
||
| this.deployResult = await this.poll(deployId); | ||
| } catch (e) { | ||
| if (e instanceof Error) { | ||
| throw SfdxError.create('@salesforce/plugin-source', 'cancel', 'CancelFailed', [e.message]); | ||
| } else { | ||
| throw SfdxError.wrap(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected resolveSuccess(): void { | ||
| const status = this.deployResult.response.status; | ||
| if (status !== RequestStatus.Canceled) { | ||
| this.setExitCode(1); | ||
| } | ||
| } | ||
|
|
||
| protected formatResult(): DeployCancelCommandResult { | ||
| const formatter = new DeployCancelResultFormatter(this.logger, this.ux, this.deployResult); | ||
| if (!this.isJsonOutput()) { | ||
| formatter.display(); | ||
| } | ||
| return formatter.getJson(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.