import * as React from 'react'; import { Link, useParams } from 'react-router-dom'; import { Button, CodeBlock, CodeBlockCode, DescriptionList, DescriptionListGroup, DescriptionListTerm, DescriptionListDescription, Flex, FlexItem, Title, Divider, ClipboardCopy, Bullseye, Spinner, } from '@patternfly/react-core'; import GitRepoLink from '~/components/GitLink/GitRepoLink'; import MetadataList from '~/components/MetadataList'; import { useModalLauncher } from '~/components/modal/ModalProvider'; import { usePipelineRunImageData } from '~/components/PipelineRun/PipelineRunDetailsView/usePipelineRunImageData'; import { StatusIconWithText } from '~/components/StatusIcon/StatusIcon'; import { PipelineRunLabel, runStatus } from '~/consts/pipelinerun'; import { usePipelineRunV2 } from '~/hooks/usePipelineRunsV2'; import { useTaskRunsForPipelineRuns } from '~/hooks/useTaskRunsV2'; import { useSbomUrl } from '~/hooks/useUIInstance'; import { SNAPSHOT_DETAILS_PATH, PIPELINE_RUNS_LOG_PATH, APPLICATION_DETAILS_PATH, COMPONENT_DETAILS_PATH, COMMIT_DETAILS_PATH, INTEGRATION_TEST_DETAILS_PATH, } from '~/routes/paths'; import { RouterParams } from '~/routes/utils'; import { Timestamp } from '~/shared'; import ExternalLink from '~/shared/components/links/ExternalLink'; import { ErrorDetailsWithStaticLog } from '~/shared/components/pipeline-run-logs/logs/log-snippet-types'; import { getPLRLogSnippet } from '~/shared/components/pipeline-run-logs/logs/pipelineRunLogSnippet'; import { useNamespace } from '~/shared/providers/Namespace'; import { getErrorState } from '~/shared/utils/error-utils'; import { getCommitSha, getCommitShortName } from '~/utils/commits-utils'; import { calculateDuration, pipelineRunStatus } from '~/utils/pipeline-utils'; import { getSourceUrl } from '~/utils/pipelinerun-utils'; import RelatedPipelineRuns from '../RelatedPipelineRuns'; import { getSBOMsFromTaskRuns } from '../utils/pipelinerun-utils'; import PipelineRunVisualization from '../visualization/PipelineRunVisualization'; import { createPipelineRunSBOMsModal } from './PipelineRunSBOMsModal'; import RunParamsList from './RunParamsList'; import RunResultsList from './RunResultsList'; import ScanDescriptionListGroup from './ScanDescriptionListGroup'; import { SnapshotCreationStatus } from './SnapshotCreationStatus'; const PipelineRunDetailsTab: React.FC = () => { const pipelineRunName = useParams().pipelineRunName; const namespace = useNamespace(); const generateSbomUrl = useSbomUrl(); const showModal = useModalLauncher(); const [pipelineRun, loaded, error] = usePipelineRunV2(namespace, pipelineRunName); const [taskRuns, taskRunsLoaded, taskRunError] = useTaskRunsForPipelineRuns( namespace, pipelineRunName, ); const sboms = React.useMemo( () => (taskRuns ? getSBOMsFromTaskRuns(taskRuns, generateSbomUrl) : []), [taskRuns, generateSbomUrl], ); const { results: patchedResultsForProxy, params: patchedSpecParamsForProxy, imageUrl: displayImageUrl, } = usePipelineRunImageData(pipelineRun, namespace); if (!(loaded && taskRunsLoaded)) { return ( ); } if (error) { return getErrorState(error, loaded, 'pipeline run'); } const pipelineRunFailed = (getPLRLogSnippet(pipelineRun, taskRuns) || {}) as ErrorDetailsWithStaticLog; const duration = calculateDuration( typeof pipelineRun.status?.startTime === 'string' ? pipelineRun.status?.startTime : '', typeof pipelineRun.status?.completionTime === 'string' ? pipelineRun.status?.completionTime : '', ); const sha = getCommitSha(pipelineRun); const applicationName = pipelineRun.metadata?.labels[PipelineRunLabel.APPLICATION]; const sourceUrl = getSourceUrl(pipelineRun); const pipelineStatus = !error ? pipelineRunStatus(pipelineRun) : null; const integrationTestName = pipelineRun.metadata.labels[PipelineRunLabel.TEST_SERVICE_SCENARIO]; const snapshot = pipelineRun.metadata?.annotations?.[PipelineRunLabel.SNAPSHOT] || pipelineRun.metadata?.labels?.[PipelineRunLabel.SNAPSHOT]; const plrNamespace = pipelineRun.metadata?.annotations?.[PipelineRunLabel.RELEASE_NAMESPACE] || pipelineRun.metadata?.labels?.[PipelineRunLabel.RELEASE_NAMESPACE] || namespace; const showSbom = sboms && ((sboms.length === 1 && sboms[0].url) || sboms.length > 1); const showFailedMessage = pipelineStatus === runStatus.Failed && pipelineRun.status?.conditions?.length > 0 && pipelineRun.status?.conditions[0]?.message !== pipelineRunFailed.staticMessage; return ( <> Pipeline run details {taskRunError ? (
{getErrorState(taskRunError, taskRunsLoaded, 'task runs', true)}
) : ( )} {!error && ( <> Name {pipelineRun.metadata?.name ?? '-'} Namespace {pipelineRun.metadata?.namespace ?? '-'} Labels Annotations Created at Duration {duration ?? '-'} Status {Object.keys(pipelineRunFailed).length > 0 && ( <> Message {pipelineRunFailed.title ?? '-'} {showFailedMessage && ( {pipelineRun.status?.conditions[0]?.message} )} Log snippet {pipelineRunFailed.staticMessage ?? '-'} )} Pipeline {pipelineRun.metadata?.labels[PipelineRunLabel.PIPELINE_NAME] ?? '-'} {snapshot && ( Snapshot {snapshot} )} {displayImageUrl && ( Download SBOM {`cosign download sbom ${displayImageUrl}`} Install Cosign )} {showSbom && ( SBOM {sboms.length === 1 ? ( View SBOM ) : ( )} )} Application {pipelineRun.metadata?.labels?.[PipelineRunLabel.APPLICATION] ? ( {pipelineRun.metadata?.labels[PipelineRunLabel.APPLICATION]} ) : ( '-' )} {!taskRunError && ( )} Component {pipelineRun.metadata?.labels?.[PipelineRunLabel.COMPONENT] ? ( pipelineRun.metadata?.labels?.[PipelineRunLabel.APPLICATION] ? ( {pipelineRun.metadata.labels[PipelineRunLabel.COMPONENT]} ) : ( pipelineRun.metadata.labels[PipelineRunLabel.COMPONENT] ) ) : ( '-' )} {sha && ( Commit {getCommitShortName(sha)} )} {sourceUrl && ( Source )} {integrationTestName && ( Integration test {integrationTestName} )} Related pipelines {patchedResultsForProxy?.length ? ( <> ) : null} {patchedSpecParamsForProxy?.length && (
)} )} ); }; export default PipelineRunDetailsTab;