Skip to content

Commit 0b89705

Browse files
Merge pull request #161 from codacy/fix-cli-update
fix: ensure cli update is called when params are available
2 parents d2ffa7f + ef93c65 commit 0b89705

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/cli/MacCodacyCli.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ export class MacCodacyCli extends CodacyCli {
3737
return
3838
}
3939

40+
protected async checkCLIMode(): Promise<string> {
41+
try {
42+
const cliConfig = fs.readFileSync(path.join(this.rootPath, CODACY_FOLDER_NAME, 'cli-config.yaml'), 'utf-8')
43+
return cliConfig.includes('mode: local') ? 'local' : 'remote'
44+
} catch (error) {
45+
throw new Error(`Failed to check CLI mode: ${error}`)
46+
}
47+
}
48+
49+
protected async validateIdentificationParameters(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+
4062
public async preflightCodacyCli(autoInstall: boolean): Promise<void> {
4163
// is there a command?
4264
if (!this.getCliCommand()) {
@@ -106,6 +128,11 @@ export class MacCodacyCli extends CodacyCli {
106128
const updateCommand = `${this.getCliCommand()} update`
107129
const resetCommand = `${this.getCliCommand()} config reset`
108130
try {
131+
const hasIdentificationParams = await this.validateIdentificationParameters(resetParams)
132+
if (!hasIdentificationParams) {
133+
Logger.debug('CLI mode is remote and no identification parameters provided. Skipping update and config reset.')
134+
return
135+
}
109136
await this.execAsync(updateCommand)
110137
await this.execAsync(resetCommand, resetParams)
111138

@@ -222,6 +249,11 @@ export class MacCodacyCli extends CodacyCli {
222249
const discoverParams = this.getIdentificationParameters()
223250

224251
try {
252+
const hasIdentificationParams = await this.validateIdentificationParameters(discoverParams)
253+
if (!hasIdentificationParams) {
254+
Logger.debug('CLI mode is remote and no identification parameters provided. Skipping config discover.')
255+
return
256+
}
225257
const { stdout, stderr } = await this.execAsync(
226258
`${this.getCliCommand()} config discover ${this.preparePathForExec(filePath)}`,
227259
discoverParams

0 commit comments

Comments
 (0)