Skip to content

Commit

Permalink
New code for pre commit, fix count when filtering & current file resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
nquinquenel committed Oct 6, 2023
1 parent c5b98f3 commit c117ebd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ public void refreshViews() {
var hotspotContent = getSecurityHotspotContent();
if (hotspotContent != null) {
var hotspotsPanel = (SecurityHotspotsPanel) hotspotContent.getComponent();
hotspotsPanel.refreshView();
hotspotContent.setDisplayName(buildTabName(hotspotsPanel.getSecurityHotspotCount(), SonarLintToolWindowFactory.SECURITY_HOTSPOTS_TAB_TITLE));
hotspotContent.setDisplayName(buildTabName(hotspotsPanel.refreshView(), SonarLintToolWindowFactory.SECURITY_HOTSPOTS_TAB_TITLE));
}

var taintContent = getTaintVulnerabilitiesContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
import org.sonarlint.intellij.actions.SonarLintToolWindow;
import org.sonarlint.intellij.analysis.AnalysisResult;
import org.sonarlint.intellij.analysis.AnalysisSubmitter;
import org.sonarlint.intellij.cayc.CleanAsYouCodeService;
import org.sonarlint.intellij.common.util.SonarLintUtils;
import org.sonarlint.intellij.finding.issue.LiveIssue;
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
import org.sonarsource.sonarlint.core.commons.Language;

import static org.sonarlint.intellij.common.util.SonarLintUtils.getService;
import static org.sonarlint.intellij.config.Settings.getGlobalSettings;

public class SonarLintCheckinHandler extends CheckinHandler {
Expand Down Expand Up @@ -103,15 +105,18 @@ private void handleError(Exception e, int numFiles) {

private ReturnResult processResult(AnalysisResult result) {
var issuesPerFile = result.getFindings().getIssuesPerFile();
var shouldFocusOnNewCode = getService(CleanAsYouCodeService.class).shouldFocusOnNewCode(project);

var numIssues = issuesPerFile.entrySet().stream()
.flatMap(e -> e.getValue().stream())
.filter(Predicate.not(LiveIssue::isResolved))
.filter(issue -> !shouldFocusOnNewCode || issue.isOnNewCode())
.count();

var numBlockerIssues = issuesPerFile.entrySet().stream()
.flatMap(e -> e.getValue().stream())
.filter(Predicate.not(LiveIssue::isResolved))
.filter(issue -> !shouldFocusOnNewCode || issue.isOnNewCode())
.filter(i -> IssueSeverity.BLOCKER.equals(i.getUserSeverity()))
.count();

Expand All @@ -122,7 +127,11 @@ private ReturnResult processResult(AnalysisResult result) {
var numFiles = issuesPerFile.keySet().size();

var issues = issuesPerFile.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
var numSecretsIssues = issues.stream().filter(issue -> issue.getRuleKey().startsWith(Language.SECRETS.getLanguageKey())).count();
var numSecretsIssues = issues.stream()
.filter(issue -> !shouldFocusOnNewCode || issue.isOnNewCode())
.filter(issue -> issue.getRuleKey()
.startsWith(Language.SECRETS.getLanguageKey()))
.count();
var msg = createMessage(numFiles, numIssues, numBlockerIssues, numSecretsIssues);

var choice = showYesNoCancel(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public CurrentFilePanel(Project project) {

public void allowResolvedIssues(boolean allowResolved) {
treeBuilder.allowResolvedIssues(allowResolved);
oldTreeBuilder.allowResolvedIssues(allowResolved);
refreshModel();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ public class SecurityHotspotsPanel extends SimpleToolWindowPanel implements Disp
private SecurityHotspotsLocalDetectionSupport status;
private int securityHotspotCount;
private Map<VirtualFile, Collection<LiveSecurityHotspot>> currentFindings;

public int getSecurityHotspotCount() {
return securityHotspotCount;
}

private int oldSecurityHotspotCount;
private JBPanelWithEmptyText notSupportedPanel;
private AnAction sonarConfigureProject;
Expand Down Expand Up @@ -400,9 +395,11 @@ public void dispose() {
// Nothing to do
}

public void refreshView() {
public int refreshView() {
if (currentFindings != null) {
updateHotspots(currentFindings);
return updateHotspots(currentFindings);
}
return 0;
}

}

0 comments on commit c117ebd

Please sign in to comment.