Skip to content

Commit

Permalink
fix(KFLUXBUGS-1751): release status replies on status & reason of rel…
Browse files Browse the repository at this point in the history
…ease type
  • Loading branch information
testcara committed Nov 11, 2024
1 parent ec397ae commit 06f8648
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/components/Releases/__tests__/ReleasesListRow.spec.tsx
Original file line number Diff line number Diff line change
@@ -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', () => ({
Expand All @@ -24,6 +25,7 @@ const mockRelease = {
{
reason: 'Succeeded',
status: 'True',
type: ReleaseCondition.Released,
},
],
},
Expand Down
22 changes: 11 additions & 11 deletions src/hooks/__tests__/useReleaseStatus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook } from '@testing-library/react-hooks';
import { ReleaseCondition } from '../../types';
import { useReleaseStatus } from '../useReleaseStatus';

const mockRelease = {
Expand All @@ -19,46 +20,45 @@ 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 },
],
},
}),
);
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 },
],
},
}),
);
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 },
],
},
}),
Expand Down
23 changes: 12 additions & 11 deletions src/hooks/useReleaseStatus.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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;
}
Expand Down

0 comments on commit 06f8648

Please sign in to comment.