generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds pushupgrade abort command support
- Loading branch information
Showing
5 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,39 @@ | ||
# summary | ||
|
||
Abort the package push upgrade request. | ||
|
||
# description | ||
|
||
Specify the request ID for which you want abort the request. If applicable, the command displays errors related to the request. Only package push requests in Created or Pending statuses can be aborted. | ||
|
||
To show all requests in the org, run "<%= config.bin %> package pushupgrade list". | ||
|
||
# examples | ||
|
||
- Cancel the specified package push upgrade request with the specified ID; uses your default Dev Hub org: | ||
|
||
<%= config.bin %> <%= command.id %> --package-push-request-id 0DV... | ||
|
||
- Cancel the specified package push upgrade request in the Dev Hub org with username [email protected]: | ||
|
||
<%= config.bin %> <%= command.id %> --package-push-request-id 0DV... --target-dev-hub [email protected] | ||
|
||
# flags.package-push-request-id.summary | ||
|
||
ID (starts with 0DV) of the package push request you want to cancel. This is the id that is returned when the push upgrade is scheduled. | ||
|
||
# error.invalid-package-push-request-id-owner | ||
|
||
--package-push-request-id 0DV... is not owned by the org from where the CLI command is run. | ||
|
||
# error.invalid-package-push-request-id | ||
|
||
Package push upgrade request id is invalid. Please use valid ID (starts with 0DV). | ||
|
||
# error.invalid-package-push-request-status | ||
|
||
The status of the push request is one of the following: In Progress, Succeeded, Failed, Canceled. Only push requests in Created or Pending statuses can be aborted. | ||
|
||
# status | ||
|
||
Status |
This file contains 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,19 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/PackagePushUpgradeAbortResult", | ||
"definitions": { | ||
"PackagePushUpgradeAbortResult": { | ||
"type": "object", | ||
"properties": { | ||
"PushUpgradeRequestId": { | ||
"type": "string" | ||
}, | ||
"Status": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["PushUpgradeRequestId", "Status"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
This file contains 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,51 @@ | ||
/* | ||
* Copyright (c) 2024, 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 fs from 'node:fs/promises'; | ||
import * as csv from 'csv-parse/sync'; | ||
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core'; | ||
import { Messages, SfError } from '@salesforce/core'; | ||
import { PackagePushUpgrade, PackagePushUpgradeAbortResult } from '@salesforce/packaging'; | ||
import { requiredHubFlag } from '../../../utils/hubFlag.js'; | ||
|
||
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_pushupgrade_abort'); | ||
|
||
export class PackagePushUpgradeAbortCommand extends SfCommand<PackagePushUpgradeAbortResult> { | ||
public static readonly summary = messages.getMessage('summary'); | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessages('examples'); | ||
// public static readonly hidden = true; | ||
// public static state = 'beta'; | ||
public static readonly deprecateAliases = true; | ||
public static readonly aliases = ['force:package:pushupgrade:abort']; | ||
public static readonly flags = { | ||
loglevel, | ||
'target-dev-hub': requiredHubFlag, | ||
'api-version': orgApiVersionFlagWithDeprecations, | ||
// eslint-disable-next-line sf-plugin/id-flag-suggestions | ||
'package-push-request-id': Flags.salesforceId({ | ||
length: 'both', | ||
deprecateAliases: true, | ||
aliases: ['packagepushrequestid'], | ||
char: 'i', | ||
summary: messages.getMessage('flags.package-push-request-id.summary'), | ||
required: true, | ||
}), | ||
}; | ||
|
||
public async run(): Promise<PackagePushUpgradeAbortResult> { | ||
const { flags } = await this.parse(PackagePushUpgradeAbortCommand); | ||
const connection = flags['target-dev-hub'].getConnection(flags['api-version']); | ||
|
||
const packagePushRequestOptions = { packagePushRequestId: flags['package-push-request-id'] }; | ||
|
||
// Schedule the push upgrade | ||
const result = await PackagePushUpgrade.abort(connection, packagePushRequestOptions); | ||
|
||
return result; | ||
} | ||
} |
This file contains 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,108 @@ | ||
// /* | ||
// * Copyright (c) 2024, 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 fs from 'node:fs'; | ||
// import { expect } from 'chai'; | ||
// import { TestContext, MockTestOrgData } from '@salesforce/core/testSetup'; | ||
// import { Config } from '@oclif/core'; | ||
// import { PackagePushUpgrade, PackagePushUpgradeAbortResult } from '@salesforce/packaging'; | ||
// import { PackagePushUpgradeAbortCommand } from '../../../src/commands/package/pushupgrade/abort.js'; | ||
|
||
// describe('package:pushupgrade:abort - tests', () => { | ||
// const $$ = new TestContext(); | ||
// const testOrg = new MockTestOrgData(); | ||
// const createStub = $$.SANDBOX.stub(PackagePushUpgrade, 'schedule'); | ||
// const config = new Config({ root: import.meta.url }); | ||
|
||
// const stubSpinner = (cmd: PackagePushUpgradeAbortCommand) => { | ||
// $$.SANDBOX.stub(cmd.spinner, 'start'); | ||
// $$.SANDBOX.stub(cmd.spinner, 'stop'); | ||
// }; | ||
|
||
// before(async () => { | ||
// await $$.stubAuths(testOrg); | ||
// await config.load(); | ||
|
||
// // Create actual file | ||
// fs.writeFileSync('valid-orgs.csv', '00D00000000000100D000000000002'); | ||
// }); | ||
|
||
// afterEach(() => { | ||
// // Clean up file | ||
// $$.restore(); | ||
// }); | ||
|
||
// it('should successfully schedule a push upgrade', async () => { | ||
// const mockResult: PackagePushScheduleResult = { | ||
// PushRequestId: 'mockPushJobId', | ||
// ScheduledStartTime: '2023-01-01T00:00:00Z', | ||
// Status: 'Scheduled', | ||
// }; | ||
|
||
// createStub.resolves(mockResult); | ||
|
||
// // Mock the file system | ||
// const mockOrgIds = ['00D000000000001', '00D000000000002']; | ||
// const mockFileContent = mockOrgIds.join(''); | ||
// $$.SANDBOX.stub(fs, 'readFileSync').returns(mockFileContent); | ||
// $$.SANDBOX.stub(fs, 'existsSync').returns(true); | ||
|
||
// const cmd = new PackagePushScheduleCommand( | ||
// [ | ||
// '-i', | ||
// '04tXXXXXXXXXXXXXXX', | ||
// '-v', | ||
// '[email protected]', | ||
// '--scheduled-start-time', | ||
// '2023-01-01T00:00:00Z', | ||
// '--org-list', | ||
// 'valid-orgs.csv', | ||
// ], | ||
// config | ||
// ); | ||
|
||
// stubSpinner(cmd); | ||
|
||
// try { | ||
// const res = await cmd.run(); | ||
// expect(res).to.eql(mockResult); | ||
// expect(createStub.calledOnce).to.be.true; | ||
// } catch (error) { | ||
// expect.fail(`Test should not throw an error: ${(error as Error).message}`); | ||
// } | ||
// // Clean up file | ||
// fs.unlinkSync('valid-orgs.csv'); | ||
// }); | ||
|
||
// it('should fail to schedule push upgrade', async () => { | ||
// const errorMessage = 'Failed to schedule push upgrade'; | ||
// createStub.rejects(new Error(errorMessage)); | ||
|
||
// const cmd = new PackagePushScheduleCommand( | ||
// [ | ||
// '-i', | ||
// '04tXXXXXXXXXXXXXXX', | ||
// '-v', | ||
// '[email protected]', | ||
// '--scheduled-start-time', | ||
// '2023-01-01T00:00:00Z', | ||
// '--org-list', | ||
// 'valid-orgs.csv', | ||
// ], | ||
// config | ||
// ); | ||
|
||
// stubSpinner(cmd); | ||
|
||
// try { | ||
// await cmd.run(); | ||
// // If the command runs successfully, fail the test | ||
// expect.fail('Expected an error to be thrown'); | ||
// } catch (error) { | ||
// expect(error).to.be.instanceOf(Error); | ||
// } | ||
// }); | ||
// }); |