Skip to content

Commit 945dc88

Browse files
authored
fix: listing tools and patterns should allow disabled ones too (#170)
* fix: listing tools and patterns should allow disabled ones too * bumplizard and trivy versions on codacy.yaml
1 parent 73051d7 commit 945dc88

16 files changed

Lines changed: 27 additions & 23 deletions

File tree

.codacy/codacy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ tools:
88
- codacy-enigma-cli@0.0.1-main.8.49310c3
99
- dartanalyzer@3.7.2
1010
- eslint@8.57.0
11-
- lizard@1.17.19
11+
- lizard@1.17.31
1212
- pmd@6.55.0
1313
- pylint@3.3.6
1414
- revive@1.7.0
1515
- semgrep@1.78.0
16-
- trivy@0.59.1
16+
- trivy@0.65.0

cmd/analyze.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func init() {
237237
rootCmd.AddCommand(analyzeCmd)
238238
}
239239

240-
func loadsToolAndPatterns(toolName string) (domain.Tool, []domain.PatternConfiguration) {
240+
func loadsToolAndPatterns(toolName string, onlyEnabledPatterns bool) (domain.Tool, []domain.PatternConfiguration) {
241241
var toolsResponse, err = codacyclient.GetToolsVersions()
242242
if err != nil {
243243
fmt.Println("Error:", err)
@@ -251,7 +251,7 @@ func loadsToolAndPatterns(toolName string) (domain.Tool, []domain.PatternConfigu
251251
}
252252
}
253253
var patterns []domain.PatternConfiguration
254-
patterns, err = codacyclient.GetDefaultToolPatternsConfig(domain.InitFlags{}, tool.Uuid)
254+
patterns, err = codacyclient.GetDefaultToolPatternsConfig(domain.InitFlags{}, tool.Uuid, onlyEnabledPatterns)
255255
if err != nil {
256256
fmt.Println("Error:", err)
257257
return domain.Tool{}, []domain.PatternConfiguration{}

cmd/configsetup/setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func CreateToolConfigurationFile(toolName string, flags domain.InitFlags) error
481481
return fmt.Errorf("tool '%s' not found in supported tools", toolName)
482482
}
483483

484-
patternsConfig, err := codacyclient.GetDefaultToolPatternsConfig(flags, toolUuid)
484+
patternsConfig, err := codacyclient.GetDefaultToolPatternsConfig(flags, toolUuid, true)
485485
if err != nil {
486486
return fmt.Errorf("failed to get default patterns: %w", err)
487487
}
@@ -734,7 +734,7 @@ func createDefaultConfigurationsForSpecificTools(discoveredToolNames map[string]
734734
// createToolConfigurationsForUUIDs creates tool configurations for specific UUIDs
735735
func createToolConfigurationsForUUIDs(uuids []string, toolsConfigDir string, initFlags domain.InitFlags) error {
736736
for _, uuid := range uuids {
737-
patternsConfig, err := codacyclient.GetDefaultToolPatternsConfig(initFlags, uuid)
737+
patternsConfig, err := codacyclient.GetDefaultToolPatternsConfig(initFlags, uuid, true)
738738
if err != nil {
739739
logToolConfigWarning(uuid, "Failed to get default patterns", err)
740740
continue

cmd/init_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestConfigFileTemplate(t *testing.T) {
2525
"node@22.2.0",
2626
"python@3.11.11",
2727
"eslint@8.57.0",
28-
"trivy@0.59.1",
28+
"trivy@0.65.0",
2929
"pylint@3.3.6",
3030
"pmd@7.11.0",
3131
},

cmd/upload.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ func processSarif(sarif Sarif) [][]map[string]interface{} {
8686

8787
for _, run := range sarif.Runs {
8888
var toolName = getToolName(strings.ToLower(run.Tool.Driver.Name), run.Tool.Driver.Version)
89-
tool, patterns := loadsToolAndPatterns(toolName)
89+
tool, patterns := loadsToolAndPatterns(toolName, false)
90+
9091
for _, result := range run.Results {
9192
modifiedType := tool.Prefix + strings.Replace(result.RuleID, "/", "_", -1)
9293
pattern := getPatternByID(patterns, modifiedType)

codacy-client/client.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ func parsePatternConfigurations(response []byte) ([]domain.PatternConfiguration,
171171
}
172172

173173
// GetDefaultToolPatternsConfig fetches the default patterns for a tool
174-
func GetDefaultToolPatternsConfig(initFlags domain.InitFlags, toolUUID string) ([]domain.PatternConfiguration, error) {
175-
baseURL := fmt.Sprintf("%s/api/v3/tools/%s/patterns?enabled=true", CodacyApiBase, toolUUID)
174+
func GetDefaultToolPatternsConfig(initFlags domain.InitFlags, toolUUID string, onlyEnabledPatterns bool) ([]domain.PatternConfiguration, error) {
175+
baseURL := fmt.Sprintf("%s/api/v3/tools/%s/patterns", CodacyApiBase, toolUUID)
176+
if onlyEnabledPatterns {
177+
baseURL += "?enabled=true"
178+
}
176179

177180
return getAllPages(baseURL, initFlags, parseDefaultPatternConfigurations)
178181
}

integration-tests/config-discover/expected/codacy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ runtimes:
66
tools:
77
- dartanalyzer@3.7.2
88
- eslint@8.57.0
9-
- lizard@1.17.19
9+
- lizard@1.17.31
1010
- pmd@7.11.0
1111
- pylint@3.3.6
1212
- semgrep@1.78.0
13-
- trivy@0.59.1
13+
- trivy@0.65.0

integration-tests/init-with-token/expected/codacy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ runtimes:
44
- python@3.11.11
55
tools:
66
- eslint@8.57.0
7-
- lizard@1.17.19
7+
- lizard@1.17.31
88
- pmd@6.55.0
99
- pylint@3.3.7
1010
- semgrep@1.78.0
11-
- trivy@0.59.1
11+
- trivy@0.65.0

integration-tests/init-without-token/expected/codacy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ runtimes:
77
tools:
88
- dartanalyzer@3.7.2
99
- eslint@8.57.0
10-
- lizard@1.17.19
10+
- lizard@1.17.31
1111
- pmd@7.11.0
1212
- pylint@3.3.6
1313
- revive@1.7.0
1414
- semgrep@1.78.0
15-
- trivy@0.59.1
15+
- trivy@0.65.0

plugins/tools/lizard/plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: lizard
22
description: Lizard is an extensible Cyclomatic Complexity Analyzer for many programming languages.
3-
default_version: 1.17.19
3+
default_version: 1.17.31
44
runtime: python
55
runtime_binaries:
66
package_manager: python3

0 commit comments

Comments
 (0)