Skip to content

Commit

Permalink
SLE-521 Fix issue severity when severity is changed on the QP
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Apr 19, 2022
1 parent 2536779 commit a8f2779
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,24 +514,22 @@ public void should_clear_server_issue_details_if_disappeared() {
var serverIssueKey = "dummy serverIssueKey";
var resolved = true;
var assignee = "dummy assignee";
var base = builder().ruleKey("dummy ruleKey").severity("CRITICAL").rawSeverity("CRITICAL");

var start = System.currentTimeMillis();
var base = builder().ruleKey("dummy ruleKey").lineHash(123).severity("CRITICAL").rawSeverity("CRITICAL");

// First analysis
cache.put(DUMMY_FILE1_PATH, tracker.matchAndTrackAsNew(file1, List.of(base.build())));
cache.put(DUMMY_FILE1_PATH, tracker.matchAndTrackServerIssues(file1,
List.of(base.copy().serverIssueKey(serverIssueKey).resolved(true).assignee(assignee).severity("BLOCKER").build())));
List.of(base.copy().serverIssueKey(serverIssueKey).creationDate(456789L).resolved(true).assignee(assignee).severity("BLOCKER").build())));

// Second analysis with no more issue on server side
cache.put(DUMMY_FILE1_PATH, tracker.matchAndTrackAsNew(file1, List.of(base.build())));
cache.put(DUMMY_FILE1_PATH, tracker.matchAndTrackServerIssues(file1, List.of()));

var trackables = cache.getCurrentTrackables(DUMMY_FILE1_PATH);
assertThat(trackables)
.extracting("serverIssueKey", "resolved", "assignee", "severity")
.containsExactly(tuple(null, !resolved, "", "CRITICAL"));
assertThat(trackables.iterator().next().getCreationDate()).isGreaterThanOrEqualTo(start);
.extracting("serverIssueKey", "resolved", "assignee", "severity", "creationDate")
// Resolution and severity are reset, but creationDate stay the same
.containsExactly(tuple(null, !resolved, "", "CRITICAL", 456789L));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
package org.sonarlint.eclipse.core.internal.tracking;

import org.sonarlint.eclipse.core.internal.utils.StringUtils;

/**
* Combine a new Trackable ("raw") with a previous state ("base")
*/
Expand All @@ -43,9 +41,13 @@ public PreviousTrackable(Trackable base, Trackable raw) {
this.resolved = base.isResolved();
this.assignee = base.getAssignee();
this.markerId = base.getMarkerId();
// Migration: severity & type were initially not stored in protobuf file
this.severity = StringUtils.isBlank(base.getSeverity()) ? raw.getSeverity() : base.getSeverity();
this.type = StringUtils.isBlank(base.getType()) ? raw.getType() : base.getType();
if (base.getServerIssueKey() != null) {
this.severity = base.getSeverity();
this.type = base.getType();
} else {
this.severity = raw.getSeverity();
this.type = raw.getType();
}
}

@Override
Expand Down

0 comments on commit a8f2779

Please sign in to comment.