Skip to content

Commit d2ffa7f

Browse files
authored
fix: fix CLI update and discover commands (#160)
* fix: run update when CLI is found * fix: fix discover issue with lack of account parameters
1 parent dee7a1e commit d2ffa7f

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

src/cli/CodacyCli.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ export abstract class CodacyCli {
5151
return path
5252
}
5353

54+
protected getIdentificationParameters(): Record<string, string> {
55+
return (
56+
this._accountToken && this.repository && this.provider && this.organization
57+
? {
58+
provider: this.provider,
59+
organization: this.organization,
60+
repository: this.repository,
61+
'api-token': this._accountToken,
62+
}
63+
: {}
64+
) as Record<string, string>
65+
}
66+
5467
protected execAsync(command: string, args?: Record<string, string>): Promise<{ stdout: string; stderr: string }> {
5568
// stringyfy the args
5669
const argsString = Object.entries(args || {})

src/cli/MacCodacyCli.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

src/extension.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,6 @@ export async function activate(context: vscode.ExtensionContext) {
340340
})
341341
)
342342

343-
const analysisMode = vscode.workspace.getConfiguration().get('codacy.cli.analysisMode')
344-
const cliVersion = vscode.workspace.getConfiguration().get('codacy.cli.cliVersion')
345-
// When the user doesn't have a specific version, update the CLI to the latest version
346-
if (!cliVersion && codacyCloud.cli?.getCliCommand() && analysisMode !== 'disabled') {
347-
await codacyCloud.cli.update()
348-
// If it is not installed, don't do anything. On the next usage of the CLI it will be installed with the most recent version
349-
}
350-
351343
// Identify user if already authenticated
352344
if (Config.apiToken) {
353345
try {

0 commit comments

Comments
 (0)