Skip to content

Commit eabc80b

Browse files
authored
Merge pull request #48 from sahil143/backport-release-fix
fix(KFLUXBUGS-1751): release status replies on status and reason of the release type
2 parents 3da4900 + 3752c0e commit eabc80b

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

src/components/Releases/__tests__/ReleaseOverviewTab.spec.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render, screen } from '@testing-library/react';
22
import { createK8sWatchResourceMock, createUseWorkspaceInfoMock } from '../../../utils/test-utils';
3-
import { mockReleases, mockReleaseWithManagedProcessing } from '../__data__/mock-release-data';
3+
import { mockReleases } from '../__data__/mock-release-data';
44
import ReleaseOverviewTab from '../ReleaseOverviewTab';
55

66
jest.mock('react-router-dom', () => ({
@@ -57,7 +57,7 @@ describe('ReleaseOverviewTab', () => {
5757
});
5858

5959
it('should render correct details if managedProcessing', () => {
60-
render(<ReleaseOverviewTab release={mockReleaseWithManagedProcessing} />);
60+
render(<ReleaseOverviewTab />);
6161
expect(screen.getByText('Pipeline Run')).toBeVisible();
6262
expect(screen.getByRole('link', { name: 'test-pipelinerun' }).getAttribute('href')).toBe(
6363
'/workspaces/target-ws/applications/test-app/pipelineruns/test-pipelinerun',

src/components/Releases/__tests__/ReleasesListRow.spec.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render } from '@testing-library/react';
2+
import { ReleaseCondition } from '../../../types';
23
import ReleasesListRow from '../ReleasesListRow';
34

45
jest.mock('react-router-dom', () => ({
@@ -21,6 +22,7 @@ const mockRelease = {
2122
{
2223
reason: 'Succeeded',
2324
status: 'True',
25+
type: ReleaseCondition.Released,
2426
},
2527
],
2628
},

src/hooks/__tests__/useReleaseStatus.spec.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { renderHook } from '@testing-library/react-hooks';
2+
import { ReleaseCondition } from '../../types';
23
import { useReleaseStatus } from '../useReleaseStatus';
34

45
const mockRelease = {
@@ -19,46 +20,45 @@ describe('useApplicationSnapshots', () => {
1920
expect(result.current).toEqual('Unknown');
2021
});
2122

22-
it('should return in progress if any of the conditions is progressing', () => {
23+
it('should return in progress if release condition is progressing', () => {
2324
const { result } = renderHook(() =>
2425
useReleaseStatus({
2526
...mockRelease,
2627
status: {
2728
conditions: [
28-
{ reason: 'Progressing' },
29-
{ reason: 'Succeeded', status: 'True' },
30-
{ reason: 'Failed', status: 'False' },
29+
{ reason: 'Succeeded', status: 'True', type: ReleaseCondition.Validated },
30+
{ reason: 'Progressing', status: 'True', type: ReleaseCondition.Released },
3131
],
3232
},
3333
}),
3434
);
3535
expect(result.current).toEqual('In Progress');
3636
});
3737

38-
it('should return in succeeded if all of the conditions pass', () => {
38+
it('should return in succeeded if release condition pass', () => {
3939
const { result } = renderHook(() =>
4040
useReleaseStatus({
4141
...mockRelease,
4242
status: {
4343
conditions: [
44-
{ reason: 'Succeeded', status: 'True' },
45-
{ reason: 'Succeeded', status: 'True' },
44+
{ reason: 'Succeeded', status: 'True', type: ReleaseCondition.Released },
45+
{ reason: 'Progressing', status: 'True', type: ReleaseCondition.Validated },
4646
],
4747
},
4848
}),
4949
);
5050
expect(result.current).toEqual('Succeeded');
5151
});
5252

53-
it('should return in failed if any of the conditions fail', () => {
53+
it('should return in failed if release condition is fail', () => {
5454
const { result } = renderHook(() =>
5555
useReleaseStatus({
5656
...mockRelease,
5757
status: {
5858
conditions: [
59-
{ reason: 'Succeeded', status: 'True' },
60-
{ reason: 'Succeeded', status: 'True' },
61-
{ reason: 'Failed', status: 'False' },
59+
{ reason: 'Succeeded', status: 'True', type: ReleaseCondition.Processed },
60+
{ reason: 'Succeeded', status: 'True', type: ReleaseCondition.Validated },
61+
{ reason: 'Failed', status: 'False', type: ReleaseCondition.Released },
6262
],
6363
},
6464
}),

src/hooks/useReleaseStatus.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { ReleaseKind } from '../types';
2+
import { ReleaseCondition, ReleaseKind } from '../types';
33
import { runStatus } from '../utils/pipeline-utils';
44

55
export const useReleaseStatus = (release: ReleaseKind) => {
@@ -8,21 +8,21 @@ export const useReleaseStatus = (release: ReleaseKind) => {
88
return runStatus.Unknown;
99
}
1010

11-
const progressing = release.status.conditions.some((c) => c.reason === 'Progressing');
12-
if (progressing) {
13-
return runStatus['In Progress'];
14-
}
15-
16-
const succeeded = release.status.conditions.every(
17-
(c) => c.reason === 'Succeeded' && c.status === 'True',
11+
const releasedCondition = release.status.conditions.find(
12+
(c) => c.type === ReleaseCondition.Released,
1813
);
14+
15+
const succeeded =
16+
releasedCondition.status === 'True' && releasedCondition.reason === 'Succeeded';
1917
if (succeeded) {
2018
return runStatus.Succeeded;
2119
}
20+
const progressing = releasedCondition.reason === 'Progressing';
21+
if (progressing) {
22+
return runStatus['In Progress'];
23+
}
2224

23-
const failed = release.status.conditions.some(
24-
(c) => c.reason === 'Failed' && c.status === 'False',
25-
);
25+
const failed = releasedCondition.reason === 'Failed' && releasedCondition.status === 'False';
2626
if (failed) {
2727
return runStatus.Failed;
2828
}

0 commit comments

Comments
 (0)