Skip to content

Commit 26ba75c

Browse files
merged main with success
1 parent e8fada6 commit 26ba75c

File tree

4 files changed

+50
-29
lines changed

4 files changed

+50
-29
lines changed

.codacy/codacy.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tools/getTools.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,55 @@ import (
1111
"time"
1212
)
1313

14+
func enrichToolsWithVersion(tools []Tool) ([]Tool, error) {
15+
client := &http.Client{
16+
Timeout: 10 * time.Second,
17+
}
18+
19+
// Create a new GET request
20+
req, err := http.NewRequest("GET", "https://api.codacy.com/api/v3/tools", nil)
21+
if err != nil {
22+
return nil, fmt.Errorf("failed to create request: %w", err)
23+
}
24+
25+
// Send the request
26+
resp, err := client.Do(req)
27+
if err != nil {
28+
return nil, fmt.Errorf("failed to send request: %w", err)
29+
}
30+
defer resp.Body.Close()
31+
32+
if resp.StatusCode != 200 {
33+
return nil, fmt.Errorf("failed to get tools from Codacy API: status code %d", resp.StatusCode)
34+
}
35+
36+
// Read the response body
37+
body, err := io.ReadAll(resp.Body)
38+
if err != nil {
39+
return nil, fmt.Errorf("failed to read response body: %w", err)
40+
}
41+
42+
var response ToolsResponse
43+
if err := json.Unmarshal(body, &response); err != nil {
44+
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
45+
}
46+
47+
// Create a map of tool UUIDs to versions
48+
versionMap := make(map[string]string)
49+
for _, tool := range response.Data {
50+
versionMap[tool.Uuid] = tool.Version
51+
}
52+
53+
// Enrich the input tools with versions
54+
for i, tool := range tools {
55+
if version, exists := versionMap[tool.Uuid]; exists {
56+
tools[i].Version = version
57+
}
58+
}
59+
60+
return tools, nil
61+
}
62+
1463
func GetRepositoryTools(codacyBase string, apiToken string, provider string, organization string, repository string) ([]Tool, error) {
1564
client := &http.Client{
1665
Timeout: 10 * time.Second,
@@ -70,7 +119,7 @@ func GetRepositoryTools(codacyBase string, apiToken string, provider string, org
70119
}
71120
}
72121

73-
return enabledTools, nil
122+
return enrichToolsWithVersion(enabledTools)
74123
}
75124

76125
type ToolsResponse struct {

trivy.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)