import * as React from 'react'; import { Link } from 'react-router-dom'; import { Alert, DescriptionList, DescriptionListGroup, DescriptionListTerm, DescriptionListDescription, Flex, FlexItem, ClipboardCopy, Spinner, Button, } from '@patternfly/react-core'; import { useImageProxy } from '~/hooks/useImageProxy'; import { useImageRepository } from '~/hooks/useImageRepository'; import { useLatestSuccessfulBuildPipelineRunForComponentV2 } from '~/hooks/useLatestPushBuildPipeline'; import { useTaskRunsForPipelineRuns } from '~/hooks/useTaskRunsV2'; import { useIsImageControllerEnabled } from '~/image-controller/conditional-checks'; import { getErrorState } from '~/shared/utils/error-utils'; import { COMMIT_DETAILS_PATH } from '../../../../routes/paths'; import { Timestamp } from '../../../../shared/components/timestamp/Timestamp'; import { useNamespace } from '../../../../shared/providers/Namespace/useNamespaceInfo'; import { ComponentKind, ImageRepositoryVisibility } from '../../../../types'; import { getCommitsFromPLRs } from '../../../../utils/commits-utils'; import { getImageUrlForVisibility } from '../../../../utils/component-utils'; import CommitLabel from '../../../Commits/commit-label/CommitLabel'; import { useBuildLogViewerModal } from '../../../LogViewer/BuildLogViewer'; import ScanDescriptionListGroup from '../../../PipelineRun/PipelineRunDetailsView/tabs/ScanDescriptionListGroup'; type ComponentLatestBuildProps = { component: ComponentKind; }; const ComponentLatestBuild: React.FC> = ({ component, }) => { const namespace = useNamespace(); const [pipelineRun, pipelineRunLoaded, pipelineRunError] = useLatestSuccessfulBuildPipelineRunForComponentV2(namespace, component.metadata.name); const commit = React.useMemo( () => ((pipelineRunLoaded && pipelineRun && getCommitsFromPLRs([pipelineRun], 1)) || [])[0], [pipelineRunLoaded, pipelineRun], ); const [taskRuns, taskRunsLoaded, taskRunsError] = useTaskRunsForPipelineRuns( namespace, pipelineRun?.metadata?.name, ); const buildLogsModal = useBuildLogViewerModal(component); const { isImageControllerEnabled } = useIsImageControllerEnabled(); const [urlInfo, proxyLoaded, proxyError] = useImageProxy(); // Fetch ImageRepository for this component const [imageRepository, imageRepoLoaded, imageRepoError] = useImageRepository( component.metadata.namespace, component.metadata.name, null, false, ); // Avoid getLastestImage fallback to spec.containerImage, which lacks image tag // and causes 'cosign download sbom' to fail. Use lastPromotedImage explicitly. const containerImage = component?.status?.lastPromotedImage ?? null; // Get the appropriate image URL based on visibility // When image controller is disabled, skip proxy logic and use original URL // When proxy or imageRepo has error or urlInfo is null, fallback to original URL (null triggers fallback in getImageUrlForVisibility) const displayImageUrl = isImageControllerEnabled ? getImageUrlForVisibility( containerImage, imageRepository?.spec?.image?.visibility ?? null, proxyError || imageRepoError || !urlInfo ? null : urlInfo.hostname, ) : containerImage; if (pipelineRunError) { return getErrorState(pipelineRunError, pipelineRunLoaded, 'pipeline run', true); } // Note: imageRepoError is handled gracefully by falling back to original URL // We don't show error state to avoid blocking the entire component // Wait for all required data including proxy for private images // When image controller is disabled, skip waiting for image repo/proxy data // Once error occurs, fallback to display the content const isPrivate = isImageControllerEnabled && imageRepository?.spec?.image?.visibility === ImageRepositoryVisibility.private; if ( !pipelineRunLoaded || !taskRunsLoaded || (isImageControllerEnabled && !imageRepoLoaded && !imageRepoError) || (isPrivate && !proxyLoaded && !proxyError) ) { return (
); } if (!pipelineRun) { return ; } return ( Build pipeline run
Completed at
Triggered by {commit ? ( <> {commit.isPullRequest ? `#${commit.pullRequestNumber}` : ''} {commit.shaTitle} {commit.shaURL && ( <> {' '} )} ) : ( '-' )}
SBOM {displayImageUrl ? ( {`cosign download sbom ${displayImageUrl}`} ) : ( '-' )} Build container image {displayImageUrl ? ( {displayImageUrl} ) : ( '-' )}
); }; export default React.memo(ComponentLatestBuild);