From 0dd7d0f0fe85b86fc8ebe618f4609f8dd752ac78 Mon Sep 17 00:00:00 2001 From: Joao Pedro Poloni Ponce Date: Tue, 19 Nov 2024 18:43:42 -0300 Subject: [PATCH] fix(pipeline): null check on status of taskrun --- .../useEnterpriseContractResultFromLogs.spec.tsx | 14 ++++++++++++++ .../useEnterpriseContractResultFromLogs.tsx | 7 +++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/EnterpriseContract/__tests__/useEnterpriseContractResultFromLogs.spec.tsx b/src/components/EnterpriseContract/__tests__/useEnterpriseContractResultFromLogs.spec.tsx index b5614cf3..35343438 100644 --- a/src/components/EnterpriseContract/__tests__/useEnterpriseContractResultFromLogs.spec.tsx +++ b/src/components/EnterpriseContract/__tests__/useEnterpriseContractResultFromLogs.spec.tsx @@ -54,6 +54,20 @@ describe('useEnterpriseContractResultFromLogs', () => { expect(result.current[0][0].warnings).toEqual(undefined); }); + it('should call tknResults when taskRun is empty array', () => { + mockUseTaskRuns.mockReturnValueOnce([[], true, undefined]); + mockGetTaskRunLogs.mockReturnValue(`asdfcdfadsf + [report-json] { "components": [] } + `); + const { result } = renderHook(() => useEnterpriseContractResultFromLogs('dummy-abcd')); + const [, loaded] = result.current; + expect(mockCommmonFetchJSON).toHaveBeenCalled(); + expect(loaded).toBe(true); + expect(mockCommmonFetchJSON).toHaveBeenLastCalledWith( + '/api/v1/namespaces/test-ns/pods/pod-acdf/log?container=step-report-json&follow=true', + ); + }); + it('should filter out all 404 image url components from EC results', async () => { const { result, waitForNextUpdate } = renderHook(() => useEnterpriseContractResultFromLogs('dummy-abcd'), diff --git a/src/components/EnterpriseContract/useEnterpriseContractResultFromLogs.tsx b/src/components/EnterpriseContract/useEnterpriseContractResultFromLogs.tsx index db13bc9b..29aece3d 100644 --- a/src/components/EnterpriseContract/useEnterpriseContractResultFromLogs.tsx +++ b/src/components/EnterpriseContract/useEnterpriseContractResultFromLogs.tsx @@ -22,7 +22,7 @@ export const useEnterpriseContractResultFromLogs = ( const [ecJson, setEcJson] = React.useState(); const [ecLoaded, setEcLoaded] = React.useState(false); const ecResultOpts = React.useMemo(() => { - const podName = loaded && !error ? taskRun[0].status.podName : null; + const podName = loaded && !error ? taskRun?.[0]?.status?.podName : null; return podName ? { ns: namespace, @@ -38,6 +38,9 @@ export const useEnterpriseContractResultFromLogs = ( React.useEffect(() => { let unmount = false; + if (loaded && !ecResultOpts) { + setFetchTknLogs(true); + } if (ecResultOpts) { commonFetchJSON(getK8sResourceURL(PodModel, undefined, ecResultOpts)) .then((res: EnterpriseContractResult) => { @@ -59,7 +62,7 @@ export const useEnterpriseContractResultFromLogs = ( return () => { unmount = true; }; - }, [ecResultOpts]); + }, [ecResultOpts, loaded]); React.useEffect(() => { let unmount = false;