Skip to content

Commit 55df236

Browse files
feat: created package bundle delete
additionally made package bundle version create report flags make more sense
1 parent c414fae commit 55df236

8 files changed

Lines changed: 173 additions & 27 deletions

File tree

command-snapshot.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@
6363
"flags": ["api-version", "description", "flags-dir", "json", "loglevel", "name", "target-dev-hub"],
6464
"plugin": "@salesforce/plugin-packaging"
6565
},
66+
{
67+
"alias": [],
68+
"command": "package:bundle:delete",
69+
"flagAliases": ["apiversion", "noprompt", "target-hub-org", "targetdevhubusername"],
70+
"flagChars": ["b", "n", "v"],
71+
"flags": ["api-version", "bundle", "flags-dir", "json", "loglevel", "no-prompt", "target-dev-hub", "undelete"],
72+
"plugin": "@salesforce/plugin-packaging"
73+
},
6674
{
6775
"alias": ["force:package:bundle:list"],
6876
"command": "package:bundle:list",
@@ -109,11 +117,11 @@
109117
"plugin": "@salesforce/plugin-packaging"
110118
},
111119
{
112-
"alias": ["force:package:bundle:version:create:report"],
120+
"alias": [],
113121
"command": "package:bundle:version:create:report",
114-
"flagAliases": ["apiversion", "packagecreaterequestid", "target-hub-org", "targetdevhubusername"],
122+
"flagAliases": ["apiversion", "bundleversioncreaterequestid", "target-hub-org", "targetdevhubusername"],
115123
"flagChars": ["i", "v"],
116-
"flags": ["api-version", "flags-dir", "json", "loglevel", "package-create-request-id", "target-dev-hub"],
124+
"flags": ["api-version", "bundle-version-create-request-id", "flags-dir", "json", "loglevel", "target-dev-hub"],
117125
"plugin": "@salesforce/plugin-packaging"
118126
},
119127
{

messages/bundle_version_create_report.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Use this command to check the status of a package bundle version creation reques
1616

1717
<%= config.bin %> force:package:bundle:version:create:report -i 0Ho0x0000000000000
1818

19-
# flags.package-create-request-id.summary
19+
# flags.bundle-version-create-request-id.summary
2020

2121
The ID of the package bundle version creation request to report on.
2222

@@ -28,11 +28,11 @@ ID
2828

2929
Status
3030

31-
# package-bundle-id
31+
# bundle-id
3232

3333
Package Bundle ID
3434

35-
# package-bundle-version-id
35+
# bundle-version-id
3636

3737
Package Bundle Version ID
3838

messages/package_bundle_delete.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ The request to delete this package bundle was canceled
4848

4949
# humanSuccess
5050

51-
Successfully deleted the package bundle.
51+
Successfully deleted the package bundle %s.
52+
53+
# humanError
54+
55+
Failed to delete the package bundle.

schemas/package-bundle-delete.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/BundleSaveResult",
4+
"definitions": {
5+
"BundleSaveResult": {
6+
"$ref": "#/definitions/SaveResult"
7+
},
8+
"SaveResult": {
9+
"anyOf": [
10+
{
11+
"type": "object",
12+
"properties": {
13+
"success": {
14+
"type": "boolean",
15+
"const": true
16+
},
17+
"id": {
18+
"type": "string"
19+
},
20+
"errors": {
21+
"type": "array",
22+
"items": {
23+
"not": {}
24+
}
25+
}
26+
},
27+
"required": ["success", "id", "errors"],
28+
"additionalProperties": false
29+
},
30+
{
31+
"type": "object",
32+
"properties": {
33+
"success": {
34+
"type": "boolean",
35+
"const": false
36+
},
37+
"id": {
38+
"not": {}
39+
},
40+
"errors": {
41+
"type": "array",
42+
"items": {
43+
"$ref": "#/definitions/SaveError"
44+
}
45+
}
46+
},
47+
"required": ["success", "errors"],
48+
"additionalProperties": false
49+
}
50+
]
51+
},
52+
"SaveError": {
53+
"type": "object",
54+
"properties": {
55+
"errorCode": {
56+
"type": "string"
57+
},
58+
"message": {
59+
"type": "string"
60+
},
61+
"fields": {
62+
"type": "array",
63+
"items": {
64+
"type": "string"
65+
}
66+
}
67+
},
68+
"required": ["errorCode", "message"],
69+
"additionalProperties": false
70+
}
71+
}
72+
}

src/commands/package/bundle/delete.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77

88
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';
99
import { Messages } from '@salesforce/core/messages';
10-
import { PackageBundle } from '@salesforce/packaging';
10+
import { PackageBundle, BundleSaveResult } from '@salesforce/packaging';
1111
import { requiredHubFlag } from '../../../utils/hubFlag.js';
1212

1313
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1414
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_bundle_delete');
1515

16-
export class PackageBundleDeleteCommand extends SfCommand<void> {
16+
export class PackageBundleDeleteCommand extends SfCommand<BundleSaveResult> {
1717
public static readonly summary = messages.getMessage('summary');
1818
public static readonly description = messages.getMessage('description');
1919
public static readonly examples = messages.getMessages('examples');
20+
public static readonly requiresProject = true;
2021
public static readonly flags = {
2122
loglevel,
2223
'target-dev-hub': requiredHubFlag,
@@ -28,7 +29,7 @@ export class PackageBundleDeleteCommand extends SfCommand<void> {
2829
summary: messages.getMessage('flags.no-prompt.summary'),
2930
}),
3031
bundle: Flags.string({
31-
char: 'p',
32+
char: 'b',
3233
summary: messages.getMessage('flags.bundle.summary'),
3334
required: true,
3435
}),
@@ -39,7 +40,7 @@ export class PackageBundleDeleteCommand extends SfCommand<void> {
3940
}),
4041
};
4142

42-
public async run(): Promise<void> {
43+
public async run(): Promise<BundleSaveResult> {
4344
const { flags } = await this.parse(PackageBundleDeleteCommand);
4445
const message = messages.getMessage(flags.undelete ? 'prompt-undelete' : 'prompt-delete');
4546
const accepted = flags['no-prompt'] || flags.json ? true : await this.confirm({ message });
@@ -48,12 +49,17 @@ export class PackageBundleDeleteCommand extends SfCommand<void> {
4849
}
4950

5051
const connection = flags['target-dev-hub'].getConnection(flags['api-version']);
51-
await PackageBundle.delete(connection, flags.bundle);
52-
this.display();
52+
const result = await PackageBundle.delete(connection, this.project!, flags.bundle);
53+
this.display(result);
54+
return result;
5355
}
5456

55-
private display(): void {
57+
private display(result: BundleSaveResult): void {
5658
this.log();
57-
this.logSuccess(messages.getMessage('humanSuccess'));
59+
if ((result as { success: boolean }).success) {
60+
this.logSuccess(messages.getMessage('humanSuccess', [(result as { id: string }).id]));
61+
} else {
62+
this.error(messages.getMessage('humanError'));
63+
}
5864
}
5965
}

src/commands/package/bundle/version/create/report.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,25 @@ export class PackageBundleVersionCreateReportCommand extends SfCommand<ReportCom
2121
public static readonly summary = messages.getMessage('summary');
2222
public static readonly description = messages.getMessage('description');
2323
public static readonly examples = messages.getMessages('examples');
24-
public static readonly deprecateAliases = true;
25-
public static readonly aliases = ['force:package:bundle:version:create:report'];
2624
public static readonly flags = {
2725
loglevel,
2826
'target-dev-hub': requiredHubFlag,
2927
'api-version': orgApiVersionFlagWithDeprecations,
3028
// eslint-disable-next-line sf-plugin/id-flag-suggestions
31-
'package-create-request-id': Flags.salesforceId({
29+
'bundle-version-create-request-id': Flags.salesforceId({
3230
length: 'both',
3331
deprecateAliases: true,
34-
aliases: ['packagecreaterequestid'],
32+
aliases: ['bundleversioncreaterequestid'],
3533
char: 'i',
36-
summary: messages.getMessage('flags.package-create-request-id.summary'),
34+
summary: messages.getMessage('flags.bundle-version-create-request-id.summary'),
3735
required: true,
3836
}),
3937
};
4038

4139
public async run(): Promise<ReportCommandResult> {
4240
const { flags } = await this.parse(PackageBundleVersionCreateReportCommand);
4341
const result = await PackageBundleVersionCreate.getCreateStatus(
44-
flags['package-create-request-id'],
42+
flags['bundle-version-create-request-id'],
4543
flags['target-dev-hub'].getConnection(flags['api-version'])
4644
);
4745
this.display(result);
@@ -59,11 +57,11 @@ export class PackageBundleVersionCreateReportCommand extends SfCommand<ReportCom
5957
value: camelCaseToTitleCase(record.RequestStatus),
6058
},
6159
{
62-
name: messages.getMessage('package-bundle-id'),
60+
name: messages.getMessage('bundle-id'),
6361
value: record.PackageBundleId,
6462
},
6563
{
66-
name: messages.getMessage('package-bundle-version-id'),
64+
name: messages.getMessage('bundle-version-id'),
6765
value: record.PackageBundleVersionId,
6866
},
6967
{
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2022, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
9+
import { expect } from 'chai';
10+
11+
describe('bundle create/delete', () => {
12+
let session: TestSession;
13+
let bundleName: string;
14+
before(async () => {
15+
session = await TestSession.create({
16+
devhubAuthStrategy: 'AUTO',
17+
project: { name: 'bundleCreateDelete' },
18+
});
19+
});
20+
21+
after(async () => {
22+
await session?.clean();
23+
});
24+
describe('create/delete - human results', () => {
25+
before(async () => {
26+
bundleName = `test-bundle-${Date.now()}`;
27+
});
28+
it('should create a bundle - human readable results', () => {
29+
const command = `package:bundle:create --name ${bundleName} -v ${session.hubOrg.username}`;
30+
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
31+
expect(output).to.contain('Ids');
32+
expect(output).to.match(/Bundle Id\s+?|1Fl/);
33+
});
34+
it('should delete a bundle - human readable results', () => {
35+
const command = `package:bundle:delete -b ${bundleName} -v ${session.hubOrg.username} --no-prompt`;
36+
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
37+
expect(output).to.contain('Successfully deleted the package bundle');
38+
});
39+
});
40+
describe('create/delete - json results', () => {
41+
before(async () => {
42+
bundleName = `test-bundle-${Date.now()}`;
43+
});
44+
it('should create a bundle - json results', () => {
45+
const command = `package:bundle:create --name ${bundleName} -v ${session.hubOrg.username} --json`;
46+
const output = execCmd<{ Id: string }>(command, { ensureExitCode: 0 }).jsonOutput;
47+
expect(output?.status).to.equal(0);
48+
expect(output?.result).to.have.property('Id');
49+
expect(output?.result?.Id).to.match(/1Fl.{12,15}/);
50+
});
51+
it('should delete a bundle - json results', () => {
52+
const command = `package:bundle:delete -b ${bundleName} -v ${session.hubOrg.username} --json`;
53+
const output = execCmd<{ id: string; success: boolean; errors: [] }>(command, { ensureExitCode: 0 }).jsonOutput;
54+
expect(output?.result?.id).to.match(/1Fl.{12,15}/);
55+
expect(output?.result?.success).to.be.true;
56+
});
57+
});
58+
});

test/commands/bundle/bundleVersionCreateReport.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('force:package:bundle:version:create:report - tests', () => {
5151
getCreateStatusStub.resolves(mockResult);
5252

5353
const cmd = new PackageBundleVersionCreateReportCommand(
54-
['--package-create-request-id', requestId, '--target-dev-hub', testOrg.username],
54+
['--bundle-version-create-request-id', requestId, '--target-dev-hub', testOrg.username],
5555
config
5656
);
5757

@@ -83,7 +83,7 @@ describe('force:package:bundle:version:create:report - tests', () => {
8383
getCreateStatusStub.resolves(mockResult);
8484

8585
const cmd = new PackageBundleVersionCreateReportCommand(
86-
['-i', requestId, '--target-dev-hub', testOrg.username],
86+
['--bundle-version-create-request-id', requestId, '--target-dev-hub', testOrg.username],
8787
config
8888
);
8989

@@ -108,7 +108,7 @@ describe('force:package:bundle:version:create:report - tests', () => {
108108

109109
it('should throw error when target-dev-hub flag is missing', async () => {
110110
const requestId = '0Ho0x0000000000000';
111-
const cmd = new PackageBundleVersionCreateReportCommand(['--package-create-request-id', requestId], config);
111+
const cmd = new PackageBundleVersionCreateReportCommand(['--bundle-version-create-request-id', requestId], config);
112112

113113
try {
114114
await cmd.run();
@@ -125,7 +125,7 @@ describe('force:package:bundle:version:create:report - tests', () => {
125125
getCreateStatusStub.rejects(new Error(errorMessage));
126126

127127
const cmd = new PackageBundleVersionCreateReportCommand(
128-
['--package-create-request-id', requestId, '--target-dev-hub', testOrg.username],
128+
['--bundle-version-create-request-id', requestId, '--target-dev-hub', testOrg.username],
129129
config
130130
);
131131

0 commit comments

Comments
 (0)