Skip to content

Commit e0cb2a9

Browse files
committed
add support to choose tool
1 parent e48b55f commit e0cb2a9

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"displayName": "codacy-cli-integration",
44
"description": "",
55
"version": "0.0.1",
6+
"publisher": "Codacy",
67
"engines": {
78
"vscode": "^1.57.0"
89
},
@@ -23,23 +24,29 @@
2324
},
2425
"scripts": {
2526
"vscode:prepublish": "npm run compile",
27+
"vscode:prepublish2": "npm run -S esbuild-base -- --minify",
2628
"compile": "tsc -p ./",
2729
"watch": "tsc -watch -p ./",
2830
"pretest": "npm run compile && npm run lint",
2931
"lint": "eslint src --ext ts",
30-
"test": "node ./out/test/runTest.js"
32+
"test": "node ./out/test/runTest.js",
33+
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node",
34+
"esbuild": "npm run -S esbuild-base -- --sourcemap",
35+
"esbuild-watch": "npm run -S esbuild-base -- --sourcemap --watch",
36+
"test-compile": "tsc -p ./"
3137
},
3238
"devDependencies": {
33-
"@types/vscode": "^1.57.0",
3439
"@types/glob": "^7.1.3",
3540
"@types/mocha": "^8.2.2",
3641
"@types/node": "14.x",
37-
"eslint": "^7.27.0",
42+
"@types/vscode": "^1.57.0",
3843
"@typescript-eslint/eslint-plugin": "^4.26.0",
3944
"@typescript-eslint/parser": "^4.26.0",
45+
"esbuild": "^0.12.9",
46+
"eslint": "^7.27.0",
4047
"glob": "^7.1.7",
4148
"mocha": "^8.4.0",
4249
"typescript": "^4.3.2",
4350
"vscode-test": "^1.5.2"
4451
}
45-
}
52+
}

src/extension.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,48 @@ export function activate(context: vscode.ExtensionContext) {
88
let disposable = vscode.commands.registerCommand('codacy-cli-integration.runCodacyCli', () => {
99
vscode.window.showInformationMessage('Codacy CLI has been launched!');
1010

11-
11+
1212
if (vscode.workspace.workspaceFolders !== undefined && vscode.workspace.workspaceFolders.length > 0) {
1313
let configuration = vscode.workspace.getConfiguration("codacy-cli");
14-
const env: any = { env: { ...process.env } }
15-
let additionalParameters = []
14+
const env: any = { env: { ...process.env } };
15+
let additionalParameters = [];
1616
let diagnosticMap: Map<string, vscode.Diagnostic[]> = new Map();
1717

1818
//if user has api-token, it also needs to have 'provider', 'username' and 'project'
1919
if (configuration.has('api-token')) {
2020
if (configuration.has('provider') && configuration.has('username') && configuration.has('project')) {
21-
env.env['CODACY_API_TOKEN'] = configuration.get('api-token')
21+
env.env['CODACY_API_TOKEN'] = configuration.get('api-token');
2222
additionalParameters.push(`--provider ${configuration.get('provider')}`);
2323
additionalParameters.push(`--username ${configuration.get('username')}`);
2424
additionalParameters.push(`--project ${configuration.get('project')}`);
2525
} else {
2626
vscode.window.showErrorMessage('You have an api-token but no provider, username or project so CLI will not consider the token');
2727
}
2828
} else if (configuration.has('project-token')) {
29-
env.env['CODACY_PROJECT_TOKEN'] = configuration.get('project-token')
29+
env.env['CODACY_PROJECT_TOKEN'] = configuration.get('project-token');
30+
}
31+
32+
if (configuration.has('codacy-api-base-url')) {
33+
env.env['env.CODACY_API_BASE_URL'] = configuration.get('codacy-api-base-url');
3034
}
3135

32-
if(configuration.has('codacy-api-base-url')){
33-
env.env['env.CODACY_API_BASE_URL'] = configuration.get('codacy-api-base-url')
36+
if (configuration.has('tool')) {
37+
additionalParameters.push(`--tool ${configuration.get('tool')}`);
3438
}
3539

3640
for (let i = 0; i < vscode.workspace.workspaceFolders.length; i++) {
3741
let workspaceFolder = vscode.workspace.workspaceFolders[i].uri.path;
38-
env.env['CODACY_CODE'] = workspaceFolder
39-
const dockerCommand = `docker run --rm=true --env CODACY_CODE="$CODACY_CODE" --volume /var/run/docker.sock:/var/run/docker.sock --volume "$CODACY_CODE":"$CODACY_CODE" --volume /tmp:/tmp codacy/codacy-analysis-cli analyze --format sarif ${additionalParameters.join(' ')}`
40-
const cp = require('child_process')
42+
env.env['CODACY_CODE'] = workspaceFolder;
43+
const dockerCommand = `docker run --rm=true --env CODACY_CODE="$CODACY_CODE" --volume /var/run/docker.sock:/var/run/docker.sock --volume "$CODACY_CODE":"$CODACY_CODE" --volume /tmp:/tmp codacy/codacy-analysis-cli analyze --format sarif ${additionalParameters.join(' ')}`;
44+
const cp = require('child_process');
4145
cp.exec(
4246
dockerCommand,
4347
env,
4448
(err: any, stdout: string, stderr: string) => {
45-
if (err && err.code != 102) {
49+
if (err && err.code !== 102) {
4650
vscode.window.showErrorMessage(`Codacy CLI failed due to ${err.message}`);
4751
console.log('error: ' + err);
48-
return
52+
return;
4953
}
5054
let sarifReport = JSON.parse(stdout);
5155

@@ -64,21 +68,22 @@ export function activate(context: vscode.ExtensionContext) {
6468
});
6569

6670
});
71+
diagnosticCollection.clear();
6772
diagnosticMap.forEach((diags, file) => {
6873
diagnosticCollection.set(vscode.Uri.parse(file), diags);
6974
});
7075
});
7176
}
7277

7378

74-
}else {
79+
} else {
7580
vscode.window.showErrorMessage('There are no workspaces to analyze!');
7681
return;
7782
}
7883

7984

8085

81-
86+
8287
});
8388

8489
context.subscriptions.push(disposable);

0 commit comments

Comments
 (0)