github.com/argoproj/argo-cd/v2@v2.10.9/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.substr(0, 7) : revision);
    16      return url !== null ? (
    17          <a href={url} target='_blank' rel='noopener noreferrer'>
    18              {content}
    19          </a>
    20      ) : (
    21          <span>{content}</span>
    22      );
    23  };
    24  
    25  export const isSHA = (revision: string) => {
    26      // https://stackoverflow.com/questions/468370/a-regex-to-match-a-sha1
    27      return revision.match(/^[a-f0-9]{5,40}$/) !== null;
    28  };