@@ -4,8 +4,8 @@ import * as fs from 'fs'
44import * as path from 'path'
55import { exec } from 'child_process'
66import { promisify } from 'util'
7- import { parseGitRemote } from '../common/parseGitRemote'
87import { Config } from '../common/config'
8+ import { Repository } from '../api/client'
99
1010const 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 } ` )
0 commit comments