Skip to content

Commit 2165bdb

Browse files
remove linux support & use repository from repositoryManager
1 parent 0c14ef7 commit 2165bdb

3 files changed

Lines changed: 20 additions & 25 deletions

File tree

src/commands/configureMCP.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export async function configureMCP(repository: Repository) {
270270

271271
vscode.window.showInformationMessage('Codacy MCP server added successfully')
272272
await createRules(repository)
273-
await installCodacyCLI()
273+
await installCodacyCLI(repository)
274274
} catch (error: unknown) {
275275
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'
276276
vscode.window.showErrorMessage(`Failed to configure MCP server: ${errorMessage}`)

src/commands/installAnalysisCLI.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import * as fs from 'fs'
44
import * as path from 'path'
55
import { exec } from 'child_process'
66
import { promisify } from 'util'
7-
import { parseGitRemote } from '../common/parseGitRemote'
87
import { Config } from '../common/config'
8+
import { Repository } from '../api/client'
99

1010
const execAsync = promisify(exec)
1111

@@ -27,25 +27,17 @@ async function isBrewInstalled(): Promise<boolean> {
2727
}
2828
}
2929

30-
async function initializeCLI(): Promise<void> {
30+
async function initializeCLI(repository: Repository): Promise<void> {
3131
const workspacePath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || ''
3232
const codacyYamlPath = path.join(workspacePath, '.codacy', 'codacy.yaml')
3333
const apiToken = Config.apiToken
3434

35-
const git = vscode.extensions.getExtension('vscode.git')?.exports.getAPI(1)
36-
const repo = git?.repositories[0]
37-
let provider, organization, repository
35+
const { provider, owner: organization, name: repositoryName } = repository
3836

39-
if (repo?.state.remotes[0]?.pushUrl) {
40-
const gitInfo = parseGitRemote(repo.state.remotes[0].pushUrl)
41-
provider = gitInfo.provider
42-
organization = gitInfo.organization
43-
repository = gitInfo.repository
44-
}
4537
try {
4638
if (!fs.existsSync(codacyYamlPath)) {
4739
await execAsync(
48-
`codacy-cli init --api-token ${apiToken} --provider ${provider} --organization ${organization} --repository ${repository}`
40+
`codacy-cli init --api-token ${apiToken} --provider ${provider} --organization ${organization} --repository ${repositoryName}`
4941
)
5042
}
5143
await execAsync('codacy-cli install')
@@ -57,11 +49,11 @@ async function initializeCLI(): Promise<void> {
5749
}
5850
}
5951

60-
export async function installCodacyCLI(): Promise<void> {
52+
export async function installCodacyCLI(repository: Repository): Promise<void> {
6153
const platform = os.platform()
6254

6355
if (await isCLIInstalled()) {
64-
await initializeCLI()
56+
await initializeCLI(repository)
6557
return
6658
}
6759

@@ -75,7 +67,9 @@ export async function installCodacyCLI(): Promise<void> {
7567
break
7668

7769
case 'linux':
78-
await execAsync('bash <(curl -Ls https://raw.githubusercontent.com/codacy/codacy-cli-v2/main/codacy-cli.sh)')
70+
throw new Error(
71+
'Codacy CLI cannot be automatically installed on Linux yet. For manual installation, please refer to the [Codacy CLI documentation](https://github.com/codacy/codacy-cli-v2).'
72+
)
7973
break
8074

8175
case 'win32':
@@ -85,7 +79,7 @@ export async function installCodacyCLI(): Promise<void> {
8579
throw new Error(`Unsupported operating system: ${platform}`)
8680
}
8781

88-
await initializeCLI()
82+
await initializeCLI(repository)
8983
} catch (error) {
9084
if (error instanceof Error) {
9185
throw new Error(`Failed to install Codacy CLI: ${error.message}`)

src/extension.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ export async function activate(context: vscode.ExtensionContext) {
9898
(vscode.env.appName.toLowerCase().includes('code') && !!vscode.extensions.getExtension('GitHub.copilot'))
9999
)
100100

101-
await vscode.commands.executeCommand(
102-
'setContext',
103-
'codacy:canInstallCLI',
104-
os.platform() === 'darwin' || os.platform() === 'linux'
105-
)
101+
await vscode.commands.executeCommand('setContext', 'codacy:canInstallCLI', os.platform() === 'darwin')
106102

107103
Config.init(context)
108104

@@ -208,9 +204,14 @@ export async function activate(context: vscode.ExtensionContext) {
208204
},
209205
async () => {
210206
try {
211-
await installCodacyCLI()
212-
await updateCLIState()
213-
vscode.window.showInformationMessage('Codacy CLI installed successfully!')
207+
const repository = repositoryManager.repository
208+
if (repository) {
209+
await installCodacyCLI(repository)
210+
await updateCLIState()
211+
vscode.window.showInformationMessage('Codacy CLI installed successfully!')
212+
} else {
213+
throw new Error('No repository found')
214+
}
214215
} catch (error) {
215216
vscode.window.showErrorMessage(
216217
`Failed to install Codacy CLI: ${error instanceof Error ? error.message : 'Unknown error'}`

0 commit comments

Comments
 (0)