From 3bc1442b38b2a78d9b98b3f04ce2c1b223c5229a Mon Sep 17 00:00:00 2001 From: Suman Maity Date: Wed, 12 Jul 2023 17:31:03 +0200 Subject: [PATCH] fix: (#380) Consume status for /{workflowId}/runs api as string instead of Enum - Closes #380 --- .talismanrc | 6 ++--- .../service/job/GithubJobDetailsService.java | 2 +- .../job/WorkflowsRunDetailsResponse.java | 4 ++- .../job/GithubJobDetailsServiceTest.java | 26 ++++++++++--------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.talismanrc b/.talismanrc index ac7e1207..e1d1db9c 100644 --- a/.talismanrc +++ b/.talismanrc @@ -28,7 +28,7 @@ fileignoreconfig: - filename: backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/PeriodicScanScheduler.java checksum: 5a3e3aa35f695587a15c0528a0adc84f5d11a4bc59c2212de66ee136814535e0 - filename: backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/job/GithubJobDetailsService.java - checksum: a23c83af2c089741e34638d39f2031cefcf5769aaec5b1f8f0f2ff31b6b73249 + checksum: f1987ab3bd116d07c32ba0271d2f2a2104fe46184ec5c6e207a05e1c6f403342 - filename: backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/notifications/TeamsNotificationMessagePayload.java checksum: d4bafd4580b23f4a8e830c749df73f85ad5fa9952d4c8ffadd9e38cf0cda4580 - filename: backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/scan/secrets/GithubSecretsScanDetailsService.java @@ -56,7 +56,7 @@ fileignoreconfig: - filename: backend/src/test/java/de/otto/platform/gitactionboard/adapters/service/PeriodicScanSchedulerTest.java checksum: 7f39196e1a6cfd1926146f7a1712ac3b6d9adbffde1b5de93a7845c3c5c17e59 - filename: backend/src/test/java/de/otto/platform/gitactionboard/adapters/service/job/GithubJobDetailsServiceTest.java - checksum: 55b1069a7de8cc62efa94c2a74d4486abce8fa28806e6e1ae3b74c5f2e6e3de9 + checksum: 7a5828f97162e20214c6251d22e1d0045be24226ec6863292fb7829ad94575e5 - filename: backend/src/test/java/de/otto/platform/gitactionboard/adapters/service/notifications/TeamsNotificationMessagePayloadTest.java checksum: efdf67477b04bf07df791fcdad4735da5d76502c6e28a4fbf9cef5267ed75a87 - filename: backend/src/test/java/de/otto/platform/gitactionboard/adapters/service/scan/secrets/GithubSecretsScanDetailsServiceTest.java @@ -108,7 +108,7 @@ fileignoreconfig: - filename: frontend/mock-data/data.json checksum: 4baf61952ab3261089ae57c7a91f920e4cb8c67425d99861b7cbff6a1eaec60e - filename: frontend/package-lock.json - checksum: e71f0cc27ee372ee27ac308527b72ce61b8069056d8fa2514db88718fcc0e87b + checksum: 27875505fe73e802d71d52da0cac676e6b27d6fe537a54d80fc6ebaae87e2a0a - filename: frontend/src/components/Dashboard.vue checksum: 55c522358eb8c8cdd66b948f52d837d7f092c9416df3a2b01284a805c1900b0e - filename: frontend/src/components/GridCell.vue diff --git a/backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/job/GithubJobDetailsService.java b/backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/job/GithubJobDetailsService.java index 431eecc4..79d70648 100644 --- a/backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/job/GithubJobDetailsService.java +++ b/backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/job/GithubJobDetailsService.java @@ -70,7 +70,7 @@ private List getPreviousJobDetails( WorkflowRunDetails previousWorkflowRun, String accessToken) { - if (COMPLETED.equals(currentWorkflowRun.getStatus())) { + if (WorkflowRunDetails.COMPLETED.equals(currentWorkflowRun.getStatus())) { return currentJobs; } return fetchPreviousJobs(workflow, currentJobs, previousWorkflowRun, accessToken); diff --git a/backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/job/WorkflowsRunDetailsResponse.java b/backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/job/WorkflowsRunDetailsResponse.java index 81e8638f..70e21f54 100644 --- a/backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/job/WorkflowsRunDetailsResponse.java +++ b/backend/src/main/java/de/otto/platform/gitactionboard/adapters/service/job/WorkflowsRunDetailsResponse.java @@ -17,9 +17,11 @@ public class WorkflowsRunDetailsResponse { @Value @Builder(toBuilder = true) public static class WorkflowRunDetails { + public static final String COMPLETED = "completed"; + long id; - @NonNull RunStatus status; + @NonNull String status; RunConclusion conclusion; diff --git a/backend/src/test/java/de/otto/platform/gitactionboard/adapters/service/job/GithubJobDetailsServiceTest.java b/backend/src/test/java/de/otto/platform/gitactionboard/adapters/service/job/GithubJobDetailsServiceTest.java index 7a15bb8b..991ea5df 100644 --- a/backend/src/test/java/de/otto/platform/gitactionboard/adapters/service/job/GithubJobDetailsServiceTest.java +++ b/backend/src/test/java/de/otto/platform/gitactionboard/adapters/service/job/GithubJobDetailsServiceTest.java @@ -103,14 +103,16 @@ private static Stream getPermutationOfWorkflowRunStatusAndPreviousCon return Stream.of(QUEUED, IN_PROGRESS) .flatMap( - status -> runConclusions.stream().map(conclusion -> Arguments.of(status, conclusion))); + status -> + runConclusions.stream().map(conclusion -> Arguments.of(status.name(), conclusion))); } private static Stream getSuccessPermutationArguments() { return Stream.of(QUEUED, IN_PROGRESS) .flatMap( status -> - Stream.of(SUCCESS, SKIPPED).map(conclusion -> Arguments.of(status, conclusion))); + Stream.of(SUCCESS, SKIPPED) + .map(conclusion -> Arguments.of(status.name(), conclusion))); } @BeforeEach @@ -190,13 +192,13 @@ void shouldFetchJobDetailsForGivenWorkflowWhenLatestBuildIsSuccess() { void shouldFetchJobDetailsForGivenWorkflowWhenLatestBuildIsSuccessAndPreviousBuildIsFailed() { final WorkflowRunDetails latestWorkflowRunDetails = BASE_WORKFLOWS_RUN_DETAILS_RESPONSE.getWorkflowRuns().get(0).toBuilder() - .status(COMPLETED) + .status(WorkflowRunDetails.COMPLETED) .conclusion(SUCCESS) .build(); final WorkflowRunDetails previousWorkflowRunDetails = BASE_WORKFLOWS_RUN_DETAILS_RESPONSE.getWorkflowRuns().get(1).toBuilder() - .status(COMPLETED) + .status(WorkflowRunDetails.COMPLETED) .conclusion(FAILURE) .build(); @@ -266,7 +268,7 @@ void shouldFetchJobDetailsForGivenWorkflowWhenLatestBuildIsSuccessAndPreviousBui @SneakyThrows void shouldFetchJobDetailsForGivenWorkflowWhenLatestBuildIsNotCompletedAndLastBuildStatusIsNotFailure( - RunStatus latestRunStatus, RunConclusion previousConclusion) { + String latestRunStatus, RunConclusion previousConclusion) { final WorkflowRunDetails latestWorkflowRunDetails = BASE_WORKFLOWS_RUN_DETAILS_RESPONSE.getWorkflowRuns().get(0).toBuilder() .status(latestRunStatus) @@ -343,7 +345,7 @@ void shouldFetchJobDetailsForGivenWorkflowWhenLatestBuildIsSuccessAndPreviousBui @MethodSource(value = "getPermutationOfWorkflowRunStatusAndPreviousConclusion") @SneakyThrows void shouldFetchJobDetailsForGivenWorkflowWhenLatestAndPreviousBothBuildsAreNotSuccessOrSkipped( - RunStatus latestRunStatus, RunConclusion previousConclusion) { + String latestRunStatus, RunConclusion previousConclusion) { final WorkflowRunDetails latestWorkflowRunDetails = BASE_WORKFLOWS_RUN_DETAILS_RESPONSE.getWorkflowRuns().get(0).toBuilder() .status(latestRunStatus) @@ -352,7 +354,7 @@ void shouldFetchJobDetailsForGivenWorkflowWhenLatestAndPreviousBothBuildsAreNotS final WorkflowRunDetails previousWorkflowRunDetails = BASE_WORKFLOWS_RUN_DETAILS_RESPONSE.getWorkflowRuns().get(1).toBuilder() - .status(COMPLETED) + .status(WorkflowRunDetails.COMPLETED) .conclusion(previousConclusion) .build(); @@ -456,7 +458,7 @@ void shouldFetchJobDetailsForGivenWorkflowWhenLatestAndPreviousBothBuildsAreNotS void shouldFetchJobDetailsWhenLatestBuildIsRunningAndItHasANewJobAddedAndLastJobIsSuccess() { final WorkflowRunDetails latestWorkflowRunDetails = BASE_WORKFLOWS_RUN_DETAILS_RESPONSE.getWorkflowRuns().get(0).toBuilder() - .status(IN_PROGRESS) + .status("in_progress") .conclusion(null) .build(); @@ -530,7 +532,7 @@ void shouldFetchJobDetailsWhenLatestBuildIsRunningAndItHasANewJobAddedAndLastJob @SneakyThrows void shouldFetchJobDetailsWhenLatestBuildIsRunningAndItHasANewJobAddedAndLastJobIsFailureConclusion( - RunStatus latestRunStatus, RunConclusion previousConclusion) { + String latestRunStatus, RunConclusion previousConclusion) { final WorkflowRunDetails latestWorkflowRunDetails = BASE_WORKFLOWS_RUN_DETAILS_RESPONSE.getWorkflowRuns().get(0).toBuilder() .status(latestRunStatus) @@ -539,7 +541,7 @@ void shouldFetchJobDetailsWhenLatestBuildIsRunningAndItHasANewJobAddedAndLastJob final WorkflowRunDetails previousWorkflowRunDetails = BASE_WORKFLOWS_RUN_DETAILS_RESPONSE.getWorkflowRuns().get(1).toBuilder() - .status(COMPLETED) + .status(WorkflowRunDetails.COMPLETED) .conclusion(previousConclusion) .build(); @@ -675,13 +677,13 @@ void shouldNotThrowErrorIfTheFetchJobDetailsRunsCallFails() { void shouldNotFetchJobDetailsForGivenWorkflowWhenTheDetailsIsPresentInCacheWithCompletedStatus() { final WorkflowRunDetails latestWorkflowRunDetails = BASE_WORKFLOWS_RUN_DETAILS_RESPONSE.getWorkflowRuns().get(0).toBuilder() - .status(COMPLETED) + .status(WorkflowRunDetails.COMPLETED) .conclusion(SUCCESS) .build(); final WorkflowRunDetails previousWorkflowRunDetails = BASE_WORKFLOWS_RUN_DETAILS_RESPONSE.getWorkflowRuns().get(1).toBuilder() - .status(COMPLETED) + .status(WorkflowRunDetails.COMPLETED) .conclusion(FAILURE) .build();