Skip to content

Commit ca0c41f

Browse files
Removed rules=nill in each run and add improve upload pmd7 issues
1 parent cf90e3d commit ca0c41f

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

cmd/upload.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,33 @@ func processSarifAndSendResults(sarifPath string, commitUUID string, projectToke
8383
func processSarif(sarif Sarif) [][]map[string]interface{} {
8484
var codacyIssues []map[string]interface{}
8585
var payloads [][]map[string]interface{}
86-
86+
var modifiedType string
8787
for _, run := range sarif.Runs {
8888
var toolName = getToolName(strings.ToLower(run.Tool.Driver.Name), run.Tool.Driver.Version)
8989
tool, patterns := loadsToolAndPatterns(toolName, false)
9090

9191
for _, result := range run.Results {
92-
modifiedType := tool.Prefix + strings.Replace(result.RuleID, "/", "_", -1)
92+
if toolName == "pmd" || toolName == "pmd-7" {
93+
var language string
94+
var ruleset string
95+
// Try to extract ruleset from tool.driver.rules if available
96+
rules := run.Tool.Driver.Rules[result.RuleIndex]
97+
if rules.HelpURI != "" {
98+
if parts := strings.Split(rules.HelpURI, "pmd_rules_"); len(parts) > 1 {
99+
subParts := strings.SplitN(parts[1], "_", 2)
100+
if len(subParts) == 2 {
101+
language = subParts[0]
102+
rulesetPart := strings.SplitN(subParts[1], ".html", 2)[0]
103+
ruleset = rulesetPart
104+
}
105+
}
106+
}
107+
modifiedType = fmt.Sprintf(tool.Prefix+"category_%s_%s_%s", language, ruleset, result.RuleID)
108+
109+
} else {
110+
modifiedType = tool.Prefix + strings.Replace(result.RuleID, "/", "_", -1)
111+
}
112+
93113
pattern := getPatternByID(patterns, modifiedType)
94114
if pattern == nil {
95115
fmt.Printf("Rule '%s' doesn't have a direct mapping on Codacy\n", modifiedType)

utils/sarif.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,6 @@ func FilterRulesFromSarif(sarifData []byte) ([]byte, error) {
254254
return nil, fmt.Errorf("failed to parse SARIF data: %w", err)
255255
}
256256

257-
// Navigate to the runs array and remove rules from each run
258-
if runs, ok := report["runs"].([]interface{}); ok {
259-
for _, run := range runs {
260-
if runMap, ok := run.(map[string]interface{}); ok {
261-
if tool, ok := runMap["tool"].(map[string]interface{}); ok {
262-
if driver, ok := tool["driver"].(map[string]interface{}); ok {
263-
// Always set rules to null to maintain consistent output format
264-
driver["rules"] = nil
265-
}
266-
}
267-
}
268-
}
269-
}
270-
271257
// Marshal back to JSON with indentation
272258
filteredData, err := json.MarshalIndent(report, "", " ")
273259
if err != nil {

0 commit comments

Comments
 (0)