Skip to content

Commit 740a939

Browse files
committed
fix(pipeline): null check on status of taskrun
1 parent 06ab0bb commit 740a939

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/components/EnterpriseContract/__tests__/useEnterpriseContractResultFromLogs.spec.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ describe('useEnterpriseContractResultFromLogs', () => {
5454
expect(result.current[0][0].warnings).toEqual(undefined);
5555
});
5656

57+
it('should call tknResults when taskRun is empty array', () => {
58+
mockUseTaskRuns.mockReturnValueOnce([[], true, undefined]);
59+
mockGetTaskRunLogs.mockReturnValue(`asdfcdfadsf
60+
[report-json] { "components": [] }
61+
`);
62+
const { result } = renderHook(() => useEnterpriseContractResultFromLogs('dummy-abcd'));
63+
const [, loaded] = result.current;
64+
expect(mockCommmonFetchJSON).toHaveBeenCalled();
65+
expect(loaded).toBe(true);
66+
expect(mockCommmonFetchJSON).toHaveBeenLastCalledWith(
67+
'/api/v1/namespaces/test-ns/pods/pod-acdf/log?container=step-report-json&follow=true',
68+
);
69+
});
70+
5771
it('should filter out all 404 image url components from EC results', async () => {
5872
const { result, waitForNextUpdate } = renderHook(() =>
5973
useEnterpriseContractResultFromLogs('dummy-abcd'),

src/components/EnterpriseContract/useEnterpriseContractResultFromLogs.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const useEnterpriseContractResultFromLogs = (
2121
const [ecJson, setEcJson] = React.useState<EnterpriseContractResult>();
2222
const [ecLoaded, setEcLoaded] = React.useState<boolean>(false);
2323
const ecResultOpts = React.useMemo(() => {
24-
const podName = loaded && !error ? taskRun[0].status.podName : null;
24+
const podName = loaded && !error ? taskRun?.[0]?.status?.podName : null;
2525
return podName
2626
? {
2727
ns: namespace,
@@ -37,6 +37,9 @@ export const useEnterpriseContractResultFromLogs = (
3737

3838
React.useEffect(() => {
3939
let unmount = false;
40+
if (loaded && !ecResultOpts) {
41+
setFetchTknLogs(true);
42+
}
4043
if (ecResultOpts) {
4144
commonFetchJSON(getK8sResourceURL(PodModel, undefined, ecResultOpts))
4245
.then((res: EnterpriseContractResult) => {
@@ -58,7 +61,7 @@ export const useEnterpriseContractResultFromLogs = (
5861
return () => {
5962
unmount = true;
6063
};
61-
}, [ecResultOpts]);
64+
}, [ecResultOpts, loaded]);
6265

6366
React.useEffect(() => {
6467
let unmount = false;

0 commit comments

Comments
 (0)