6
6
*/
7
7
8
8
import { Flags , loglevel , orgApiVersionFlagWithDeprecations , SfCommand } from '@salesforce/sf-plugins-core' ;
9
- import { Messages } from '@salesforce/core' ;
9
+ import { Messages , Org , Logger } from '@salesforce/core' ;
10
+ import chalk from 'chalk' ;
10
11
11
12
import {
12
13
PackagePushUpgrade ,
13
14
PackagePushRequestReportResult ,
14
15
PackagePushRequestReportJobFailuresResult ,
15
16
} from '@salesforce/packaging' ;
16
- import chalk from 'chalk' ;
17
17
import { requiredHubFlag } from '../../../utils/hubFlag.js' ;
18
18
19
19
Messages . importMessagesDirectoryFromMetaUrl ( import . meta. url ) ;
20
20
const messages = Messages . loadMessages ( '@salesforce/plugin-packaging' , 'package_pushupgrade_report' ) ;
21
21
const ERROR_LIMIT = 12 ;
22
22
23
- export type ReportCommandResult = null | PackagePushRequestReportResult ;
23
+ export type ReportCommandResult = PackagePushRequestReportResult | null ;
24
24
25
25
export class PackagePushUpgradeReportCommand extends SfCommand < ReportCommandResult > {
26
26
public static readonly summary = messages . getMessage ( 'summary' ) ;
@@ -29,12 +29,11 @@ export class PackagePushUpgradeReportCommand extends SfCommand<ReportCommandResu
29
29
public static readonly deprecateAliases = true ;
30
30
public static readonly aliases = [ 'force:package:pushupgrade:report' ] ;
31
31
public static readonly hidden = true ;
32
- public static state = 'beta' ;
32
+ public static readonly state = 'beta' ;
33
33
public static readonly flags = {
34
34
loglevel,
35
35
'target-dev-hub' : requiredHubFlag ,
36
36
'api-version' : orgApiVersionFlagWithDeprecations ,
37
- // eslint-disable-next-line sf-plugin/id-flag-suggestions
38
37
'push-request-id' : Flags . salesforceId ( {
39
38
length : 'both' ,
40
39
deprecateAliases : true ,
@@ -47,34 +46,41 @@ export class PackagePushUpgradeReportCommand extends SfCommand<ReportCommandResu
47
46
48
47
public async run ( ) : Promise < ReportCommandResult > {
49
48
const { flags } = await this . parse ( PackagePushUpgradeReportCommand ) ;
50
- const connection = flags [ 'target-dev-hub' ] . getConnection ( flags [ 'api-version' ] ) ;
49
+ const logger = await Logger . child ( this . constructor . name ) ;
50
+ const hubOrg = flags [ 'target-dev-hub' ] as Org ;
51
+ const connection = hubOrg . getConnection ( flags [ 'api-version' ] ) ;
52
+
53
+ const packagePushRequestOptions = { packagePushRequestId : flags [ 'push-request-id' ] as string } ;
51
54
52
- const packagePushRequestOptions = { packagePushRequestId : flags [ 'push-request-id' ] } ;
55
+ logger . debug (
56
+ `Querying PackagePushRequestReport records from org ${ hubOrg ?. getOrgId ( ) } using PackagePushRequest ID: ${ packagePushRequestOptions . packagePushRequestId } `
57
+ ) ;
58
+ const records : PackagePushRequestReportResult [ ] = await PackagePushUpgrade . report ( connection , packagePushRequestOptions ) ;
53
59
54
- const records = await PackagePushUpgrade . report ( connection , packagePushRequestOptions ) ;
55
60
if ( records ?. length === 1 ) {
56
- const record = records [ 0 ] ;
61
+ const record : PackagePushRequestReportResult = records [ 0 ] ;
62
+
63
+ logger . debug ( `Found PackagePushRequestReport record: ${ record ?. Id } ` ) ;
57
64
58
- const totalJobs = await PackagePushUpgrade . getTotalJobs ( connection , packagePushRequestOptions ) ;
65
+ const totalJobs : number = await PackagePushUpgrade . getTotalJobs ( connection , packagePushRequestOptions ) ;
59
66
60
67
let failedJobs = 0 ;
61
68
let succeededJobs = 0 ;
62
- let jobFailureReasons ;
69
+ let jobFailureReasons : PackagePushRequestReportJobFailuresResult [ ] | undefined ;
63
70
64
71
if ( record ?. Status === 'Succeeded' || record ?. Status === 'Failed' || record ?. Status === 'In Progress' ) {
65
- failedJobs = await PackagePushUpgrade . getFailedJobs ( connection , packagePushRequestOptions ) ;
66
- succeededJobs = await PackagePushUpgrade . getSucceededJobs ( connection , packagePushRequestOptions ) ;
67
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
72
+ logger . debug ( `PushRequest Status is ${ record . Status } , getting job details.` ) ;
73
+ failedJobs = await PackagePushUpgrade . getFailedJobs ( connection , packagePushRequestOptions ) as number ;
74
+ succeededJobs = await PackagePushUpgrade . getSucceededJobs ( connection , packagePushRequestOptions ) as number ;
68
75
jobFailureReasons = await PackagePushUpgrade . getJobFailureReasons ( connection , packagePushRequestOptions ) ;
69
76
}
70
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
71
- this . display ( records [ 0 ] , totalJobs , succeededJobs , failedJobs , jobFailureReasons ) ;
77
+ this . display ( record , totalJobs , succeededJobs , failedJobs , jobFailureReasons ) ;
72
78
return record ;
73
79
}
80
+ this . warn ( 'No results found' ) ;
74
81
return null ;
75
82
}
76
83
77
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
78
84
private display (
79
85
record : PackagePushRequestReportResult ,
80
86
totalJobs : number ,
@@ -85,17 +91,14 @@ export class PackagePushUpgradeReportCommand extends SfCommand<ReportCommandResu
85
91
const data = [
86
92
{
87
93
name : 'Package Name' ,
88
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
89
94
value : record . PackageVersion . MetadataPackage . Name ,
90
95
} ,
91
96
{
92
97
name : 'Package Version Name' ,
93
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
94
98
value : record . PackageVersion . Name ,
95
99
} ,
96
100
{
97
101
name : 'Package Version' ,
98
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
99
102
value : record . PackageVersion . MajorVersion + '.' + record . PackageVersion . MinorVersion ,
100
103
} ,
101
104
{
@@ -148,20 +151,17 @@ export class PackagePushUpgradeReportCommand extends SfCommand<ReportCommandResu
148
151
} ,
149
152
] ;
150
153
151
- this . table ( { data, title : chalk . blue ( 'Push Upgrade Request' ) } ) ;
154
+ this . table ( { data } ) ;
152
155
153
156
if ( jobFailureReasons ?. length ) {
154
157
this . log ( '' ) ;
155
158
const errors : string [ ] = [ ] ;
156
159
jobFailureReasons . slice ( 0 , ERROR_LIMIT ) . forEach ( ( error : PackagePushRequestReportJobFailuresResult ) => {
157
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
158
160
errors . push ( `(${ errors . length + 1 } ) ${ error . ErrorMessage } ` ) ;
159
161
} ) ;
160
162
this . styledHeader ( chalk . red ( 'Errors' ) ) ;
161
163
this . warn ( errors . join ( '\n' ) ) ;
162
164
163
- // Check if errors were truncated. If so, inform the user with
164
- // instructions on how to retrieve the remaining errors.
165
165
if ( jobFailureReasons ?. length > ERROR_LIMIT ) {
166
166
this . warn ( messages . getMessage ( 'truncatedErrors' , [ this . config . bin , record . Id ] ) ) ;
167
167
}
0 commit comments