From 06f86481c169a4b645818c576b7710937116a9bd Mon Sep 17 00:00:00 2001 From: Cara Wang Date: Tue, 5 Nov 2024 16:38:25 +0800 Subject: [PATCH] fix(KFLUXBUGS-1751): release status replies on status & reason of release type --- .../__tests__/ReleasesListRow.spec.tsx | 2 ++ src/hooks/__tests__/useReleaseStatus.ts | 22 +++++++++--------- src/hooks/useReleaseStatus.ts | 23 ++++++++++--------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/components/Releases/__tests__/ReleasesListRow.spec.tsx b/src/components/Releases/__tests__/ReleasesListRow.spec.tsx index 2966fd92d..fc579bfb1 100644 --- a/src/components/Releases/__tests__/ReleasesListRow.spec.tsx +++ b/src/components/Releases/__tests__/ReleasesListRow.spec.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import { render, configure } from '@testing-library/react'; +import { ReleaseCondition } from '../../../types'; import ReleasesListRow from '../ReleasesListRow'; jest.mock('react-router-dom', () => ({ @@ -24,6 +25,7 @@ const mockRelease = { { reason: 'Succeeded', status: 'True', + type: ReleaseCondition.Released, }, ], }, diff --git a/src/hooks/__tests__/useReleaseStatus.ts b/src/hooks/__tests__/useReleaseStatus.ts index 388901dbd..00923b596 100644 --- a/src/hooks/__tests__/useReleaseStatus.ts +++ b/src/hooks/__tests__/useReleaseStatus.ts @@ -1,4 +1,5 @@ import { renderHook } from '@testing-library/react-hooks'; +import { ReleaseCondition } from '../../types'; import { useReleaseStatus } from '../useReleaseStatus'; const mockRelease = { @@ -19,15 +20,14 @@ describe('useApplicationSnapshots', () => { expect(result.current).toEqual('Unknown'); }); - it('should return in progress if any of the conditions is progressing', () => { + it('should return in progress if release condition is progressing', () => { const { result } = renderHook(() => useReleaseStatus({ ...mockRelease, status: { conditions: [ - { reason: 'Progressing' }, - { reason: 'Succeeded', status: 'True' }, - { reson: 'Failed', status: 'False' }, + { reason: 'Succeeded', status: 'True', type: ReleaseCondition.Validated }, + { reason: 'Progressing', status: 'True', type: ReleaseCondition.Released }, ], }, }), @@ -35,14 +35,14 @@ describe('useApplicationSnapshots', () => { expect(result.current).toEqual('In Progress'); }); - it('should return in succeeded if all of the conditions pass', () => { + it('should return in succeeded if release condition is pass', () => { const { result } = renderHook(() => useReleaseStatus({ ...mockRelease, status: { conditions: [ - { reason: 'Succeeded', status: 'True' }, - { reason: 'Succeeded', status: 'True' }, + { reason: 'Succeeded', status: 'True', type: ReleaseCondition.Released }, + { reason: 'Progressing', status: 'True', type: ReleaseCondition.Validated }, ], }, }), @@ -50,15 +50,15 @@ describe('useApplicationSnapshots', () => { expect(result.current).toEqual('Succeeded'); }); - it('should return in failed if any of the conditions fail', () => { + it('should return in failed if release condition is fail', () => { const { result } = renderHook(() => useReleaseStatus({ ...mockRelease, status: { conditions: [ - { reason: 'Succeeded', status: 'True' }, - { reason: 'Succeeded', status: 'True' }, - { reason: 'Failed', status: 'False' }, + { reason: 'Succeeded', status: 'True', type: ReleaseCondition.Processed }, + { reason: 'Succeeded', status: 'True', type: ReleaseCondition.Validated }, + { reason: 'Failed', status: 'False', type: ReleaseCondition.Released }, ], }, }), diff --git a/src/hooks/useReleaseStatus.ts b/src/hooks/useReleaseStatus.ts index b9fbff664..326daa269 100644 --- a/src/hooks/useReleaseStatus.ts +++ b/src/hooks/useReleaseStatus.ts @@ -1,5 +1,5 @@ import * as React from 'react'; -import { ReleaseKind } from '../types'; +import { ReleaseCondition, ReleaseKind } from '../types'; import { runStatus } from '../utils/pipeline-utils'; export const useReleaseStatus = (release: ReleaseKind) => { @@ -8,21 +8,22 @@ export const useReleaseStatus = (release: ReleaseKind) => { return runStatus.Unknown; } - const progressing = release.status.conditions.some((c) => c.reason === 'Progressing'); - if (progressing) { - return runStatus['In Progress']; - } - - const succeeded = release.status.conditions.every( - (c) => c.reason === 'Succeeded' && c.status === 'True', + const releasedCondition = release.status.conditions.find( + (c) => c.type === ReleaseCondition.Released, ); + + const succeeded = + releasedCondition.status === 'True' && releasedCondition.reason === 'Succeeded'; if (succeeded) { return runStatus.Succeeded; } - const failed = release.status.conditions.some( - (c) => c.reason === 'Failed' && c.status === 'False', - ); + const progressing = releasedCondition.reason === 'Progressing'; + if (progressing) { + return runStatus['In Progress']; + } + + const failed = releasedCondition.reason === 'Failed' && releasedCondition.status === 'False'; if (failed) { return runStatus.Failed; }