Skip to content

Commit 0535646

Browse files
Merge pull request #988 from salesforcecli/t/packaging-distribution/W-18839621/Package-Bundle-Version-List-command
feat: added package version list
2 parents 366694b + 21892c4 commit 0535646

7 files changed

Lines changed: 353 additions & 1 deletion

File tree

command-snapshot.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@
7575
"alias": ["force:package:bundle:version:create"],
7676
"command": "package:bundle:version:create",
7777
"flagAliases": ["apiversion", "target-hub-org", "targetdevhubusername"],
78-
"flagChars": ["b", "p", "v", "w"],
78+
"flagChars": ["b", "d", "p", "v", "w"],
7979
"flags": [
8080
"api-version",
8181
"bundle",
8282
"definition-file",
83+
"description",
8384
"flags-dir",
8485
"json",
8586
"loglevel",
@@ -115,6 +116,14 @@
115116
"flags": ["api-version", "flags-dir", "json", "loglevel", "package-create-request-id", "target-dev-hub"],
116117
"plugin": "@salesforce/plugin-packaging"
117118
},
119+
{
120+
"alias": [],
121+
"command": "package:bundle:version:list",
122+
"flagAliases": ["apiversion", "target-hub-org", "targetdevhubusername"],
123+
"flagChars": ["v"],
124+
"flags": ["api-version", "flags-dir", "json", "loglevel", "target-dev-hub", "verbose"],
125+
"plugin": "@salesforce/plugin-packaging"
126+
},
118127
{
119128
"alias": ["force:package:convert"],
120129
"command": "package:convert",

messages/bundle_version_create.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Show verbose output of the command execution.
3232

3333
Show detailed information about the bundle version creation process.
3434

35+
# flags.description.summary
36+
37+
Description of the package bundle version.
38+
3539
# bundleVersionCreateWaitingStatus
3640

3741
Waiting for bundle version creation to complete. %s minutes remaining. Current status: %s

messages/bundle_version_list.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# summary
2+
3+
List all package bundle versions in the Dev Hub org.
4+
5+
# examples
6+
7+
List all package bundle versions in the specified Dev Hub org; uses the Dev Hub org with the username devhub@example.com:
8+
9+
sf package bundle version list --target-dev-hub <dev_hub_alias>
10+
11+
# namespace
12+
13+
Namespace Prefix
14+
15+
# name
16+
17+
Name
18+
19+
# id
20+
21+
Id
22+
23+
# bundle-id
24+
25+
Package Bundle Id
26+
27+
# alias
28+
29+
Alias
30+
31+
# description
32+
33+
Description
34+
35+
# flags.verbose.summary
36+
37+
Display extended bundle detail.
38+
39+
# error-notification-username
40+
41+
Error Notification Username
42+
43+
# createdBy
44+
45+
Created By
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/PackageBundleVersionResults",
4+
"definitions": {
5+
"PackageBundleVersionResults": {
6+
"type": "array",
7+
"items": {
8+
"$ref": "#/definitions/BundleSObjects.BundleVersion"
9+
}
10+
},
11+
"BundleSObjects.BundleVersion": {
12+
"type": "object",
13+
"properties": {
14+
"Id": {
15+
"type": "string"
16+
},
17+
"PackageBundle": {
18+
"$ref": "#/definitions/BundleSObjects.Bundle"
19+
},
20+
"VersionName": {
21+
"type": "string"
22+
},
23+
"MajorVersion": {
24+
"type": "string"
25+
},
26+
"MinorVersion": {
27+
"type": "string"
28+
},
29+
"Ancestor": {
30+
"anyOf": [
31+
{
32+
"$ref": "#/definitions/BundleSObjects.BundleVersion"
33+
},
34+
{
35+
"type": "null"
36+
}
37+
]
38+
},
39+
"IsReleased": {
40+
"type": "boolean"
41+
},
42+
"CreatedDate": {
43+
"type": "string"
44+
},
45+
"CreatedById": {
46+
"type": "string"
47+
},
48+
"LastModifiedDate": {
49+
"type": "string"
50+
},
51+
"LastModifiedById": {
52+
"type": "string"
53+
}
54+
},
55+
"required": [
56+
"Id",
57+
"PackageBundle",
58+
"VersionName",
59+
"MajorVersion",
60+
"MinorVersion",
61+
"IsReleased",
62+
"CreatedDate",
63+
"CreatedById",
64+
"LastModifiedDate",
65+
"LastModifiedById"
66+
],
67+
"additionalProperties": false
68+
},
69+
"BundleSObjects.Bundle": {
70+
"type": "object",
71+
"properties": {
72+
"BundleName": {
73+
"type": "string"
74+
},
75+
"Description": {
76+
"type": "string"
77+
},
78+
"Id": {
79+
"type": "string"
80+
},
81+
"IsDeleted": {
82+
"type": "boolean"
83+
},
84+
"CreatedDate": {
85+
"type": "string"
86+
},
87+
"CreatedById": {
88+
"type": "string"
89+
},
90+
"LastModifiedDate": {
91+
"type": "string"
92+
},
93+
"LastModifiedById": {
94+
"type": "string"
95+
},
96+
"SystemModstamp": {
97+
"type": "string"
98+
}
99+
},
100+
"required": [
101+
"BundleName",
102+
"Id",
103+
"IsDeleted",
104+
"CreatedDate",
105+
"CreatedById",
106+
"LastModifiedDate",
107+
"LastModifiedById",
108+
"SystemModstamp"
109+
],
110+
"additionalProperties": false
111+
}
112+
}
113+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export class PackageBundlesCreate extends SfCommand<BundleSObjects.PackageBundle
3434
summary: messages.getMessage('flags.bundle.summary'),
3535
required: true,
3636
}),
37+
description: Flags.string({
38+
char: 'd',
39+
summary: messages.getMessage('flags.description.summary'),
40+
}),
3741
'definition-file': Flags.string({
3842
char: 'p',
3943
summary: messages.getMessage('flags.definition-file.summary'),
@@ -58,6 +62,7 @@ export class PackageBundlesCreate extends SfCommand<BundleSObjects.PackageBundle
5862
project: this.project!,
5963
PackageBundle: flags.bundle,
6064
BundleVersionComponentsPath: flags['definition-file'],
65+
Description: flags.description,
6166
MajorVersion: '',
6267
MinorVersion: '',
6368
Ancestor: '',
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';
9+
import { Connection, Messages } from '@salesforce/core';
10+
import { BundleSObjects, PackageBundleVersion } from '@salesforce/packaging';
11+
import chalk from 'chalk';
12+
import { requiredHubFlag } from '../../../../utils/hubFlag.js';
13+
14+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
15+
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'bundle_version_list');
16+
17+
export type PackageBundleVersionResults = BundleSObjects.BundleVersion[];
18+
19+
export class PackageBundleVersionListCommand extends SfCommand<PackageBundleVersionResults> {
20+
public static readonly summary = messages.getMessage('summary');
21+
public static readonly description = messages.getMessage('description');
22+
public static readonly examples = messages.getMessages('examples');
23+
public static readonly flags = {
24+
loglevel,
25+
'target-dev-hub': requiredHubFlag,
26+
'api-version': orgApiVersionFlagWithDeprecations,
27+
verbose: Flags.boolean({
28+
summary: messages.getMessage('flags.verbose.summary'),
29+
}),
30+
};
31+
32+
private connection!: Connection;
33+
34+
public async run(): Promise<PackageBundleVersionResults> {
35+
const { flags } = await this.parse(PackageBundleVersionListCommand);
36+
this.connection = flags['target-dev-hub'].getConnection(flags['api-version']);
37+
const results = await PackageBundleVersion.list(this.connection);
38+
39+
if (results.length === 0) {
40+
this.warn('No results found');
41+
} else {
42+
const data = results.map((r) => ({
43+
'Bundle Name': r.PackageBundle.BundleName,
44+
'Bundle Id': r.PackageBundle.Id,
45+
'Bundle Version Number': String(r.MajorVersion) + '.' + String(r.MinorVersion),
46+
'Bundle Version Id': r.Id,
47+
'Bundle Version Name': r.VersionName,
48+
'Bundle Version Description': r.PackageBundle.Description,
49+
...(flags.verbose
50+
? {
51+
'Ancestor Id': r.Ancestor?.Id,
52+
'Ancestor Name': r.Ancestor?.PackageBundle.BundleName,
53+
'Ancestor Version Name': r.Ancestor?.VersionName,
54+
'Ancestor Version': String(r.Ancestor?.MajorVersion) + '.' + String(r.Ancestor?.MinorVersion),
55+
'Created Date': r.CreatedDate,
56+
'Created By': r.CreatedById,
57+
'Last Modified Date': r.LastModifiedDate,
58+
'Last Modified By': r.LastModifiedById,
59+
}
60+
: {}),
61+
}));
62+
63+
this.table({
64+
data,
65+
overflow: 'wrap',
66+
title: chalk.blue(`Package Bundle Version List [${results.length}]`),
67+
});
68+
}
69+
70+
return results;
71+
}
72+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) 2025, 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+
import { Config } from '@oclif/core';
8+
import { TestContext, MockTestOrgData } from '@salesforce/core/testSetup';
9+
import { expect } from 'chai';
10+
import { PackageBundleVersion } from '@salesforce/packaging';
11+
import { stubSfCommandUx } from '@salesforce/sf-plugins-core';
12+
import sinon from 'sinon';
13+
import { PackageBundleVersionListCommand } from '../../../src/commands/package/bundle/version/list.js';
14+
describe('package:bundle:version:list - tests', () => {
15+
const $$ = new TestContext();
16+
const testOrg = new MockTestOrgData();
17+
let sfCommandStubs: ReturnType<typeof stubSfCommandUx>;
18+
let listStub: sinon.SinonStub;
19+
const config = new Config({ root: import.meta.url });
20+
21+
beforeEach(async () => {
22+
await $$.stubAuths(testOrg);
23+
await config.load();
24+
sfCommandStubs = stubSfCommandUx($$.SANDBOX);
25+
26+
listStub = $$.SANDBOX.stub(PackageBundleVersion, 'list');
27+
});
28+
29+
afterEach(() => {
30+
$$.restore();
31+
});
32+
33+
it('should list a bundle', async () => {
34+
const cmd = new PackageBundleVersionListCommand(['-v', testOrg.username], config);
35+
36+
listStub.resolves([
37+
{
38+
Id: 'test-version-id',
39+
PackageBundle: {
40+
Id: 'test-bundle-id',
41+
BundleName: 'test-bundle',
42+
Description: undefined,
43+
IsDeleted: false,
44+
CreatedDate: '2025-01-01T00:00:00.000Z',
45+
CreatedById: 'test-user-id',
46+
LastModifiedDate: '2025-01-01T00:00:00.000Z',
47+
LastModifiedById: 'test-user-id',
48+
SystemModstamp: '2025-01-01T00:00:00.000Z',
49+
},
50+
VersionName: 'test-version',
51+
MajorVersion: '1',
52+
MinorVersion: '0',
53+
CreatedDate: '2025-01-01T00:00:00.000Z',
54+
CreatedById: 'test-user-id',
55+
LastModifiedDate: '2025-01-01T00:00:00.000Z',
56+
LastModifiedById: 'test-user-id',
57+
Ancestor: null,
58+
IsReleased: false,
59+
},
60+
]);
61+
62+
await cmd.run();
63+
64+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
65+
expect(sfCommandStubs.table.calledOnce).to.be.true;
66+
});
67+
68+
it('should throw error when test org flag is missing', async () => {
69+
const cmd = new PackageBundleVersionListCommand([], config);
70+
71+
listStub.resolves([
72+
{
73+
Id: 'test-version-id',
74+
PackageBundle: {
75+
Id: 'test-bundle-id',
76+
BundleName: 'test-bundle',
77+
Description: undefined,
78+
IsDeleted: false,
79+
CreatedDate: '2025-01-01T00:00:00.000Z',
80+
CreatedById: 'test-user-id',
81+
LastModifiedDate: '2025-01-01T00:00:00.000Z',
82+
LastModifiedById: 'test-user-id',
83+
SystemModstamp: '2025-01-01T00:00:00.000Z',
84+
},
85+
VersionName: 'test-version',
86+
MajorVersion: '1',
87+
MinorVersion: '0',
88+
CreatedDate: '2025-01-01T00:00:00.000Z',
89+
CreatedById: 'test-user-id',
90+
LastModifiedDate: '2025-01-01T00:00:00.000Z',
91+
LastModifiedById: 'test-user-id',
92+
Ancestor: null,
93+
IsReleased: false,
94+
},
95+
]);
96+
97+
try {
98+
await cmd.run();
99+
expect.fail('Expected error was not thrown');
100+
} catch (error) {
101+
expect((error as Error).message).to.include('No default dev hub found');
102+
}
103+
});
104+
});

0 commit comments

Comments
 (0)