From 591e9160a82db9fb03d0a2dfa61b400fb716b325 Mon Sep 17 00:00:00 2001 From: Yunsong Date: Sun, 4 Feb 2024 11:06:17 +0800 Subject: [PATCH] ADM-791:[backend]refactor: should get source control report and the pipeline report --- .../service/report/GenerateReporterService.java | 14 +++++++++----- .../report/GenerateReporterServiceTest.java | 10 ++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/heartbeat/service/report/GenerateReporterService.java b/backend/src/main/java/heartbeat/service/report/GenerateReporterService.java index b8fb48dd9e..9d9caffbfe 100644 --- a/backend/src/main/java/heartbeat/service/report/GenerateReporterService.java +++ b/backend/src/main/java/heartbeat/service/report/GenerateReporterService.java @@ -99,12 +99,16 @@ public void generateBoardReport(GenerateReportRequest request) { public void generateDoraReport(GenerateReportRequest request) { removePreviousAsyncException(request.getPipelineReportId()); removePreviousAsyncException(request.getSourceControlReportId()); - FetchedData fetchedData = fetchOriginalData(request, new FetchedData()); - if (CollectionUtils.isNotEmpty(request.getPipelineMetrics())) { - generatePipelineReport(request.toPipelineRequest(), fetchedData); - } + FetchedData fetchedData = new FetchedData(); if (CollectionUtils.isNotEmpty(request.getSourceControlMetrics())) { - generateSourceControlReport(request.toSourceControlRequest(), fetchedData); + GenerateReportRequest sourceControlRequest = request.toSourceControlRequest(); + fetchOriginalData(sourceControlRequest, fetchedData); + generateSourceControlReport(sourceControlRequest, fetchedData); + } + if (CollectionUtils.isNotEmpty(request.getPipelineMetrics())) { + GenerateReportRequest pipelineRequest = request.toPipelineRequest(); + fetchOriginalData(pipelineRequest, fetchedData); + generatePipelineReport(pipelineRequest, fetchedData); } generateCSVForPipeline(request, fetchedData.getBuildKiteData()); asyncMetricsDataHandler.updateMetricsDataCompletedInHandler(request.getCsvTimeStamp(), DORA); diff --git a/backend/src/test/java/heartbeat/service/report/GenerateReporterServiceTest.java b/backend/src/test/java/heartbeat/service/report/GenerateReporterServiceTest.java index f677a17b0c..e23adadf94 100644 --- a/backend/src/test/java/heartbeat/service/report/GenerateReporterServiceTest.java +++ b/backend/src/test/java/heartbeat/service/report/GenerateReporterServiceTest.java @@ -6,6 +6,7 @@ import heartbeat.controller.report.dto.request.CodebaseSetting; import heartbeat.controller.report.dto.request.GenerateReportRequest; import heartbeat.controller.report.dto.request.JiraBoardSetting; +import heartbeat.controller.report.dto.request.MetricEnum; import heartbeat.controller.report.dto.request.MetricType; import heartbeat.controller.report.dto.response.ChangeFailureRate; import heartbeat.controller.report.dto.response.Classification; @@ -555,7 +556,8 @@ void shouldGenerateCsvWithCachedDataWhenBuildKiteDataAlreadyExisted() { .considerHoliday(false) .startTime("10000") .endTime("20000") - .metrics(List.of("lead time for changes", "change failure rate")) + .metrics( + List.of(MetricEnum.LEAD_TIME_FOR_CHANGES.getValue(), MetricEnum.CHANGE_FAILURE_RATE.getValue())) .codebaseSetting(CodebaseSetting.builder().build()) .buildKiteSetting(BuildKiteSetting.builder().build()) .csvTimeStamp(TIMESTAMP) @@ -567,9 +569,9 @@ void shouldGenerateCsvWithCachedDataWhenBuildKiteDataAlreadyExisted() { List pipelineCSVInfos = List.of(); when(pipelineService.generateCSVForPipelineWithCodebase(any(), any(), any(), any(), any())) .thenReturn(pipelineCSVInfos); - when(pipelineService.fetchGithubData(request)) + when(pipelineService.fetchGithubData(any())) .thenReturn(FetchedData.BuildKiteData.builder().buildInfosList(List.of()).build()); - when(pipelineService.fetchBuildKiteInfo(request)) + when(pipelineService.fetchBuildKiteInfo(any())) .thenReturn(FetchedData.BuildKiteData.builder().buildInfosList(List.of()).build()); LeadTimeForChanges fakeLeadTimeForChange = LeadTimeForChanges.builder().build(); when(leadTimeForChangesCalculator.calculate(any())).thenReturn(fakeLeadTimeForChange); @@ -591,7 +593,7 @@ void shouldUpdateMetricCompletedWhenGenerateCsvWithSourceControlReportFailed() { .considerHoliday(false) .startTime("10000") .endTime("20000") - .metrics(List.of("lead time for changes")) + .metrics(List.of(MetricEnum.LEAD_TIME_FOR_CHANGES.getValue())) .codebaseSetting(CodebaseSetting.builder().build()) .buildKiteSetting(BuildKiteSetting.builder().build()) .csvTimeStamp(TIMESTAMP)