Skip to content

Commit

Permalink
#1011: Add support for Sonarqube 24.12 (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
mc1arke authored Dec 11, 2024
1 parent d4298a8 commit b3366cd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The Sonarqube base image. 'latest' if building locally, '8.5-community' if targeting a specific version
SONARQUBE_VERSION=10.6-community
SONARQUBE_VERSION=24.12.0.100206-community

# The name of the Dockerfile to run. 'Dockerfile' is building locally, 'release.Dockerfile' if building the release image
DOCKERFILE=Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repositories {
}
}

def sonarqubeVersion = '10.6.0.92116'
def sonarqubeVersion = '24.12.0.100206'
def sonarqubeLibDir = "${projectDir}/sonarqube-lib"
def sonarLibraries = "${sonarqubeLibDir}/sonarqube-${sonarqubeVersion}/lib"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ static boolean exceedsMaximumNumberOfAnnotations(int chunkCounter, AnnotationUpl
private static String toBitbucketSeverity(Severity severity) {
switch (severity) {
case HIGH:
case BLOCKER:
return "HIGH";
case MEDIUM:
return "MEDIUM";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ private static GHCheckRun.AnnotationLevel mapToGithubAnnotationLevel(Collection<
Severity maxSeverity = sonarqubeSeverity.stream().max(Severity::compareTo).orElseThrow();
switch (maxSeverity) {
case LOW:
case INFO:
return GHCheckRun.AnnotationLevel.NOTICE;
case MEDIUM:
return GHCheckRun.AnnotationLevel.WARNING;
case HIGH:
case BLOCKER:
return GHCheckRun.AnnotationLevel.FAILURE;
default:
throw new IllegalArgumentException("Unknown severity value: " + sonarqubeSeverity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.measure.MeasureDto;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.protobuf.DbProjectBranches;
Expand Down Expand Up @@ -91,9 +91,9 @@ public void handleProjectRequest(ProjectDto project, Request request, Response r
.collect(Collectors.toList()))
.stream().collect(Collectors.toMap(BranchDto::getUuid, Function.identity()));

Map<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = getDbClient().liveMeasureDao()
Map<String, MeasureDto> qualityGateMeasuresByComponentUuids = getDbClient().measureDao()
.selectByComponentUuidsAndMetricKeys(dbSession, pullRequestUuids, List.of(CoreMetrics.ALERT_STATUS_KEY)).stream()
.collect(Collectors.toMap(LiveMeasureDto::getComponentUuid, Function.identity()));
.collect(Collectors.toMap(MeasureDto::getComponentUuid, Function.identity()));
Map<String, String> analysisDateByBranchUuid = getDbClient().snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, pullRequestUuids).stream()
.collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, s -> DateUtils.formatDateTime(s.getCreatedAt())));

Expand All @@ -114,7 +114,7 @@ private static void checkPermission(ProjectDto project, UserSession userSession)
}

private static void addPullRequest(ProjectPullRequests.ListWsResponse.Builder response, BranchDto branch, Map<String, BranchDto> mergeBranchesByUuid,
@Nullable LiveMeasureDto qualityGateMeasure, @Nullable String analysisDate) {
@Nullable MeasureDto qualityGateMeasure, @Nullable String analysisDate) {
Optional<BranchDto> mergeBranch = Optional.ofNullable(mergeBranchesByUuid.get(branch.getMergeBranchUuid()));

ProjectPullRequests.PullRequest.Builder builder = ProjectPullRequests.PullRequest.newBuilder();
Expand Down Expand Up @@ -147,10 +147,10 @@ private static void addPullRequest(ProjectPullRequests.ListWsResponse.Builder re
response.addPullRequests(builder);
}

private static void setQualityGate(ProjectPullRequests.PullRequest.Builder builder, @Nullable LiveMeasureDto qualityGateMeasure) {
private static void setQualityGate(ProjectPullRequests.PullRequest.Builder builder, @Nullable MeasureDto qualityGateMeasure) {
ProjectPullRequests.Status.Builder statusBuilder = ProjectPullRequests.Status.newBuilder();
if (qualityGateMeasure != null) {
Optional.ofNullable(qualityGateMeasure.getDataAsString()).ifPresent(statusBuilder::setQualityGateStatus);
Optional.ofNullable(qualityGateMeasure.getString(CoreMetrics.ALERT_STATUS_KEY)).ifPresent(statusBuilder::setQualityGateStatus);
}
builder.setStatus(statusBuilder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void shouldDecoratePullRequestWithCorrectAnalysisAndSummaryCommentWhenEnabled()
output.add(new GHCheckRunBuilder.Annotation(
"path" + i,
i,
GHCheckRun.AnnotationLevel.values()[i % GHCheckRun.AnnotationLevel.values().length],
GHCheckRun.AnnotationLevel.values()[i % Severity.values().length < 2 ? 0 : i % Severity.values().length > 2 ? 2 : 1],
"issue message " + i));
}

Expand Down Expand Up @@ -235,7 +235,7 @@ void shouldDecoratePullRequestWithCorrectAnalysisAndNoSummaryCommentWhenDisabled
output.add(new GHCheckRunBuilder.Annotation(
"path" + i,
i,
GHCheckRun.AnnotationLevel.values()[i % GHCheckRun.AnnotationLevel.values().length],
GHCheckRun.AnnotationLevel.values()[i % Severity.values().length < 2 ? 0 : i % Severity.values().length > 2 ? 2 : 1],
"issue message " + i));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
Expand All @@ -40,8 +41,8 @@
import org.sonar.db.component.BranchType;
import org.sonar.db.component.SnapshotDao;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.LiveMeasureDao;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.measure.MeasureDao;
import org.sonar.db.measure.MeasureDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.protobuf.DbProjectBranches;
import org.sonar.server.component.ComponentFinder;
Expand Down Expand Up @@ -130,11 +131,11 @@ void shouldExecuteRequestWithValidParameter() {
.setUuid("uuid2")
.setKey("branch2Key")));

LiveMeasureDao liveMeasureDao = mock();
when(dbClient.liveMeasureDao()).thenReturn(liveMeasureDao);
when(liveMeasureDao.selectByComponentUuidsAndMetricKeys(any(), any(), any())).thenReturn(List.of(new LiveMeasureDto()
MeasureDao measureDao = mock();
when(dbClient.measureDao()).thenReturn(measureDao);
when(measureDao.selectByComponentUuidsAndMetricKeys(any(), any(), any())).thenReturn(List.of(new MeasureDto()
.setComponentUuid("uuid1")
.setData("live measure")));
.addValue(CoreMetrics.ALERT_STATUS_KEY, "live measure")));

SnapshotDao snapshotDao = mock();
when(dbClient.snapshotDao()).thenReturn(snapshotDao);
Expand Down

0 comments on commit b3366cd

Please sign in to comment.