@@ -23,6 +23,12 @@ export class MacCodacyCli extends CodacyCli {
2323
2424 if ( fs . existsSync ( fullPath ) ) {
2525 this . setCliCommand ( this . _cliVersion ? `CODACY_CLI_V2_VERSION=${ this . _cliVersion } ${ localPath } ` : localPath )
26+
27+ // CLI found, update it if necessary
28+ if ( ! this . _cliVersion ) {
29+ await this . update ( )
30+ }
31+
2632 return
2733 }
2834
@@ -96,16 +102,7 @@ export class MacCodacyCli extends CodacyCli {
96102 }
97103
98104 public async update ( ) : Promise < void > {
99- const resetParams = (
100- this . _accountToken && this . repository && this . provider && this . organization
101- ? {
102- provider : this . provider ,
103- organization : this . organization ,
104- repository : this . repository ,
105- 'api-token' : this . _accountToken ,
106- }
107- : { }
108- ) as Record < string , string >
105+ const resetParams = this . getIdentificationParameters ( )
109106 const updateCommand = `${ this . getCliCommand ( ) } update`
110107 const resetCommand = `${ this . getCliCommand ( ) } config reset`
111108 try {
@@ -148,19 +145,11 @@ export class MacCodacyCli extends CodacyCli {
148145 // install dependencies
149146 await this . installDependencies ( )
150147 Logger . debug ( 'Dev mode enabled. Skipping initialization.' )
148+ return
151149 }
152150
153151 if ( needsInitialization ) {
154- const initParams = (
155- this . _accountToken && this . repository && this . provider && this . organization
156- ? {
157- provider : this . provider ,
158- organization : this . organization ,
159- repository : this . repository ,
160- 'api-token' : this . _accountToken ,
161- }
162- : { }
163- ) as Record < string , string >
152+ const initParams = this . getIdentificationParameters ( )
164153
165154 try {
166155 // initialize codacy-cli
@@ -230,9 +219,12 @@ export class MacCodacyCli extends CodacyCli {
230219
231220 Logger . debug ( `Running Codacy CLI config discover for ${ filePath } ` )
232221
222+ const discoverParams = this . getIdentificationParameters ( )
223+
233224 try {
234225 const { stdout, stderr } = await this . execAsync (
235- `${ this . getCliCommand ( ) } config discover ${ this . preparePathForExec ( filePath ) } `
226+ `${ this . getCliCommand ( ) } config discover ${ this . preparePathForExec ( filePath ) } ` ,
227+ discoverParams
236228 )
237229
238230 if ( stderr ) {
0 commit comments