Skip to content

Commit

Permalink
Merge pull request #1018 from testcara/KFLUXBUGS-1751
Browse files Browse the repository at this point in the history
fix(KFLUXBUGS-1751):  release status replies on status and reason of the release type
  • Loading branch information
openshift-merge-bot[bot] authored Nov 14, 2024
2 parents 9c97585 + 06f8648 commit ba451ac
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 ba451ac

Please sign in to comment.