Skip to content
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

feat: Package Push Upgrade List command #853

Draft
wants to merge 16 commits into
base: packagingDistribution/pushUpgradeCLI
Choose a base branch
from
Draft
93 changes: 93 additions & 0 deletions messages/package_pushupgrade_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# summary

List package push upgrades.

# description

Shows the details of each request to create a package version in the Dev Hub org.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to update here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this whole file could probably be updated. If you just change package version create with package pushupgrade it should be pretty good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I haven't updated this file except for the first line as placeholder. I'll update it.


All filter parameters are applied using the AND logical operator (not OR).

To get information about a specific request, run "<%= config.bin %> package version create report" and supply the request ID.

# flags.package-id.summary

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

# flags.scheduled-last-days.summary

Filter the list output to display only converted package version.

# flags.status.summary

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

# flags.show-conversions-only.summary

Filter the list output to display only converted package version.

# flags.verbose.summary

Displays additional information at a slight performance cost, such as the version name and number for each package version create request.

# examples

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

<%= config.bin %> <%= command.id %>

- List package version creation requests from the last 3 days in the Dev Hub org with username [email protected]:

<%= config.bin %> <%= command.id %> --created-last-days 3 --target-dev-hub

- List package version creation requests with status Error:

<%= config.bin %> <%= command.id %> --status Error

- List package version creation requests with status InProgress:

<%= config.bin %> <%= command.id %> --status InProgress

- List package version creation requests with status Success that were created today:

<%= config.bin %> <%= command.id %> --created-last-days 0 --status Success

# id

ID

# status

Status

# package-id

Package Id

# packageVersionId

Package Version Id

# subscriberPackageVersionId

Subscriber Package Version Id

# branch

Branch

# tag

Tag

# installUrl

Installation URL

# createdBy

Created By

# convertedFromVersionId

Converted From Version Id
48 changes: 48 additions & 0 deletions schemas/package-pushupgrade-list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/PackagePushRequestListResultArr",
"definitions": {
"PackagePushRequestListResultArr": {
"type": "array",
"items": {
"$ref": "#/definitions/PackagePushRequestListResult"
}
},
"PackagePushRequestListResult": {
"type": "object",
"properties": {
"PushRequestId": {
"type": "string"
},
"PackageVersionId": {
"type": "string"
},
"PushRequestStatus": {
"type": "string"
},
"PushRequestScheduledDateTime": {
"type": "string"
},
"NumOrgsScheduled": {
"type": "number"
},
"NumOrgsUpgradedFail": {
"type": "number"
},
"NumOrgsUpgradedSuccess": {
"type": "number"
}
},
"required": [
"PushRequestId",
"PackageVersionId",
"PushRequestStatus",
"PushRequestScheduledDateTime",
"NumOrgsScheduled",
"NumOrgsUpgradedSuccess",
"NumOrgsUpgradedFail"
],
"additionalProperties": false
}
}
}
100 changes: 100 additions & 0 deletions src/commands/package/pushupgrade/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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 { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { Connection, Messages } from '@salesforce/core';
import { PackagePushRequestListResult, PackagePushUpgrade } from '@salesforce/packaging';
import chalk from 'chalk';
import { requiredHubFlag } from '../../../utils/hubFlag.js';

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

type Status = 'Created' | 'Cancelled' | 'Pending' | 'In Progress' | 'Failed' | 'Succeeded';

export type PackagePushRequestListResultArr = PackagePushRequestListResult[];

export class PackagePushRequestListCommand extends SfCommand<PackagePushRequestListResultArr> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the option to hide the command go here? We should make sure that goes in on first checkin as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I haven't added the hiding command function yet. Let me add that.

public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static readonly aliases = ['force:package:pushupgrade:list'];
public static readonly flags = {
'target-dev-hub': requiredHubFlag,
packageid: Flags.string({
char: 'p',
summary: messages.getMessage('flags.package-id.summary'),
}),
'scheduled-last-days': Flags.integer({
char: 'l',
deprecateAliases: true,
aliases: ['scheduledlastdays'],
summary: messages.getMessage('flags.scheduled-last-days.summary'),
}),
status: Flags.custom<Status>({
options: ['Created', 'Cancelled', 'Pending', 'In Progress', 'Failed', 'Succeeded'],
})({
char: 's',
summary: messages.getMessage('flags.status.summary'),
}),
verbose: Flags.boolean({
summary: messages.getMessage('flags.verbose.summary'),
}),
};

private connection!: Connection;

public async run(): Promise<PackagePushRequestListResultArr> {
const { flags } = await this.parse(PackagePushRequestListCommand);
this.connection = flags['target-dev-hub'].getConnection('61.0');

// Get results of query here
// Use const since we will add verbose later
const results = await PackagePushUpgrade.list(this.connection, {
packageId: flags.packageid!,
status: flags.status,
});

if (results.length === 0) {
this.warn('No results found');
} else {
// if (flags.verbose) {
// try {
// results = fetchVerboseData(results);
// } catch (err) {
// const errMsg = typeof err === 'string' ? err : err instanceof Error ? err.message : 'unknown error';
// this.warn(`error when retrieving verbose data due to: ${errMsg}`);
// }
// }

const data = results.map((record) => ({
PushRequestId: record?.PushRequestId,
PackageVersionId: record?.PackageVersionId,
PushRequestStatus: record?.PushRequestStatus,
PushRequestScheduledDateTime: 'test',
NumOrgsScheduled: 0,
NumOrgsUpgradedFail: 0,
NumOrgsUpgradedSuccess: 0,
}));

this.table({ data, overflow: 'wrap', title: chalk.blue(`Push Upgrade List: [${results.length}]`) });
}
return results;
}
}

// function fetchVerboseData(results: PackagePushRequestListResultArr): PackagePushRequestListResultArr {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we actually do check in let's not have commented out code. We will just check it in later if we need it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, will clean this up upon check in

// return results.map((result) => ({
// ...result,
// ...{
// PushUpgradeRequestCreatedDateTime: '',
// ActualUpgradeStartTime: '',
// ActualUpgradeEndTime: '',
// ActualDurationsOfPushUpgrades: 0,
// },
// }));
// }
Loading