github.com/argoproj/argo-cd/v3@v3.2.1/ui/src/app/shared/components/revision.tsx (about) 1 import * as React from 'react'; 2 import {revisionUrl} from './urls'; 3 4 export const Revision = ({repoUrl, revision, path, isForPath, children}: {repoUrl: string; revision: string; path?: string; isForPath?: boolean; children?: React.ReactNode}) => { 5 if (isForPath && !path) { 6 // This source literally has no path, so we won't show one. 7 return <span />; 8 } 9 revision = revision || ''; 10 const hasPath = path && path !== '.'; 11 let url = revisionUrl(repoUrl, revision, hasPath); 12 if (url !== null && hasPath) { 13 url += '/' + path; 14 } 15 const content = children || (isSHA(revision) ? (revision.startsWith('sha256:') ? revision.substr(0, 14) : revision.substr(0, 7)) : revision); 16 return url !== null ? ( 17 <a href={url} target='_blank' rel='noopener noreferrer'> 18 {content} <i className='fa fa-external-link-alt' /> 19 </a> 20 ) : ( 21 <span>{content}</span> 22 ); 23 }; 24 25 export const isSHA = (revision: string) => { 26 if (revision.startsWith('sha256:')) { 27 const hashOnly = revision.replace('sha256:', ''); 28 return hashOnly.match(/^[a-f0-9]{8,69}$/) !== null; 29 } 30 // https://stackoverflow.com/questions/468370/a-regex-to-match-a-sha1 31 return revision.match(/^[a-f0-9]{5,40}$/) !== null; 32 };