@@ -46,6 +46,19 @@ export class MacCodacyCli extends CodacyCli {
4646 }
4747 }
4848
49+ protected async hasIdentificationParams ( params : Record < string , string > = { } ) : Promise < boolean > {
50+ try {
51+ const cliMode = await this . checkCLIMode ( )
52+ if ( cliMode === 'remote' && Object . keys ( params ) . length === 0 ) {
53+ return false
54+ }
55+ return true
56+ } catch ( error ) {
57+ Logger . error ( `Failed to check identification parameters: ${ error } ` )
58+ return false
59+ }
60+ }
61+
4962 public async preflightCodacyCli ( autoInstall : boolean ) : Promise < void > {
5063 // is there a command?
5164 if ( ! this . getCliCommand ( ) ) {
@@ -115,12 +128,12 @@ export class MacCodacyCli extends CodacyCli {
115128 const updateCommand = `${ this . getCliCommand ( ) } update`
116129 const resetCommand = `${ this . getCliCommand ( ) } config reset`
117130 try {
118- await this . execAsync ( updateCommand )
119- const cliMode = await this . checkCLIMode ( )
120- if ( cliMode === 'remote' && Object . keys ( resetParams ) . length === 0 ) {
121- Logger . debug ( 'CLI mode is remote and no identification parameters provided. Skipping config reset.' )
131+ const hasIdentificationParams = await this . hasIdentificationParams ( resetParams )
132+ if ( ! hasIdentificationParams ) {
133+ Logger . debug ( 'CLI mode is remote and no identification parameters provided. Skipping update and config reset.' )
122134 return
123135 }
136+ await this . execAsync ( updateCommand )
124137 await this . execAsync ( resetCommand , resetParams )
125138
126139 // Initialize codacy-cli after update
@@ -236,8 +249,8 @@ export class MacCodacyCli extends CodacyCli {
236249 const discoverParams = this . getIdentificationParameters ( )
237250
238251 try {
239- const cliMode = await this . checkCLIMode ( )
240- if ( cliMode === 'remote' && Object . keys ( discoverParams ) . length === 0 ) {
252+ const hasIdentificationParams = await this . hasIdentificationParams ( discoverParams )
253+ if ( ! hasIdentificationParams ) {
241254 Logger . debug ( 'CLI mode is remote and no identification parameters provided. Skipping config discover.' )
242255 return
243256 }
0 commit comments