@sonar-autofix/github-action 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.
Files changed (3) hide show
  1. package/action.yml +71 -0
  2. package/index.js +86 -0
  3. package/package.json +17 -0
package/action.yml ADDED
@@ -0,0 +1,71 @@
1
+ name: 'Sonar Autofix'
2
+ description: 'Automatically fix SonarQube/SonarCloud issues using LLMs'
3
+ author: 'Sonar Autofix Team'
4
+
5
+ inputs:
6
+ sonar-host:
7
+ description: 'SonarQube/SonarCloud host URL'
8
+ required: false
9
+ default: 'https://sonarcloud.io'
10
+ sonar-project:
11
+ description: 'Sonar project key'
12
+ required: true
13
+ sonar-token:
14
+ description: 'Sonar authentication token'
15
+ required: true
16
+ llm-provider:
17
+ description: 'LLM provider (lmstudio, openai, azure, anthropic, ollama, openrouter)'
18
+ required: false
19
+ default: 'lmstudio'
20
+ llm-endpoint:
21
+ description: 'LLM API endpoint URL'
22
+ required: true
23
+ llm-model:
24
+ description: 'LLM model name'
25
+ required: true
26
+ llm-api-key:
27
+ description: 'LLM API key'
28
+ required: false
29
+ default: ''
30
+ git-branch:
31
+ description: 'Branch name for autofix commits'
32
+ required: false
33
+ default: 'sonar-autofix'
34
+ max-iterations:
35
+ description: 'Maximum number of fix iterations'
36
+ required: false
37
+ default: '5'
38
+ max-retries:
39
+ description: 'Maximum retries per file fix'
40
+ required: false
41
+ default: '3'
42
+ dry-run:
43
+ description: 'Run without making changes'
44
+ required: false
45
+ default: 'false'
46
+ build-commands:
47
+ description: 'Build commands (JSON array)'
48
+ required: false
49
+ default: '["npm run build"]'
50
+ lint-commands:
51
+ description: 'Lint commands (JSON array)'
52
+ required: false
53
+ default: '["npm run lint"]'
54
+ test-commands:
55
+ description: 'Test commands (JSON array)'
56
+ required: false
57
+ default: '["npm test"]'
58
+
59
+ outputs:
60
+ files-fixed:
61
+ description: 'Number of files fixed'
62
+ iterations:
63
+ description: 'Number of iterations performed'
64
+
65
+ runs:
66
+ using: 'node20'
67
+ main: 'index.js'
68
+
69
+ branding:
70
+ icon: 'check-circle'
71
+ color: 'green'
package/index.js ADDED
@@ -0,0 +1,86 @@
1
+ // GitHub Action entry point for Sonar Autofix
2
+ const CoreOrchestrator = require('@sonar-autofix/core');
3
+
4
+ /**
5
+ * Read a GitHub Action input value.
6
+ * In a real GitHub Actions environment, inputs are exposed as INPUT_<NAME> environment variables.
7
+ */
8
+ function getInput(name, required = false) {
9
+ const envKey = `INPUT_${name.replace(/-/g, '_').toUpperCase()}`;
10
+ const value = process.env[envKey] || '';
11
+ if (required && !value) {
12
+ throw new Error(`Missing required input: ${name}`);
13
+ }
14
+ return value;
15
+ }
16
+
17
+ /**
18
+ * Set a GitHub Action output value.
19
+ */
20
+ function setOutput(name, value) {
21
+ if (process.env.GITHUB_OUTPUT) {
22
+ const fs = require('fs');
23
+ fs.appendFileSync(process.env.GITHUB_OUTPUT, `${name}=${value}\n`);
24
+ } else {
25
+ console.log(`::set-output name=${name}::${value}`);
26
+ }
27
+ }
28
+
29
+ /**
30
+ * GitHub Action entry point
31
+ */
32
+ async function run() {
33
+ console.log('Sonar Autofix GitHub Action');
34
+ console.log('===================================');
35
+
36
+ try {
37
+ // Read action inputs (from action.yml)
38
+ const config = {
39
+ sonar: {
40
+ host: getInput('sonar-host') || 'https://sonarcloud.io',
41
+ project: getInput('sonar-project', true),
42
+ token: getInput('sonar-token', true),
43
+ },
44
+ llm: {
45
+ provider: getInput('llm-provider') || 'lmstudio',
46
+ endpoint: getInput('llm-endpoint', true),
47
+ model: getInput('llm-model', true),
48
+ apiKey: getInput('llm-api-key') || undefined,
49
+ },
50
+ git: {
51
+ branch: getInput('git-branch') || 'sonar-autofix',
52
+ },
53
+ retry: {
54
+ maxIterations: parseInt(getInput('max-iterations') || '5', 10),
55
+ maxRetries: parseInt(getInput('max-retries') || '3', 10),
56
+ },
57
+ validation: {
58
+ build: JSON.parse(getInput('build-commands') || '["npm run build"]'),
59
+ lint: JSON.parse(getInput('lint-commands') || '["npm run lint"]'),
60
+ tests: JSON.parse(getInput('test-commands') || '["npm test"]'),
61
+ },
62
+ dryRun: getInput('dry-run') === 'true',
63
+ };
64
+
65
+ const orchestrator = new CoreOrchestrator(config);
66
+
67
+ console.log('🚀 Starting Sonar Autofix GitHub Action...');
68
+ const summary = await orchestrator.run();
69
+
70
+ // Set outputs
71
+ setOutput('files-fixed', summary.totalFixed);
72
+ setOutput('iterations', summary.iterations);
73
+
74
+ console.log('✅ Done!');
75
+ } catch (error) {
76
+ console.error(`::error::${error.message}`);
77
+ process.exit(1);
78
+ }
79
+ }
80
+
81
+ // Run the GitHub Action if this file is executed directly
82
+ if (require.main === module) {
83
+ run();
84
+ }
85
+
86
+ module.exports = { run };
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@sonar-autofix/github-action",
3
+ "version": "0.0.1",
4
+ "description": "GitHub Action wrapper for the Sonar Autofix tool",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "sonar",
11
+ "autofix",
12
+ "github",
13
+ "action"
14
+ ],
15
+ "author": "Sonar Autofix Team",
16
+ "license": "MIT"
17
+ }