diff --git a/src/components/EnterpriseContract/useEnterpriseContractResultFromLogs.tsx b/src/components/EnterpriseContract/useEnterpriseContractResultFromLogs.tsx index 193e771..db13bc9 100644 --- a/src/components/EnterpriseContract/useEnterpriseContractResultFromLogs.tsx +++ b/src/components/EnterpriseContract/useEnterpriseContractResultFromLogs.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { useTaskRuns } from '../../hooks/useTaskRuns'; import { commonFetchJSON, getK8sResourceURL } from '../../k8s'; import { PodModel } from '../../models/pod'; +import { getPipelineRunFromTaskRunOwnerRef } from '../../utils/common-utils'; import { getTaskRunLog } from '../../utils/tekton-results'; import { useWorkspaceInfo } from '../Workspace/useWorkspaceInfo'; import { @@ -65,10 +66,12 @@ export const useEnterpriseContractResultFromLogs = ( if (fetchTknLogs) { const fetch = async () => { try { + const pid = getPipelineRunFromTaskRunOwnerRef(taskRun[0])?.uid; const logs = await getTaskRunLog( workspace, taskRun[0].metadata.namespace, - taskRun[0].metadata.name, + taskRun[0].metadata.uid, + pid, ); if (unmount) return; const json = extractEcResultsFromTaskRunLogs(logs); diff --git a/src/hooks/__tests__/useTektonResults.spec.tsx b/src/hooks/__tests__/useTektonResults.spec.tsx index bf7fb29..4ce4ac9 100644 --- a/src/hooks/__tests__/useTektonResults.spec.tsx +++ b/src/hooks/__tests__/useTektonResults.spec.tsx @@ -2,6 +2,8 @@ // import { QueryClientProvider } from '@tanstack/react-query'; // import { act, renderHook as rtlRenderHook } from '@testing-library/react-hooks'; import { renderHook } from '@testing-library/react-hooks'; +import { PipelineRunModel } from '../../models'; +import { TaskRunKind } from '../../types'; import { // TektonResultsOptions, getPipelineRuns, @@ -180,6 +182,16 @@ describe('useTektonResults', () => { }); }); + const mockTR = { + metadata: { + name: 'sample-task-run', + uid: 'sample-task-run-id', + ownerReferences: [ + { kind: PipelineRunModel.kind, uid: 'sample-pipeline-run-id', name: 'sample-pipeline-run' }, + ], + }, + } as TaskRunKind; + describe('useTRTaskRunLog', () => { it('should not attempt to get task run log', () => { renderHook(() => useTRTaskRunLog(null, null)); @@ -188,14 +200,19 @@ describe('useTektonResults', () => { renderHook(() => useTRTaskRunLog('test-ns', null)); expect(getTaskRunLogMock).not.toHaveBeenCalled(); - renderHook(() => useTRTaskRunLog(null, 'sample-task-run')); + renderHook(() => useTRTaskRunLog(null, mockTR)); expect(getTaskRunLogMock).not.toHaveBeenCalled(); }); it('should return task run log', async () => { getTaskRunLogMock.mockReturnValue('sample log'); - const { result, waitFor } = renderHook(() => useTRTaskRunLog('test-ns', 'sample-task-run')); - expect(getTaskRunLogMock).toHaveBeenCalledWith('test-ws', 'test-ns', 'sample-task-run'); + const { result, waitFor } = renderHook(() => useTRTaskRunLog('test-ns', mockTR)); + expect(getTaskRunLogMock).toHaveBeenCalledWith( + 'test-ws', + 'test-ns', + 'sample-task-run-id', + 'sample-pipeline-run-id', + ); expect(result.current).toEqual([null, false, undefined]); await waitFor(() => result.current[1]); expect(result.current).toEqual(['sample log', true, undefined]); @@ -206,8 +223,13 @@ describe('useTektonResults', () => { getTaskRunLogMock.mockImplementation(() => { throw error; }); - const { result } = renderHook(() => useTRTaskRunLog('test-ns', 'sample-task-run')); - expect(getTaskRunLogMock).toHaveBeenCalledWith('test-ws', 'test-ns', 'sample-task-run'); + const { result } = renderHook(() => useTRTaskRunLog('test-ns', mockTR)); + expect(getTaskRunLogMock).toHaveBeenCalledWith( + 'test-ws', + 'test-ns', + 'sample-task-run-id', + 'sample-pipeline-run-id', + ); expect(result.current).toEqual([null, false, error]); }); }); diff --git a/src/hooks/useTektonResults.ts b/src/hooks/useTektonResults.ts index 3192273..24f8e3f 100644 --- a/src/hooks/useTektonResults.ts +++ b/src/hooks/useTektonResults.ts @@ -2,6 +2,7 @@ import React from 'react'; import { useInfiniteQuery } from '@tanstack/react-query'; import { useWorkspaceInfo } from '../components/Workspace/useWorkspaceInfo'; import { PipelineRunKind, TaskRunKind } from '../types'; +import { getPipelineRunFromTaskRunOwnerRef } from '../utils/common-utils'; import { TektonResultsOptions, getTaskRunLog, @@ -61,16 +62,18 @@ export const useTRTaskRuns = ( export const useTRTaskRunLog = ( namespace: string, - taskRunName: string, + taskRun: TaskRunKind, ): [string, boolean, unknown] => { const { workspace } = useWorkspaceInfo(); const [result, setResult] = React.useState<[string, boolean, unknown]>([null, false, undefined]); + const taskRunUid = taskRun.metadata.uid; + const pipelineRunUid = getPipelineRunFromTaskRunOwnerRef(taskRun)?.uid; React.useEffect(() => { let disposed = false; - if (namespace && taskRunName) { + if (namespace && taskRunUid) { void (async () => { try { - const log = await getTaskRunLog(workspace, namespace, taskRunName); + const log = await getTaskRunLog(workspace, namespace, taskRunUid, pipelineRunUid); if (!disposed) { setResult([log, true, undefined]); } @@ -84,6 +87,6 @@ export const useTRTaskRunLog = ( return () => { disposed = true; }; - }, [workspace, namespace, taskRunName]); + }, [workspace, namespace, taskRunUid, pipelineRunUid]); return result; }; diff --git a/src/shared/components/pipeline-run-logs/logs/TektonTaskRunLog.tsx b/src/shared/components/pipeline-run-logs/logs/TektonTaskRunLog.tsx index 290a16e..a95fa34 100644 --- a/src/shared/components/pipeline-run-logs/logs/TektonTaskRunLog.tsx +++ b/src/shared/components/pipeline-run-logs/logs/TektonTaskRunLog.tsx @@ -19,10 +19,7 @@ export const TektonTaskRunLog: React.FC { const scrollPane = React.useRef(); const taskName = taskRun?.spec.taskRef?.name ?? taskRun?.metadata.name; - const [trResults, trLoaded, trError] = useTRTaskRunLog( - taskRun.metadata.namespace, - taskRun.metadata.name, - ); + const [trResults, trLoaded, trError] = useTRTaskRunLog(taskRun.metadata.namespace, taskRun); React.useEffect(() => { setCurrentLogsGetter(() => scrollPane.current?.innerText); diff --git a/src/shared/components/pipeline-run-logs/logs/logs-utils.ts b/src/shared/components/pipeline-run-logs/logs/logs-utils.ts index e16a101..1d437e4 100644 --- a/src/shared/components/pipeline-run-logs/logs/logs-utils.ts +++ b/src/shared/components/pipeline-run-logs/logs/logs-utils.ts @@ -2,6 +2,7 @@ import { saveAs } from 'file-saver'; import { commonFetchText } from '../../../../k8s'; import { K8sGetResource } from '../../../../k8s/k8s-fetch'; import { getK8sResourceURL } from '../../../../k8s/k8s-utils'; +import { PipelineRunModel } from '../../../../models'; import { PodModel } from '../../../../models/pod'; import { TaskRunKind } from '../../../../types'; import { getTaskRunLog } from '../../../../utils/tekton-results'; @@ -146,9 +147,16 @@ export const getDownloadAllLogsCallback = ( ]); } } else { - allLogs += await getTaskRunLog(workspace, namespace, currTask).then( - (log) => `${tasks[currTask].name.toUpperCase()}\n\n${log}\n\n`, - ); + const taskRun = taskRuns.find((t) => t.metadata.name === currTask); + const pipelineRunUID = taskRun?.metadata?.ownerReferences?.find( + (res) => res.kind === PipelineRunModel.kind, + )?.uid; + allLogs += await getTaskRunLog( + workspace, + namespace, + pipelineRunUID, + taskRun?.metadata?.uid, + ).then((log) => `${tasks[currTask].name.toUpperCase()}\n\n${log}\n\n`); } } const buffer = new LineBuffer(); diff --git a/src/utils/__tests__/tekton-results.spec.ts b/src/utils/__tests__/tekton-results.spec.ts index f35584f..327b115 100644 --- a/src/utils/__tests__/tekton-results.spec.ts +++ b/src/utils/__tests__/tekton-results.spec.ts @@ -348,11 +348,18 @@ describe('tekton-results', () => { describe('createTektonResultsUrl', () => { it('should create minimal URL', () => { - expect(createTektonResultsUrl('test-ws', 'test-ns', DataType.PipelineRun)).toEqual( - '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&filter=data_type+%3D%3D+%22tekton.dev%2Fv1beta1.PipelineRun%22', + expect( + createTektonResultsUrl('test-ws', 'test-ns', [ + DataType.PipelineRun, + DataType.PipelineRun_v1beta1, + ]), + ).toEqual( + '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&filter=data_type+in+%5B%22tekton.dev%2Fv1.PipelineRun%22%2C%22tekton.dev%2Fv1beta1.PipelineRun%22%5D', ); - expect(createTektonResultsUrl('test-ws', 'test-ns', DataType.TaskRun)).toEqual( - '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&filter=data_type+%3D%3D+%22tekton.dev%2Fv1beta1.TaskRun%22', + expect( + createTektonResultsUrl('test-ws', 'test-ns', [DataType.TaskRun, DataType.TaskRun_v1beta1]), + ).toEqual( + '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&filter=data_type+in+%5B%22tekton.dev%2Fv1.TaskRun%22%2C%22tekton.dev%2Fv1beta1.TaskRun%22%5D', ); }); @@ -361,7 +368,7 @@ describe('tekton-results', () => { createTektonResultsUrl( 'test-ws', 'test-ns', - DataType.PipelineRun, + [DataType.PipelineRun, DataType.PipelineRun_v1beta1], null, null, 'test-token', @@ -370,37 +377,65 @@ describe('tekton-results', () => { }); it('should create URL with filter', () => { - expect(createTektonResultsUrl('test-ws', 'test-ns', DataType.PipelineRun, 'foo=bar')).toEqual( - '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&filter=data_type+%3D%3D+%22tekton.dev%2Fv1beta1.PipelineRun%22+%26%26+foo%3Dbar', + expect( + createTektonResultsUrl( + 'test-ws', + 'test-ns', + [DataType.PipelineRun, DataType.PipelineRun_v1beta1], + 'foo=bar', + ), + ).toEqual( + '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&filter=data_type+in+%5B%22tekton.dev%2Fv1.PipelineRun%22%2C%22tekton.dev%2Fv1beta1.PipelineRun%22%5D+%26%26+foo%3Dbar', ); }); it('should create URL with page size', () => { // default page size - expect(createTektonResultsUrl('test-ws', 'test-ns', DataType.PipelineRun)).toContain( - 'page_size=30', - ); + expect( + createTektonResultsUrl('test-ws', 'test-ns', [ + DataType.PipelineRun, + DataType.PipelineRun_v1beta1, + ]), + ).toContain('page_size=30'); // min page size expect( - createTektonResultsUrl('test-ws', 'test-ns', DataType.PipelineRun, '', { - pageSize: 1, - }), + createTektonResultsUrl( + 'test-ws', + 'test-ns', + [DataType.PipelineRun, DataType.PipelineRun_v1beta1], + '', + { + pageSize: 1, + }, + ), ).toContain('page_size=5'); // min page size expect( - createTektonResultsUrl('test-ws', 'test-ns', DataType.PipelineRun, '', { - pageSize: 11000, - }), + createTektonResultsUrl( + 'test-ws', + 'test-ns', + [DataType.PipelineRun, DataType.PipelineRun_v1beta1], + '', + { + pageSize: 11000, + }, + ), ).toContain('page_size=10000'); }); it('should create URL using limit to affect page size', () => { expect( - createTektonResultsUrl('test-ws', 'test-ns', DataType.PipelineRun, '', { - pageSize: 10, - limit: 5, - }), + createTektonResultsUrl( + 'test-ws', + 'test-ns', + [DataType.PipelineRun, DataType.PipelineRun_v1beta1], + '', + { + pageSize: 10, + limit: 5, + }, + ), ).toContain('page_size=5'); }); @@ -409,12 +444,12 @@ describe('tekton-results', () => { createTektonResultsUrl( 'test-ws', 'test-ns', - DataType.PipelineRun, + [DataType.PipelineRun, DataType.PipelineRun_v1beta1], 'foo=bar', sampleOptions, ), ).toContain( - 'filter=data_type+%3D%3D+%22tekton.dev%2Fv1beta1.PipelineRun%22+%26%26+foo%3Dbar+%26%26+data.metadata.labels%5B%22test%22%5D+%3D%3D+%22a%22+%26%26+data.metadata.labels%5B%22mtest%22%5D+%3D%3D+%22ma%22+%26%26+count+%3E+1', + '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&filter=data_type+in+%5B%22tekton.dev%2Fv1.PipelineRun%22%2C%22tekton.dev%2Fv1beta1.PipelineRun%22%5D+%26%26+foo%3Dbar+%26%26+data.metadata.labels%5B%22test%22%5D+%3D%3D+%22a%22+%26%26+data.metadata.labels%5B%22mtest%22%5D+%3D%3D+%22ma%22+%26%26+count+%3E+1', ); }); }); @@ -423,8 +458,14 @@ describe('tekton-results', () => { it('should return cached value', async () => { commonFetchJSONMock.mockReturnValue(mockEmptyRecordsList); - await getFilteredRecord('test-ws', 'test-ns', DataType.PipelineRun); - await getFilteredRecord('test-ws', 'test-ns', DataType.PipelineRun); + await getFilteredRecord('test-ws', 'test-ns', [ + DataType.PipelineRun, + DataType.PipelineRun_v1beta1, + ]); + await getFilteredRecord('test-ws', 'test-ns', [ + DataType.PipelineRun, + DataType.PipelineRun_v1beta1, + ]); expect(commonFetchJSONMock).toHaveBeenCalledTimes(2); commonFetchJSONMock.mockClear(); @@ -432,7 +473,7 @@ describe('tekton-results', () => { await getFilteredRecord( 'test-ws', 'test-ns', - DataType.PipelineRun, + [DataType.PipelineRun, DataType.PipelineRun_v1beta1], null, null, null, @@ -441,7 +482,7 @@ describe('tekton-results', () => { await getFilteredRecord( 'test-ws', 'test-ns', - DataType.PipelineRun, + [DataType.PipelineRun, DataType.PipelineRun_v1beta1], null, null, null, @@ -456,7 +497,10 @@ describe('tekton-results', () => { code: 404, }; }); - const result = await getFilteredRecord('test-ws', 'test-ns', DataType.PipelineRun); + const result = await getFilteredRecord('test-ws', 'test-ns', [ + DataType.PipelineRun, + DataType.PipelineRun_v1beta1, + ]); expect(result).toEqual([[], { nextPageToken: null, records: [] }]); }); @@ -467,21 +511,33 @@ describe('tekton-results', () => { }; }); await expect( - getFilteredRecord('test-ws', 'test-ns', DataType.PipelineRun), + getFilteredRecord('test-ws', 'test-ns', [ + DataType.PipelineRun, + DataType.PipelineRun_v1beta1, + ]), ).rejects.toBeTruthy(); }); it('should return record list and decoded value', async () => { commonFetchJSONMock.mockReturnValue(mockRecordsList); - expect(await getFilteredRecord('test-ws', 'test-ns', DataType.PipelineRun)).toEqual( - mockResponseCheck, - ); + expect( + await getFilteredRecord('test-ws', 'test-ns', [ + DataType.PipelineRun, + DataType.PipelineRun_v1beta1, + ]), + ).toEqual(mockResponseCheck); }); it('should return record list and decoded value', async () => { commonFetchJSONMock.mockReturnValue(mockRecordsList); expect( - await getFilteredRecord('test-ws', 'test-ns', DataType.PipelineRun, null, { limit: 1 }), + await getFilteredRecord( + 'test-ws', + 'test-ns', + [DataType.PipelineRun, DataType.PipelineRun_v1beta1], + null, + { limit: 1 }, + ), ).toEqual([ [mockResponseCheck[0][0]], { @@ -501,7 +557,7 @@ describe('tekton-results', () => { it('should query tekton results with options', async () => { await getPipelineRuns('test-ws', 'test-ns', sampleOptions, 'test-token'); expect(commonFetchJSONMock).toHaveBeenCalledWith( - '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&page_token=test-token&filter=data_type+%3D%3D+%22tekton.dev%2Fv1beta1.PipelineRun%22+%26%26+data.metadata.labels%5B%22test%22%5D+%3D%3D+%22a%22+%26%26+data.metadata.labels%5B%22mtest%22%5D+%3D%3D+%22ma%22+%26%26+count+%3E+1', + '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&page_token=test-token&filter=data_type+in+%5B%22tekton.dev%2Fv1.PipelineRun%22%2C%22tekton.dev%2Fv1beta1.PipelineRun%22%5D+%26%26+data.metadata.labels%5B%22test%22%5D+%3D%3D+%22a%22+%26%26+data.metadata.labels%5B%22mtest%22%5D+%3D%3D+%22ma%22+%26%26+count+%3E+1', ); }); }); @@ -515,7 +571,7 @@ describe('tekton-results', () => { it('should query tekton results with options', async () => { await getTaskRuns('test-ws', 'test-ns', sampleOptions, 'test-token'); expect(commonFetchJSONMock).toHaveBeenCalledWith( - '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&page_token=test-token&filter=data_type+%3D%3D+%22tekton.dev%2Fv1beta1.TaskRun%22+%26%26+data.metadata.labels%5B%22test%22%5D+%3D%3D+%22a%22+%26%26+data.metadata.labels%5B%22mtest%22%5D+%3D%3D+%22ma%22+%26%26+count+%3E+1', + '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=30&page_token=test-token&filter=data_type+in+%5B%22tekton.dev%2Fv1.TaskRun%22%2C%22tekton.dev%2Fv1beta1.TaskRun%22%5D+%26%26+data.metadata.labels%5B%22test%22%5D+%3D%3D+%22a%22+%26%26+data.metadata.labels%5B%22mtest%22%5D+%3D%3D+%22ma%22+%26%26+count+%3E+1', ); }); }); @@ -524,22 +580,19 @@ describe('tekton-results', () => { it('should return the latest component build task run', async () => { commonFetchJSONMock.mockReturnValueOnce(mockLogsRecordsList); commonFetchTextMock.mockReturnValueOnce(Promise.resolve(mockLogResponse)); - expect(await getTaskRunLog('test-ws', 'test-ns', 'sample-task-run')).toEqual('sample log'); - expect(commonFetchJSONMock.mock.calls).toEqual([ - [ - '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/-/records?order_by=create_time+desc&page_size=5&filter=data_type+%3D%3D+%22results.tekton.dev%2Fv1alpha2.Log%22+%26%26+data.spec.resource.kind+%3D%3D+%22TaskRun%22+%26%26+data.spec.resource.name+%3D%3D+%22sample-task-run%22', - ], - ]); + expect(await getTaskRunLog('test-ws', 'test-ns', 'pipelinerun-uid', 'test-id')).toEqual( + 'sample log', + ); expect(commonFetchTextMock.mock.calls).toEqual([ [ - '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/b9f43742-3675-4a71-8d73-31c5f5080a74/logs/113298cc-07f9-3ce0-85e3-5cf635eacf62', + '/plugins/tekton-results/workspaces/test-ws/apis/results.tekton.dev/v1alpha2/parents/test-ns/results/pipelinerun-uid/logs/test-id', ], ]); }); it('should throw error 404 if record not found', async () => { - commonFetchJSONMock.mockReturnValue(mockEmptyRecordsList); - await expect(getTaskRunLog('test-ws', 'test-ns', 'sample-task-run')).rejects.toEqual({ + commonFetchTextMock.mockClear().mockRejectedValue(mockEmptyRecordsList); + await expect(getTaskRunLog('test-ws', 'test-ns', 'sample-task-run', 'test')).rejects.toEqual({ code: 404, }); }); diff --git a/src/utils/common-utils.tsx b/src/utils/common-utils.tsx new file mode 100644 index 0000000..85c86a8 --- /dev/null +++ b/src/utils/common-utils.tsx @@ -0,0 +1,13 @@ +import { curry } from 'lodash-es'; +import { PipelineRunModel } from '../models'; +import { K8sModelCommon, K8sResourceCommon, OwnerReference } from '../types/k8s'; + +export const getResourceFromOwnerReference = curry( + (model: K8sModelCommon, resource: K8sResourceCommon): OwnerReference => { + return resource + ? resource.metadata.ownerReferences?.find((res) => res.kind === model.kind) + : undefined; + }, +); + +export const getPipelineRunFromTaskRunOwnerRef = getResourceFromOwnerReference(PipelineRunModel); diff --git a/src/utils/tekton-results.ts b/src/utils/tekton-results.ts index 32589a7..8b95771 100644 --- a/src/utils/tekton-results.ts +++ b/src/utils/tekton-results.ts @@ -72,13 +72,20 @@ export const OR = (...expressions: string[]) => { const EXP = (left: string, right: string, operator: string) => `${left} ${operator} ${right}`; export const EQ = (left: string, right: string) => EXP(left, `"${right}"`, '=='); export const NEQ = (left: string, right: string) => EXP(left, `"${right}"`, '!='); +export const IN = (left: string, right: string[]) => { + const rightOperands = right.map((operand) => `"${operand.toString()}"`); + return EXP(left, `[${rightOperands.join(',')}]`, 'in'); +}; // TODO: switch to v1 once API is ready // https://github.com/tektoncd/community/pull/1055 export enum DataType { - PipelineRun = 'tekton.dev/v1beta1.PipelineRun', - TaskRun = 'tekton.dev/v1beta1.TaskRun', - Log = 'results.tekton.dev/v1alpha2.Log', + PipelineRun = 'tekton.dev/v1.PipelineRun', + TaskRun = 'tekton.dev/v1.TaskRun', + Log = 'results.tekton.dev/v1alpha3.Log', + PipelineRun_v1beta1 = 'tekton.dev/v1beta1.PipelineRun', + TaskRun_v1beta1 = 'tekton.dev/v1beta1.TaskRun', + Log_v1alpha2 = 'results.tekton.dev/v1alpha2.Log', } export const labelsToFilter = (labels?: MatchLabels): string => @@ -191,7 +198,7 @@ const getTRUrlPrefix = (workspace: string): string => URL_PREFIX.replace(_WORKSP export const createTektonResultsUrl = ( workspace: string, namespace: string, - dataType: DataType, + dataTypes: DataType[], filter?: string, options?: TektonResultsOptions, nextPageToken?: string, @@ -205,7 +212,7 @@ export const createTektonResultsUrl = ( )}`, ...(nextPageToken ? { ['page_token']: nextPageToken } : {}), filter: AND( - EQ('data_type', dataType.toString()), + IN('data_type', dataTypes), filter, selectorToFilter(options?.selector), options?.filter, @@ -215,7 +222,7 @@ export const createTektonResultsUrl = ( export const getFilteredRecord = async ( workspace: string, namespace: string, - dataType: DataType, + dataTypes: DataType[], filter?: string, options?: TektonResultsOptions, nextPageToken?: string, @@ -224,7 +231,7 @@ export const getFilteredRecord = async ( const url = createTektonResultsUrl( workspace, namespace, - dataType, + dataTypes, filter, options, nextPageToken, @@ -290,7 +297,7 @@ const getFilteredPipelineRuns = ( getFilteredRecord( workspace, namespace, - DataType.PipelineRun, + [DataType.PipelineRun, DataType.PipelineRun_v1beta1], filter, options, nextPageToken, @@ -308,7 +315,7 @@ const getFilteredTaskRuns = ( getFilteredRecord( workspace, namespace, - DataType.TaskRun, + [DataType.TaskRun, DataType.TaskRun_v1beta1], filter, options, nextPageToken, @@ -333,25 +340,18 @@ export const getTaskRuns = ( cacheKey?: string, ) => getFilteredTaskRuns(workspace, namespace, '', options, nextPageToken, cacheKey); -const getLog = (workspace: string, taskRunPath: string) => - commonFetchText(`${getTRUrlPrefix(workspace)}/${taskRunPath.replace('/records/', '/logs/')}`); +// const getLog = (workspace: string, taskRunPath: string) => +// commonFetchText(`${getTRUrlPrefix(workspace)}/${taskRunPath.replace('/records/', '/logs/')}`); export const getTaskRunLog = ( workspace: string, namespace: string, - taskRunName: string, + pid: string, + taskRunID: string, ): Promise => - getFilteredRecord( - workspace, - namespace, - DataType.Log, - AND(EQ(`data.spec.resource.kind`, 'TaskRun'), EQ(`data.spec.resource.name`, taskRunName)), - { limit: 1 }, - ).then((x) => - x?.[1]?.records.length > 0 - ? getLog(workspace, x?.[1]?.records[0].name).catch(() => throw404()) - : throw404(), - ); + commonFetchText( + `${getTRUrlPrefix(workspace)}/${namespace}/results/${pid}/logs/${taskRunID}`, + ).catch(() => throw404()); export const createTektonResultsQueryKeys = ( model: K8sModelCommon,