From e997fa00173b8d487452c1249816ca592a1f56ae Mon Sep 17 00:00:00 2001 From: Michael Clarke Date: Sun, 11 Aug 2024 18:35:22 +0100 Subject: [PATCH] #940: Use correct component IDs when extracting analysis date The component ID was being used to create a map of analysis dates to items, but the Pull Request's component ID did not map into this item, so the Pull Request web service was always returning the analysis date as empty. The service has been altered to use the root component ID as was used in the search to ensure the IDs align. --- .../server/pullrequest/ws/pullrequest/action/ListAction.java | 2 +- .../pullrequest/ws/pullrequest/action/ListActionTest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListAction.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListAction.java index dccef12de..a84dc477f 100644 --- a/src/main/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListAction.java +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListAction.java @@ -95,7 +95,7 @@ public void handleProjectRequest(ProjectDto project, Request request, Response r .selectByComponentUuidsAndMetricKeys(dbSession, pullRequestUuids, List.of(CoreMetrics.ALERT_STATUS_KEY)).stream() .collect(Collectors.toMap(LiveMeasureDto::getComponentUuid, Function.identity())); Map analysisDateByBranchUuid = getDbClient().snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, pullRequestUuids).stream() - .collect(Collectors.toMap(SnapshotDto::getUuid, s -> DateUtils.formatDateTime(s.getCreatedAt()))); + .collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, s -> DateUtils.formatDateTime(s.getCreatedAt()))); ProjectPullRequests.ListWsResponse.Builder protobufResponse = ProjectPullRequests.ListWsResponse.newBuilder(); pullRequests diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListActionTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListActionTest.java index e55e568f4..5edce85d7 100644 --- a/src/test/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListActionTest.java +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListActionTest.java @@ -137,7 +137,7 @@ void shouldExecuteRequestWithValidParameter() { SnapshotDao snapshotDao = mock(SnapshotDao.class); when(dbClient.snapshotDao()).thenReturn(snapshotDao); - when(snapshotDao.selectLastAnalysesByRootComponentUuids(any(), any())).thenReturn(List.of(new SnapshotDto().setUuid("componentUuid").setCreatedAt(1234L))); + when(snapshotDao.selectLastAnalysesByRootComponentUuids(any(), any())).thenReturn(List.of(new SnapshotDto().setRootComponentUuid("uuid3").setCreatedAt(1234567891234L))); Response response = mock(Response.class); @@ -157,6 +157,7 @@ void shouldExecuteRequestWithValidParameter() { .setKey("prKey2") .setTitle("title2") .setBranch("prBranch2") + .setAnalysisDate("2009-02-13T23:31:31+0000") .setStatus(ProjectPullRequests.Status.newBuilder() .build()) .setIsOrphan(true)