Skip to content

Commit

Permalink
🐛 QD-10627 Don't fail analysis step if changeset is empty in case of …
Browse files Browse the repository at this point in the history
…scoped analysis.
  • Loading branch information
hybloid committed Jan 9, 2025
1 parent e6e23fa commit 36d1e94
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
3 changes: 3 additions & 0 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ func checkExitCode(exitCode int, resultsDir string, options *core.QodanaOptions)
} else if exitCode == platform.QodanaTimeoutExitCodePlaceholder {
platform.ErrorMessage("Qodana analysis reached timeout %s", options.GetAnalysisTimeout())
os.Exit(options.AnalysisTimeoutExitCode)
} else if exitCode == platform.QodanaEmptyChangesetExitCodePlaceholder {
platform.ErrorMessage("Nothing to analyse. Exiting with %s", platform.QodanaSuccessExitCode)
os.Exit(platform.QodanaSuccessExitCode)
} else if exitCode != platform.QodanaSuccessExitCode && exitCode != platform.QodanaFailThresholdExitCode {
platform.ErrorMessage("Qodana exited with code %d", exitCode)
platform.WarningMessage("Check ./logs/ in the results directory for more information")
Expand Down
27 changes: 14 additions & 13 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,19 @@ func runScopeScript(ctx context.Context, options *QodanaOptions, startHash strin
}
}

scopeFile, err := writeChangesFile(options, startHash, end)
if startHash == "" || end == "" {
log.Fatal("No commits given. Consider passing --commit or --diff-start and --diff-end (optional) with the range of commits to analyze.")
}
changedFiles, err := platform.GitChangedFiles(options.ProjectDir, startHash, end, options.LogDirPath())
if err != nil {
log.Fatal(err)
}
if len(changedFiles.Files) == 0 {
log.Warnf("Nothing to compare between %s and %s", startHash, end)
return platform.QodanaEmptyChangesetExitCodePlaceholder
}

scopeFile, err := writeChangesFile(options, changedFiles)
if err != nil {
log.Fatal("Failed to prepare diff run ", err)
}
Expand Down Expand Up @@ -415,18 +427,7 @@ func runScopeScript(ctx context.Context, options *QodanaOptions, startHash strin
}

// writeChangesFile creates a temp file containing the changes between diffStart and diffEnd
func writeChangesFile(options *QodanaOptions, start string, end string) (string, error) {
if start == "" || end == "" {
return "", fmt.Errorf("no commits given")
}
changedFiles, err := platform.GitChangedFiles(options.ProjectDir, start, end, options.LogDirPath())
if err != nil {
return "", err
}

if len(changedFiles.Files) == 0 {
return "", fmt.Errorf("nothing to compare between %s and %s", start, end)
}
func writeChangesFile(options *QodanaOptions, changedFiles platform.ChangedFiles) (string, error) {
file, err := os.CreateTemp("", "diff-scope.txt")
if err != nil {
return "", err
Expand Down
5 changes: 4 additions & 1 deletion platform/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ const (
// QodanaEapLicenseExpiredExitCode reports an expired license.
QodanaEapLicenseExpiredExitCode = 7
// QodanaTimeoutExitCodePlaceholder is not a real exit code (it is not obtained from IDE process! and not returned from CLI)
QodanaTimeoutExitCodePlaceholder = 1000
// Placeholder used to identify the case when the analysis reached timeout
QodanaTimeoutExitCodePlaceholder = 1000
// QodanaEmptyChangesetExitCodePlaceholder is not a real exit code (it is not obtained from IDE process! and not returned from CLI)
// Placeholder used to identify the case when the changeset for scoped analysis is empty
QodanaEmptyChangesetExitCodePlaceholder = 2000
)

// RunCmd executes subprocess with forwarding of signals, and returns its exit code.
Expand Down

0 comments on commit 36d1e94

Please sign in to comment.