import * as React from 'react'; import { Link } from 'react-router-dom'; import { Alert, Flex, FlexItem, Skeleton } from '@patternfly/react-core'; import { COMPONENT_VERSION_DETAILS_PATH } from '@routes/paths'; import CommitLabel from '~/components/Commits/commit-label/CommitLabel'; import { PipelineRunLabel } from '~/consts/pipelinerun'; import { useLatestPushBuildPipelineRunForComponentV2 } from '~/hooks/useLatestPushBuildPipeline'; import { useNamespace } from '~/shared/providers/Namespace'; import { getErrorState } from '~/shared/utils/error-utils'; import { getCommitsFromPLRs } from '~/utils/commits-utils'; import PipelineRunStatus from '../PipelineRun/PipelineRunStatus'; import './LatestPushBuildSection.scss'; type LatestPushBuildSectionProps = { componentName: string; version?: string; }; const LatestPushBuildSection: React.FC = ({ componentName, version, }) => { const namespace = useNamespace(); const [pipelineRun, pipelineRunLoaded, pipelineRunError] = useLatestPushBuildPipelineRunForComponentV2(namespace, componentName, version); const commit = React.useMemo( () => ((pipelineRunLoaded && pipelineRun && getCommitsFromPLRs([pipelineRun], 1)) || [])[0], [pipelineRunLoaded, pipelineRun], ); if (pipelineRunError) { return getErrorState(pipelineRunError, pipelineRunLoaded, 'pipeline run', true); } if (!pipelineRunLoaded) { return ; } if (!pipelineRun) { return ; } const actualVersion = version ?? pipelineRun?.metadata?.labels?.[PipelineRunLabel.COMPONENT_VERSION]; return ( {commit && ( {/* TODO: replace with a link to the commit details page, once the new version is implemented */} {`${commit.isPullRequest ? `#${commit.pullRequestNumber} ` : ''}${commit.shaTitle}`} {commit.shaURL && ( )} )} {actualVersion && ( Built from {actualVersion} )} ); }; export default LatestPushBuildSection;