Skip to content

Commit 0f4e1c8

Browse files
authored
feat: display version in list
* chore: lint fixes * chore: update schemas and snapshots * fix: use latest packaging lib * fix: no result mutation when fetching verbose data * fix: reduce query size from test
1 parent 9ddd9b8 commit 0f4e1c8

File tree

7 files changed

+300
-82
lines changed

7 files changed

+300
-82
lines changed

command-snapshot.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
{
267267
"command": "package:version:create:list",
268268
"plugin": "@salesforce/plugin-packaging",
269-
"flags": ["api-version", "created-last-days", "json", "loglevel", "status", "target-dev-hub"],
269+
"flags": ["api-version", "created-last-days", "json", "loglevel", "status", "target-dev-hub", "verbose"],
270270
"alias": ["force:package:version:create:list"],
271271
"flagChars": ["c", "s", "v"],
272272
"flagAliases": ["apiversion", "createdlastdays", "target-hub-org", "targetdevhubusername"]

messages/package_version_create_list.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ To get information about a specific request, run "<%= config.bin %> package vers
1414

1515
Status of the version creation request, used to filter the list.
1616

17+
# flags.verbose.summary
18+
19+
Displays additional information at a slight performance cost, such as the version name and number for each package version create request.
20+
1721
# examples
1822

1923
- List all package version creation requests in your default Dev Hub org:

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"author": "Salesforce",
77
"bugs": "https://github.com/forcedotcom/cli/issues",
88
"dependencies": {
9-
"@oclif/core": "^2.8.2",
10-
"@salesforce/core": "^4.2.1",
11-
"@salesforce/kit": "^3.0.2",
12-
"@salesforce/packaging": "^2.1.2",
13-
"@salesforce/sf-plugins-core": "^3.0.4",
9+
"@oclif/core": "^2.8.11",
10+
"@salesforce/core": "^4.3.2",
11+
"@salesforce/kit": "^3.0.3",
12+
"@salesforce/packaging": "^2.2.0",
13+
"@salesforce/sf-plugins-core": "^3.1.4",
1414
"chalk": "^4.1.2",
1515
"tslib": "^2"
1616
},
@@ -258,4 +258,4 @@
258258
"output": []
259259
}
260260
}
261-
}
261+
}

schemas/package-version-create-list.json

+57-54
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,64 @@
55
"CreateListCommandResult": {
66
"type": "array",
77
"items": {
8-
"$ref": "#/definitions/PackageVersionCreateRequestResult"
9-
}
10-
},
11-
"PackageVersionCreateRequestResult": {
12-
"type": "object",
13-
"properties": {
14-
"Id": {
15-
"type": "string"
16-
},
17-
"Status": {
18-
"$ref": "#/definitions/PackagingSObjects.Package2VersionStatus"
19-
},
20-
"Package2Id": {
21-
"type": "string"
22-
},
23-
"Package2VersionId": {
24-
"type": "string"
25-
},
26-
"SubscriberPackageVersionId": {
27-
"type": ["string", "null"]
28-
},
29-
"Tag": {
30-
"type": "string"
8+
"type": "object",
9+
"additionalProperties": false,
10+
"properties": {
11+
"VersionName": {
12+
"type": "string"
13+
},
14+
"VersionNumber": {
15+
"type": "string"
16+
},
17+
"Id": {
18+
"type": "string"
19+
},
20+
"Status": {
21+
"$ref": "#/definitions/PackagingSObjects.Package2VersionStatus"
22+
},
23+
"Package2Id": {
24+
"type": "string"
25+
},
26+
"Package2VersionId": {
27+
"type": "string"
28+
},
29+
"SubscriberPackageVersionId": {
30+
"type": ["string", "null"]
31+
},
32+
"Tag": {
33+
"type": "string"
34+
},
35+
"Branch": {
36+
"type": "string"
37+
},
38+
"Error": {
39+
"type": "array",
40+
"items": {}
41+
},
42+
"CreatedDate": {
43+
"type": "string"
44+
},
45+
"HasMetadataRemoved": {
46+
"type": ["boolean", "null"]
47+
},
48+
"CreatedBy": {
49+
"type": "string"
50+
}
3151
},
32-
"Branch": {
33-
"type": "string"
34-
},
35-
"Error": {
36-
"type": "array",
37-
"items": {}
38-
},
39-
"CreatedDate": {
40-
"type": "string"
41-
},
42-
"HasMetadataRemoved": {
43-
"type": ["boolean", "null"]
44-
},
45-
"CreatedBy": {
46-
"type": "string"
47-
}
48-
},
49-
"required": [
50-
"Id",
51-
"Status",
52-
"Package2Id",
53-
"Package2VersionId",
54-
"SubscriberPackageVersionId",
55-
"Tag",
56-
"Branch",
57-
"Error",
58-
"CreatedDate",
59-
"HasMetadataRemoved",
60-
"CreatedBy"
61-
],
62-
"additionalProperties": false
52+
"required": [
53+
"Branch",
54+
"CreatedBy",
55+
"CreatedDate",
56+
"Error",
57+
"HasMetadataRemoved",
58+
"Id",
59+
"Package2Id",
60+
"Package2VersionId",
61+
"Status",
62+
"SubscriberPackageVersionId",
63+
"Tag"
64+
]
65+
}
6366
},
6467
"PackagingSObjects.Package2VersionStatus": {
6568
"type": "string",

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

+78-7
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,38 @@
66
*/
77

88
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';
9-
import { Messages } from '@salesforce/core';
10-
import { PackageVersion, PackageVersionCreateRequestResult } from '@salesforce/packaging';
9+
import { Connection, Messages } from '@salesforce/core';
10+
import { PackageVersion, PackageVersionCreateRequestResult, getPackageVersionNumber } from '@salesforce/packaging';
1111
import * as chalk from 'chalk';
1212
import { requiredHubFlag } from '../../../../utils/hubFlag';
1313

1414
Messages.importMessagesDirectory(__dirname);
1515
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_create_list');
1616
const packaging = Messages.loadMessages('@salesforce/plugin-packaging', 'packaging');
1717

18-
export type CreateListCommandResult = PackageVersionCreateRequestResult[];
18+
export type CreateListCommandResult = Array<
19+
PackageVersionCreateRequestResult & {
20+
VersionName?: string;
21+
VersionNumber?: string;
22+
}
23+
>;
24+
25+
type ColumnDataHeader = {
26+
header?: string;
27+
};
28+
type ColumnData = {
29+
Id: ColumnDataHeader;
30+
Status: ColumnDataHeader;
31+
Package2Id: ColumnDataHeader;
32+
Package2VersionId: ColumnDataHeader;
33+
SubscriberPackageVersionId: ColumnDataHeader;
34+
Tag: ColumnDataHeader;
35+
Branch: ColumnDataHeader;
36+
CreatedDate: ColumnDataHeader;
37+
CreatedBy: ColumnDataHeader;
38+
VersionName?: ColumnDataHeader;
39+
VersionNumber?: ColumnDataHeader;
40+
};
1941

2042
type Status = 'Queued' | 'InProgress' | 'Success' | 'Error';
2143

@@ -41,21 +63,26 @@ export class PackageVersionCreateListCommand extends SfCommand<CreateListCommand
4163
char: 's',
4264
summary: messages.getMessage('flags.status.summary'),
4365
}),
66+
verbose: Flags.boolean({
67+
summary: messages.getMessage('flags.verbose.summary'),
68+
}),
4469
};
4570

71+
private connection!: Connection;
72+
4673
public async run(): Promise<CreateListCommandResult> {
4774
const { flags } = await this.parse(PackageVersionCreateListCommand);
48-
const connection = flags['target-dev-hub'].getConnection(flags['api-version']);
49-
const results = await PackageVersion.getPackageVersionCreateRequests(connection, {
75+
this.connection = flags['target-dev-hub'].getConnection(flags['api-version']);
76+
let results = (await PackageVersion.getPackageVersionCreateRequests(this.connection, {
5077
createdlastdays: flags['created-last-days'],
5178
status: flags.status,
52-
});
79+
})) as CreateListCommandResult;
5380

5481
if (results.length === 0) {
5582
this.warn('No results found');
5683
} else {
5784
this.styledHeader(chalk.blue(`Package Version Create Requests [${results.length}]`));
58-
const columnData = {
85+
const columnData: ColumnData = {
5986
Id: {},
6087
Status: {
6188
header: messages.getMessage('status'),
@@ -80,9 +107,53 @@ export class PackageVersionCreateListCommand extends SfCommand<CreateListCommand
80107
header: messages.getMessage('createdBy'),
81108
},
82109
};
110+
if (flags.verbose) {
111+
try {
112+
results = await this.fetchVerboseData(results);
113+
columnData.VersionName = { header: 'Version Name' };
114+
columnData.VersionNumber = { header: 'Version Number' };
115+
} catch (err) {
116+
const errMsg = typeof err === 'string' ? err : err instanceof Error ? err.message : 'unknown error';
117+
this.warn(`error when retrieving verbose data (package name and version) due to: ${errMsg}`);
118+
}
119+
}
83120
this.table(results, columnData, { 'no-truncate': true });
84121
}
85122

86123
return results;
87124
}
125+
126+
// Queries Package2Version for the name and version number of the packages and adds that data
127+
// to the results.
128+
private async fetchVerboseData(results: CreateListCommandResult): Promise<CreateListCommandResult> {
129+
type VersionDataMap = {
130+
[id: string]: { name: string; version: string };
131+
};
132+
// Query for the version name and number data
133+
const versionData = await PackageVersion.queryPackage2Version(this.connection, {
134+
fields: ['Id', 'Name', 'MajorVersion', 'MinorVersion', 'PatchVersion', 'BuildNumber'],
135+
whereClause: "WHERE Id IN ('%IDS%')",
136+
whereClauseItems: results.map((pvcrr) => pvcrr.Package2VersionId).filter(Boolean),
137+
});
138+
139+
const vDataMap: VersionDataMap = {};
140+
versionData.map((vData) => {
141+
if (vData) {
142+
const version = getPackageVersionNumber(vData, true);
143+
vDataMap[vData.Id] = { name: vData.Name, version };
144+
}
145+
});
146+
147+
return results.map((pvcrr) => {
148+
if (vDataMap[pvcrr.Package2VersionId]) {
149+
return {
150+
...pvcrr,
151+
...{
152+
VersionName: vDataMap[pvcrr.Package2VersionId].name,
153+
VersionNumber: vDataMap[pvcrr.Package2VersionId].version,
154+
},
155+
};
156+
} else return pvcrr;
157+
});
158+
}
88159
}

test/commands/package/packageVersion.nut.ts

+28-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
VersionNumber,
1818
} from '@salesforce/packaging';
1919
import { PackageVersionListCommandResult, PackageVersionListDetails } from '../../../src/commands/package/version/list';
20+
import { CreateListCommandResult } from '../../../src/commands/package/version/create/list';
2021

2122
chaiConfig.truncateThreshold = 0;
2223

@@ -181,15 +182,15 @@ describe('package:version:*', () => {
181182

182183
it('should list all of the successful package versions created', async () => {
183184
const command = `package:version:create:list --status Success -v ${session.hubOrg.username} --json`;
184-
const output = execCmd<[{ Status: string }]>(command, { ensureExitCode: 0 }).jsonOutput;
185+
const output = execCmd<CreateListCommandResult>(command, { ensureExitCode: 0 }).jsonOutput;
185186
output?.result?.forEach((result) => {
186187
expect(result?.Status).to.equal('Success');
187188
});
188189
});
189190

190191
it('should list all of the package versions created within the last 2 days', () => {
191192
const command = `package:version:create:list --created-last-days 2 -v ${session.hubOrg.username} --json`;
192-
const output = execCmd<[{ CreatedDate: string }]>(command, { ensureExitCode: 0 }).jsonOutput;
193+
const output = execCmd<CreateListCommandResult>(command, { ensureExitCode: 0 }).jsonOutput;
193194
const keys = [
194195
'Id',
195196
'Status',
@@ -221,7 +222,7 @@ describe('package:version:*', () => {
221222

222223
it('should list the package versions created (json)', async () => {
223224
const command = `package:version:create:list -v ${session.hubOrg.username} --json`;
224-
const output = execCmd<{ [key: string]: unknown }>(command, { ensureExitCode: 0 }).jsonOutput;
225+
const output = execCmd<CreateListCommandResult>(command, { ensureExitCode: 0 }).jsonOutput;
225226
const keys = [
226227
'Id',
227228
'Status',
@@ -240,6 +241,30 @@ describe('package:version:*', () => {
240241
expect(output?.result).to.have.length.greaterThan(0);
241242
expect(output?.result[0]).to.have.keys(keys);
242243
});
244+
245+
it('should list the package versions created --verbose (json)', async () => {
246+
const command = `package:version:create:list --status Success --created-last-days 10 -v ${session.hubOrg.username} --json --verbose`;
247+
const output = execCmd<CreateListCommandResult>(command, { ensureExitCode: 0 }).jsonOutput;
248+
const keys = [
249+
'Id',
250+
'Status',
251+
'Package2Id',
252+
'Package2VersionId',
253+
'SubscriberPackageVersionId',
254+
'Tag',
255+
'Branch',
256+
'Error',
257+
'CreatedDate',
258+
'HasMetadataRemoved',
259+
'CreatedBy',
260+
'VersionName',
261+
'VersionNumber',
262+
];
263+
expect(output).to.be.ok;
264+
expect(output?.status).to.equal(0);
265+
expect(output?.result).to.have.length.greaterThan(0);
266+
expect(output?.result[0]).to.have.keys(keys);
267+
});
243268
});
244269
describe('package:version:list', () => {
245270
it('should list package versions in dev hub - human readable results', () => {

0 commit comments

Comments
 (0)