@sonar-autofix/cli 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +132 -0
- package/package.json +23 -0
package/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// CLI entry point for Sonar Autofix
|
|
3
|
+
const CoreOrchestrator = require('@sonar-autofix/core');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* CLI interface for the Sonar Autofix tool
|
|
9
|
+
* Supports configuration via JSON file and/or environment variables.
|
|
10
|
+
*/
|
|
11
|
+
async function main() {
|
|
12
|
+
console.log('Sonar Autofix CLI');
|
|
13
|
+
console.log('=========================');
|
|
14
|
+
|
|
15
|
+
// Parse command line arguments
|
|
16
|
+
const args = process.argv.slice(2);
|
|
17
|
+
|
|
18
|
+
// Handle help
|
|
19
|
+
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
|
20
|
+
console.log('');
|
|
21
|
+
console.log('This tool automatically fixes Sonar issues using LLMs.');
|
|
22
|
+
console.log('');
|
|
23
|
+
console.log('Usage:');
|
|
24
|
+
console.log(' npx sonar-autofix --config <path> [options]');
|
|
25
|
+
console.log('');
|
|
26
|
+
console.log('Options:');
|
|
27
|
+
console.log(' --help, -h Show this help message');
|
|
28
|
+
console.log(' --version, -v Show version information');
|
|
29
|
+
console.log(' --config <path> Path to configuration JSON file');
|
|
30
|
+
console.log(' --dry-run Run without making changes');
|
|
31
|
+
console.log('');
|
|
32
|
+
console.log('Environment Variables:');
|
|
33
|
+
console.log(' SONAR_HOST SonarQube/SonarCloud host URL');
|
|
34
|
+
console.log(' SONAR_PROJECT Sonar project key');
|
|
35
|
+
console.log(' SONAR_TOKEN Sonar authentication token');
|
|
36
|
+
console.log(' LLM_PROVIDER LLM provider (lmstudio, openai, azure, anthropic, ollama, openrouter)');
|
|
37
|
+
console.log(' LLM_ENDPOINT LLM API endpoint URL');
|
|
38
|
+
console.log(' LLM_MODEL LLM model name');
|
|
39
|
+
console.log(' LLM_API_KEY LLM API key');
|
|
40
|
+
console.log(' GIT_BRANCH Branch name for autofix commits (default: sonar-autofix)');
|
|
41
|
+
console.log('');
|
|
42
|
+
console.log('Environment variables override config file values.');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Handle version
|
|
47
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
48
|
+
console.log('sonar-autofix v0.0.1');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Handle dry-run flag
|
|
53
|
+
const dryRun = args.includes('--dry-run');
|
|
54
|
+
|
|
55
|
+
// Load configuration from file
|
|
56
|
+
let config = {};
|
|
57
|
+
const configIndex = args.indexOf('--config');
|
|
58
|
+
if (configIndex !== -1 && configIndex + 1 < args.length) {
|
|
59
|
+
const configPath = args[configIndex + 1];
|
|
60
|
+
try {
|
|
61
|
+
const configFileContent = fs.readFileSync(path.resolve(configPath), 'utf8');
|
|
62
|
+
config = JSON.parse(configFileContent);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error('❌ Failed to read configuration file:', error.message);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Apply environment variable overrides
|
|
70
|
+
if (process.env.SONAR_HOST || process.env.SONAR_PROJECT || process.env.SONAR_TOKEN) {
|
|
71
|
+
config.sonar = config.sonar || {};
|
|
72
|
+
if (process.env.SONAR_HOST) config.sonar.host = process.env.SONAR_HOST;
|
|
73
|
+
if (process.env.SONAR_PROJECT) config.sonar.project = process.env.SONAR_PROJECT;
|
|
74
|
+
if (process.env.SONAR_TOKEN) config.sonar.token = process.env.SONAR_TOKEN;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (process.env.LLM_PROVIDER || process.env.LLM_ENDPOINT || process.env.LLM_MODEL || process.env.LLM_API_KEY) {
|
|
78
|
+
config.llm = config.llm || {};
|
|
79
|
+
if (process.env.LLM_PROVIDER) config.llm.provider = process.env.LLM_PROVIDER;
|
|
80
|
+
if (process.env.LLM_ENDPOINT) config.llm.endpoint = process.env.LLM_ENDPOINT;
|
|
81
|
+
if (process.env.LLM_MODEL) config.llm.model = process.env.LLM_MODEL;
|
|
82
|
+
if (process.env.LLM_API_KEY) config.llm.apiKey = process.env.LLM_API_KEY;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (process.env.GIT_BRANCH) {
|
|
86
|
+
config.git = config.git || {};
|
|
87
|
+
config.git.branch = process.env.GIT_BRANCH;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Apply dry-run
|
|
91
|
+
if (dryRun) {
|
|
92
|
+
config.dryRun = true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Validate required configuration
|
|
96
|
+
if (!config.sonar?.project) {
|
|
97
|
+
console.error('❌ Missing required configuration: sonar.project (or SONAR_PROJECT env var)');
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
if (!config.sonar?.token) {
|
|
101
|
+
console.error('❌ Missing required configuration: sonar.token (or SONAR_TOKEN env var)');
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
if (!config.llm?.provider) {
|
|
105
|
+
console.error('❌ Missing required configuration: llm.provider (or LLM_PROVIDER env var)');
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Run the core orchestrator
|
|
110
|
+
try {
|
|
111
|
+
const orchestrator = new CoreOrchestrator(config);
|
|
112
|
+
|
|
113
|
+
console.log('🚀 Starting Sonar Autofix...');
|
|
114
|
+
if (dryRun) {
|
|
115
|
+
console.log(' (dry-run mode — no changes will be made)');
|
|
116
|
+
}
|
|
117
|
+
const summary = await orchestrator.run();
|
|
118
|
+
|
|
119
|
+
console.log('✅ Done!');
|
|
120
|
+
return summary;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error('❌ Error:', error.message);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Run the CLI if this file is executed directly
|
|
128
|
+
if (require.main === module) {
|
|
129
|
+
main();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = { main };
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sonar-autofix/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "CLI tool for the Sonar Autofix tool",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"sonar-autofix": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"sonar",
|
|
14
|
+
"autofix",
|
|
15
|
+
"github",
|
|
16
|
+
"cli"
|
|
17
|
+
],
|
|
18
|
+
"author": "Sonar Autofix Team",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@sonar-autofix/core": "^0.0.1"
|
|
22
|
+
}
|
|
23
|
+
}
|