Skip to content

Commit a2b6a2d

Browse files
committed
feature: Only send sourceId for Trivy CF-1813
This will avoid messing with the results from other tools and respectes on how codacy cloud and the CLI v1 handles it. The downside is that will be a bit error prone when adding other tools and if forget to add it, less results will be added on Codacy, but for now it is an acceptable compromise
1 parent 3ba1156 commit a2b6a2d

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

plugins/tool-utils.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,19 @@ type RuntimeBinaries struct {
5555

5656
// ToolPluginConfig holds the structure of the tool plugin.yaml file
5757
type ToolPluginConfig struct {
58-
Name string `yaml:"name"`
59-
Description string `yaml:"description"`
60-
DefaultVersion string `yaml:"default_version"`
61-
Runtime string `yaml:"runtime"`
62-
RuntimeBinaries RuntimeBinaries `yaml:"runtime_binaries"`
63-
Installation InstallationConfig `yaml:"installation"`
64-
Download DownloadConfig `yaml:"download"`
65-
Environment map[string]string `yaml:"environment"`
66-
Binaries []ToolBinary `yaml:"binaries"`
67-
Formatters []Formatter `yaml:"formatters"`
68-
OutputOptions OutputOptions `yaml:"output_options"`
69-
AnalysisOptions AnalysisOptions `yaml:"analysis_options"`
58+
Name string `yaml:"name"`
59+
Description string `yaml:"description"`
60+
DefaultVersion string `yaml:"default_version"`
61+
Runtime string `yaml:"runtime"`
62+
RuntimeBinaries RuntimeBinaries `yaml:"runtime_binaries"`
63+
Installation InstallationConfig `yaml:"installation"`
64+
Download DownloadConfig `yaml:"download"`
65+
Environment map[string]string `yaml:"environment"`
66+
Binaries []ToolBinary `yaml:"binaries"`
67+
Formatters []Formatter `yaml:"formatters"`
68+
OutputOptions OutputOptions `yaml:"output_options"`
69+
AnalysisOptions AnalysisOptions `yaml:"analysis_options"`
70+
NeedsSourceIdUpload bool `yaml:"needs_source_id_upload"`
7071
}
7172

7273
// ToolConfig represents configuration for a tool
@@ -98,7 +99,8 @@ type ToolInfo struct {
9899
FileName string
99100
Extension string
100101
// Environment variables
101-
Environment map[string]string
102+
Environment map[string]string
103+
NeedsSourceIdUpload bool
102104
}
103105

104106
// ProcessTools processes a list of tool configurations and returns a map of tool information
@@ -151,7 +153,8 @@ func ProcessTools(configs []ToolConfig, toolDir string, runtimes map[string]*Run
151153
InstallCommand: pluginConfig.Installation.Command,
152154
RegistryCommand: pluginConfig.Installation.RegistryTemplate,
153155
// Store environment variables
154-
Environment: make(map[string]string),
156+
Environment: make(map[string]string),
157+
NeedsSourceIdUpload: pluginConfig.NeedsSourceIdUpload,
155158
}
156159

157160
// Handle download configuration for directly downloaded tools

plugins/tool-utils_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func TestProcessTools(t *testing.T) {
6666
// Assert installation command templates are correctly set
6767
assert.Equal(t, "install --prefix {{.InstallDir}} {{.PackageName}}@{{.Version}} @microsoft/eslint-formatter-sarif", eslintInfo.InstallCommand)
6868
assert.Equal(t, "config set registry {{.Registry}}", eslintInfo.RegistryCommand)
69+
assert.Equal(t, eslintInfo.NeedsSourceIdUpload, false)
6970
}
7071

7172
func TestProcessToolsWithDownload(t *testing.T) {
@@ -151,6 +152,7 @@ func TestProcessToolsWithDownload(t *testing.T) {
151152
expectedArch = runtime.GOARCH
152153
}
153154
assert.Contains(t, trivyInfo.DownloadURL, expectedArch)
155+
assert.Equal(t, trivyInfo.NeedsSourceIdUpload, true)
154156
}
155157

156158
func TestGetSupportedTools(t *testing.T) {

plugins/tools/trivy/plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ download:
1616
"darwin": "macOS"
1717
"linux": "Linux"
1818
"windows": "Windows"
19-
2019
binaries:
2120
- name: trivy
2221
path: "trivy"
22+
needs_source_id_upload: true

0 commit comments

Comments
 (0)