import { Link } from 'react-router-dom'; import { Alert, ClipboardCopy, DescriptionList, DescriptionListDescription, DescriptionListGroup, DescriptionListTerm, Grid, GridItem, Skeleton, Spinner, } from '@patternfly/react-core'; import { NAMESPACE_PIPELINE_RUN_DETAILS_PATH } from '@routes/paths'; import CommitLabel from '~/components/Commits/commit-label/CommitLabel'; import { DetailsSection } from '~/components/DetailsPage'; import ScanDescriptionListGroup from '~/components/PipelineRun/PipelineRunDetailsView/tabs/ScanDescriptionListGroup'; import { PipelineRunLabel } from '~/consts/pipelinerun'; import { useImageProxy } from '~/hooks/useImageProxy'; import { useImageRepository } from '~/hooks/useImageRepository'; import { useTaskRunsForPipelineRuns } from '~/hooks/useTaskRunsV2'; import { useIsImageControllerEnabled } from '~/image-controller/conditional-checks'; import { Timestamp } from '~/shared/components/timestamp/Timestamp'; import { getErrorState } from '~/shared/utils/error-utils'; import { ComponentKind, ImageRepositoryVisibility, PipelineRunKind } from '~/types'; import { createCommitObjectFromPLR } from '~/utils/commits-utils'; import { getImageUrlForVisibility } from '~/utils/component-utils'; import { getPipelineRunStatusResults, SBOMResultKeys } from '~/utils/pipeline-utils'; const IMAGE_URL_RESULT = 'IMAGE_URL'; const SelectedBuild: React.FC<{ component: ComponentKind; pipelineRun: PipelineRunKind }> = ({ component, pipelineRun, }) => { const namespace = component.metadata.namespace; const [taskRuns, tasksLoaded, tasksError] = useTaskRunsForPipelineRuns( namespace, pipelineRun.metadata.name, undefined, false, ); const [proxy, proxyLoaded, proxyError] = useImageProxy(); const [repository, repositoryLoaded, repositoryError] = useImageRepository( namespace, component.metadata.name, null, false, ); const { isImageControllerEnabled } = useIsImageControllerEnabled(); const results = getPipelineRunStatusResults(pipelineRun); const imageUrl = results?.find((result) => result.name === IMAGE_URL_RESULT)?.value; const digest = results?.find((result) => result.name === SBOMResultKeys.IMAGE_DIGEST)?.value; // Strip an existing tag/digest without removing a registry port. const image = imageUrl && digest ? `${imageUrl.split('@')[0].replace(/:[^/:]+$/, '')}@${digest}` : imageUrl; const visibility = isImageControllerEnabled ? repository?.spec.image?.visibility : null; const displayImage = getImageUrlForVisibility( image, visibility, proxyError || repositoryError ? null : proxy?.hostname, ); const imageLoading = isImageControllerEnabled && ((!repositoryLoaded && !repositoryError) || (visibility === ImageRepositoryVisibility.private && !proxyLoaded && !proxyError)); const commit = createCommitObjectFromPLR(pipelineRun); const routeParams = { workspaceName: namespace, pipelineRunName: pipelineRun.metadata.name }; const version = pipelineRun.metadata.labels?.[PipelineRunLabel.COMPONENT_VERSION]; return ( Build pipeline run {pipelineRun.metadata.name} Completed at{' '} {pipelineRun.status?.completionTime ? ( ) : ( '-' )} View build logs Triggered by {commit ? ( <> {commit.shaTitle}{' '} {commit.shaURL ? ( ) : ( commit.sha )} > ) : ( '-' )} Version {version || '-'} SBOM {imageLoading ? ( ) : displayImage ? ( {`cosign download sbom ${displayImage}`} ) : ( '-' )} Latest image {imageLoading ? ( ) : displayImage ? ( {displayImage} ) : ( '-' )} ) } /> ); }; const ComponentSuccessfulBuild: React.FC<{ component: ComponentKind; pipelineRun?: PipelineRunKind; loaded: boolean; error?: unknown; }> = ({ component, pipelineRun, loaded, error }) => ( {error ? ( getErrorState(error, true, 'pipeline run', true) ) : !loaded ? ( ) : pipelineRun ? ( ) : ( )} ); export default ComponentSuccessfulBuild;