Skip to content

Commit 42e362b

Browse files
chore: update Codacy configuration and refactor runtime version handling
- Add Flutter runtime to Codacy configuration - Upgrade ESLint version in tools - Refactor runtime version retrieval to use embedded filesystem - Remove deprecated getRuntimeVersions function and replace with plugins.GetRuntimeVersions - Ensure default version is included in plugin configuration structure
1 parent e0a847e commit 42e362b

3 files changed

Lines changed: 50 additions & 52 deletions

File tree

.codacy/codacy.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
runtimes:
2-
- node@22.2.0
3-
- python@3.11.11
42
- dart@3.7.2
3+
- flutter@3.7.2
54
- java@17.0.10
5+
- node@22.2.0
6+
- python@3.11.11
67
tools:
7-
- eslint@8.57.0
8-
- trivy@0.59.1
9-
- pylint@3.3.6
10-
- pmd@6.55.0
11-
- semgrep@1.78.0
128
- dartanalyzer@3.7.2
9+
- eslint@9.3.0
1310
- lizard@1.17.19
14-
- codacy-enigma-cli@0.0.1-main.8.49310c3
11+
- pmd@6.55.0
12+
- pylint@3.3.6
13+
- semgrep@1.78.0
14+
- trivy@0.59.1

cmd/init.go

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"time"
2222

2323
"github.com/spf13/cobra"
24-
"gopkg.in/yaml.v3"
2524
)
2625

2726
const CodacyApiBase = "https://app.codacy.com"
@@ -152,44 +151,6 @@ type RuntimePluginConfig struct {
152151
DefaultVersion string `yaml:"default_version"`
153152
}
154153

155-
func getRuntimeVersions() map[string]string {
156-
versions := make(map[string]string)
157-
158-
// Read the runtimes directory
159-
entries, err := os.ReadDir("plugins/runtimes")
160-
if err != nil {
161-
log.Printf("Warning: Could not read runtimes directory: %v", err)
162-
return versions
163-
}
164-
165-
// Process each runtime directory
166-
for _, entry := range entries {
167-
if !entry.IsDir() {
168-
continue
169-
}
170-
171-
runtime := entry.Name()
172-
pluginPath := fmt.Sprintf("plugins/runtimes/%s/plugin.yaml", runtime)
173-
data, err := os.ReadFile(pluginPath)
174-
if err != nil {
175-
log.Printf("Warning: Could not read plugin file for runtime %s: %v", runtime, err)
176-
continue
177-
}
178-
179-
var config RuntimePluginConfig
180-
if err := yaml.Unmarshal(data, &config); err != nil {
181-
log.Printf("Warning: Could not parse plugin file for runtime %s: %v", runtime, err)
182-
continue
183-
}
184-
185-
if config.DefaultVersion != "" {
186-
versions[runtime] = config.DefaultVersion
187-
}
188-
}
189-
190-
return versions
191-
}
192-
193154
func configFileTemplate(tools []tools.Tool) string {
194155
// Maps to track which tools are enabled
195156
toolsMap := make(map[string]bool)
@@ -210,7 +171,7 @@ func configFileTemplate(tools []tools.Tool) string {
210171
}
211172

212173
// Get runtime versions all at once
213-
runtimeVersions := getRuntimeVersions()
174+
runtimeVersions := plugins.GetRuntimeVersions()
214175

215176
// Build map of enabled tools with their versions
216177
for _, tool := range tools {

plugins/runtime-utils.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ type binaryPath struct {
2929

3030
// pluginConfig holds the structure of the plugin.yaml file
3131
type pluginConfig struct {
32-
Name string `yaml:"name"`
33-
Description string `yaml:"description"`
34-
Download downloadConfig `yaml:"download"`
35-
Binaries []binary `yaml:"binaries"`
32+
Name string `yaml:"name"`
33+
Description string `yaml:"description"`
34+
Download downloadConfig `yaml:"download"`
35+
Binaries []binary `yaml:"binaries"`
36+
DefaultVersion string `yaml:"default_version"`
3637
}
3738

3839
// downloadConfig holds the download configuration from the plugin.yaml
@@ -306,3 +307,39 @@ func (p *runtimePlugin) getMappedOS(goos string) string {
306307
// Return the original OS if no mapping exists
307308
return goos
308309
}
310+
311+
// GetRuntimeVersions returns a map of runtime names to their default versions
312+
func GetRuntimeVersions() map[string]string {
313+
versions := make(map[string]string)
314+
315+
// Read the runtimes directory from embedded filesystem
316+
entries, err := pluginsFS.ReadDir("runtimes")
317+
if err != nil {
318+
return versions
319+
}
320+
321+
// Process each runtime directory
322+
for _, entry := range entries {
323+
if !entry.IsDir() {
324+
continue
325+
}
326+
327+
runtime := entry.Name()
328+
pluginPath := fmt.Sprintf("runtimes/%s/plugin.yaml", runtime)
329+
data, err := pluginsFS.ReadFile(pluginPath)
330+
if err != nil {
331+
continue
332+
}
333+
334+
var config pluginConfig
335+
if err := yaml.Unmarshal(data, &config); err != nil {
336+
continue
337+
}
338+
339+
if config.DefaultVersion != "" {
340+
versions[runtime] = config.DefaultVersion
341+
}
342+
}
343+
344+
return versions
345+
}

0 commit comments

Comments
 (0)