Skip to content

Commit a5e980d

Browse files
committed
feat: Call cli discover reset on startup CF-2031
This CLI call is only ever invoked on CLI update, but it ensures tools are automatically up to gate's standards
1 parent 22dc4a0 commit a5e980d

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/cli/CodacyCli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export abstract class CodacyCli {
3838
public abstract analyze(options: { file?: string; tool?: string }): Promise<ProcessedSarifResult[] | null>
3939

4040
public abstract configDiscover(filePath: string): Promise<void>
41+
42+
public abstract configReset(): Promise<void>
4143

4244
public getCliCommand(): string {
4345
return this._cliCommand

src/cli/MacCodacyCli.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,16 @@ export class MacCodacyCli extends CodacyCli {
276276
}
277277
}
278278
}
279+
280+
public async configReset(): Promise<void> {
281+
const resetCommand = `${this.getCliCommand()} config reset`
282+
const resetParams = this.getIdentificationParameters()
283+
284+
const hasIdentificationParams = await this.validateIdentificationParameters(resetParams)
285+
if (!hasIdentificationParams) {
286+
Logger.debug('CLI mode is remote and no identification parameters provided. Skipping update and config reset.')
287+
return
288+
}
289+
await this.execAsync(resetCommand, resetParams)
290+
}
279291
}

src/cli/WinCodacyCli.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ export class WinCodacyCli extends CodacyCli {
3535
public configDiscover(_filePath: string): Promise<void> {
3636
throw new Error(NOT_SUPPORTED)
3737
}
38+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
39+
public configReset(): Promise<void> {
40+
throw new Error(NOT_SUPPORTED)
41+
}
3842
}

src/cli/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export class Cli {
8383

8484
// set Cli command if found
8585
await this.cliInstance.preflightCodacyCli(false)
86+
87+
// check for an already installed CLI to update tools config
88+
await this.cliInstance.configReset()
8689

8790
return this.cliInstance
8891
}

0 commit comments

Comments
 (0)