Skip to content

Conversation

@andrzej-janczak
Copy link
Contributor

When running like:
cli-v2 analyze --format sarif --output results.sarif then all tools declared in codacy yaml will run and output will be merged into one sarif file

- Moved the `mergeSarifOutputs` function from `analyze.go` to `utils/sarif.go` for better code organization.
- Updated the `analyze.go` file to use the new utility function for merging SARIF outputs.
- Enhanced the `Rule` struct in the utils package to use `map[string]interface{}` for properties.
@codacy-production
Copy link

codacy-production bot commented Apr 8, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.90% 0.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (93219d2) 2260 600 26.55%
Head commit (5c0f1a6) 2339 (+79) 600 (+0) 25.65% (-0.90%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#64) 97 0 0.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@andrzej-janczak andrzej-janczak requested a review from Copilot April 8, 2025 15:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

utils/sarif.go:180

  • Consider handling the error returned by json.MarshalIndent in createEmptySarifReport to avoid potential silent failures.
sarifData, _ := json.MarshalIndent(emptyReport, "", "  ")

cmd/analyze.go:294

  • [nitpick] Changing the unsupported tool handling from a fatal error to a warning may lead to silent failures; please verify that this behavior is intentional or consider handling it by returning an error.
log.Printf("Warning: Unsupported tool: %s\n", toolName)

cmd/analyze.go Outdated
func init() {
analyzeCmd.Flags().StringVarP(&outputFile, "output", "o", "", "Output file for analysis results")
analyzeCmd.Flags().StringVarP(&toolToAnalyze, "tool", "t", "", "Which tool to run analysis with")
analyzeCmd.Flags().StringVarP(&toolToAnalyze, "tool", "t", "", "Optional: Specific tool to run analysis with. If not specified, all configured tools will be run")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, we don't need to specify that arguments are optional, just like the Output file as an example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

cmd/analyze.go Outdated
// If a specific tool is specified, only run that tool
if toolToAnalyze != "" {
log.Printf("Running %s...\n", toolToAnalyze)
runTool(workDirectory, toolToAnalyze, args, outputFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion, can we do something like this, so we can only have one flow and one code to deal with 'running a list of tools:

tools := config.Config.Tools()
if toolToAnalyze != "" {
			tools = toolToAnalyze
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

cmd/analyze.go Outdated
log.Fatal("Trying to run unsupported tool: ", toolToAnalyze)
log.Println("Running all configured tools...")

if outputFormat == "sarif" && outputFile != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am expecting that running something with --format sarif > out.sarif to be similar to --format sarif --output out.sarif, is is a fair expectation? Meaning, that if we do any strategy of merging when it is a SARIF, it should not depend if the user specifies a file or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

- Renamed `toolToAnalyze` to `toolsToAnalyzeParam` for clarity.
- Updated the logic to allow specifying a single tool for analysis or running all configured tools if none is specified.
- Improved error handling for cases with no configured tools.
Copy link
Contributor

@machadoit machadoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@andrzej-janczak andrzej-janczak merged commit 703c641 into main Apr 9, 2025
7 checks passed
@alerizzo alerizzo deleted the analyze-run-all-PLUTO-1385 branch June 3, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants