github.com/argoproj/argo-cd@v1.8.7/ui/src/app/shared/components/urls.ts (about)

     1  import {GitUrl} from 'git-url-parse';
     2  import {isSHA} from './revision';
     3  
     4  const GitUrlParse = require('git-url-parse');
     5  
     6  function supportedSource(parsed: GitUrl): boolean {
     7      return parsed.resource.startsWith('github') || ['gitlab.com', 'bitbucket.org'].indexOf(parsed.source) >= 0;
     8  }
     9  
    10  function protocol(proto: string): string {
    11      return proto === 'ssh' ? 'https' : proto;
    12  }
    13  
    14  export function repoUrl(url: string): string {
    15      const parsed = GitUrlParse(url);
    16  
    17      if (!supportedSource(parsed)) {
    18          return null;
    19      }
    20  
    21      return `${protocol(parsed.protocol)}://${parsed.resource}/${parsed.owner}/${parsed.name}`;
    22  }
    23  
    24  export function revisionUrl(url: string, revision: string): string {
    25      const parsed = GitUrlParse(url);
    26      let urlSubPath = isSHA(revision) ? 'commit' : 'tree';
    27  
    28      if (url.indexOf('bitbucket') >= 0) {
    29          urlSubPath = isSHA(revision) ? 'commits' : 'branch';
    30      }
    31  
    32      if (!supportedSource(parsed)) {
    33          return null;
    34      }
    35  
    36      return `${protocol(parsed.protocol)}://${parsed.resource}/${parsed.owner}/${parsed.name}/${urlSubPath}/${revision || 'HEAD'}`;
    37  }