Skip to content

Commit

Permalink
SLCORE-999 Store custom impacts when synchronizing rules
Browse files Browse the repository at this point in the history
  • Loading branch information
eray-felek-sonarsource committed Oct 28, 2024
1 parent 950bf9b commit ec233e2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private ServerActiveRule tryConvertDeprecatedKeys(String connectionId, ServerAct
var ruleKey = new RuleKey(templateRuleKeyWithCorrectRepo.repository(), ruleKeyPossiblyWithDeprecatedRepo.rule()).toString();
//TODO Replace empty list with proper one.
return new ServerActiveRule(ruleKey, possiblyDeprecatedActiveRuleFromStorage.getSeverity(), possiblyDeprecatedActiveRuleFromStorage.getParams(),
ruleOrTemplateDefinition.getKey(), Collections.emptyList());
ruleOrTemplateDefinition.getKey(), possiblyDeprecatedActiveRuleFromStorage.getOverriddenImpacts());
} else {
ruleOrTemplateDefinition = rulesRepository.getRule(connectionId, possiblyDeprecatedActiveRuleFromStorage.getRuleKey()).orElse(null);
if (ruleOrTemplateDefinition == null) {
Expand All @@ -429,7 +429,7 @@ private ServerActiveRule tryConvertDeprecatedKeys(String connectionId, ServerAct
}
//TODO Replace empty list with proper one.
return new ServerActiveRule(ruleOrTemplateDefinition.getKey(), possiblyDeprecatedActiveRuleFromStorage.getSeverity(), possiblyDeprecatedActiveRuleFromStorage.getParams(),
null, Collections.emptyList());
null, possiblyDeprecatedActiveRuleFromStorage.getOverriddenImpacts());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private ServerActiveRule tryConvertDeprecatedKeys(ServerActiveRule possiblyDepre
var ruleKey = new RuleKey(templateRuleKeyWithCorrectRepo.repository(), ruleKeyPossiblyWithDeprecatedRepo.rule()).toString();
//TODO Replace empty list with proper one.
return new ServerActiveRule(ruleKey, possiblyDeprecatedActiveRuleFromStorage.getSeverity(), possiblyDeprecatedActiveRuleFromStorage.getParams(),
ruleOrTemplateDefinition.get().getKey(), Collections.emptyList());
ruleOrTemplateDefinition.get().getKey(), possiblyDeprecatedActiveRuleFromStorage.getOverriddenImpacts());
} else {
ruleOrTemplateDefinition = rulesRepository.getRule(connectionId, possiblyDeprecatedActiveRuleFromStorage.getRuleKey());
if (ruleOrTemplateDefinition.isEmpty()) {
Expand All @@ -242,7 +242,7 @@ private ServerActiveRule tryConvertDeprecatedKeys(ServerActiveRule possiblyDepre
//TODO Replace empty list with proper one.
return new ServerActiveRule(ruleOrTemplateDefinition.get().getKey(), possiblyDeprecatedActiveRuleFromStorage.getSeverity(),
possiblyDeprecatedActiveRuleFromStorage.getParams(),
null, Collections.emptyList());
null, possiblyDeprecatedActiveRuleFromStorage.getOverriddenImpacts());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.sonarsource.sonarlint.core.commons.CleanCodeAttribute;
import org.sonarsource.sonarlint.core.commons.ImpactSeverity;
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
Expand All @@ -40,6 +41,7 @@
import org.sonarsource.sonarlint.core.serverapi.ServerApiHelper;
import org.sonarsource.sonarlint.core.serverapi.UrlUtils;
import org.sonarsource.sonarlint.core.serverapi.proto.sonarqube.ws.Rules;
import org.sonarsource.sonarlint.core.serverapi.push.parsing.common.ImpactPayload;

import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -120,8 +122,10 @@ public Collection<ServerActiveRule> getAllActiveRules(String qualityProfileKey,
IssueSeverity.valueOf(ar.getSeverity()),
ar.getParamsList().stream().collect(toMap(Rules.Active.Param::getKey, Rules.Active.Param::getValue)),
ruleTemplatesByRuleKey.get(ruleKey),
//TODO Pass the right value
Collections.emptyList()));
//TODO replace empty list with proper one
ar.getImpacts().getImpactsList().stream()
.map(impact -> new ImpactPayload(impact.getSoftwareQuality().toString(), impact.getSeverity().name()))
.collect(Collectors.toList())));

},
false,
Expand Down
5 changes: 5 additions & 0 deletions backend/server-api/src/main/proto/sonarqube/ws-rules.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ message Active {
optional string qProfile = 1;
optional string severity = 3;
repeated Param params = 5;
optional Impacts impacts = 9;

message Param {
optional string key = 1;
optional string value = 2;
}

message Impacts{
repeated sonarqube.ws.commons.Impact impacts = 1;
}
}

0 comments on commit ec233e2

Please sign in to comment.