Skip to content
Snippets Groups Projects
Select Git revision
  • 91da82aaa8d1ed8e93f3f5215b353343e4132c91
  • main default protected
  • dependabot/docker/golang-1.24.5
  • lihiz_preflight
  • release/prepare-v0.10.7
  • dependabot/github_actions/golangci/golangci-lint-action-7
  • release/prepare-v0.9.1
  • gh-pages
  • aquadev
  • v0.11.1
  • v0.11.0
  • v0.10.7
  • v0.10.6
  • v0.10.5
  • v0.10.4
  • v0.10.3
  • v0.10.2
  • v0.10.1
  • v0.10.0
  • v0.9.4
  • v0.9.3
  • v0.9.2
  • v0.9.1
  • v0.9.0
  • v0.8.0
  • v0.7.3
  • v0.7.2
  • v0.7.1
  • v0.7.0
29 results

test_test.go

Blame
  • util.ts 931 B
    import {
      GITHUB_API_USING_HOST_TYPES,
      GITLAB_API_USING_HOST_TYPES,
    } from '../../constants';
    import * as hostRules from '../../util/host-rules';
    import { parseUrl } from '../../util/url';
    
    /**
     * Tries to detect the `platform from a url.
     *
     * @param url the url to detect platform from
     * @returns matched `platform` if found, otherwise `null`
     */
    export function detectPlatform(url: string): 'gitlab' | 'github' | null {
      const { hostname } = parseUrl(url) ?? {};
      if (hostname === 'github.com' || hostname?.includes('github')) {
        return 'github';
      }
      if (hostname === 'gitlab.com' || hostname?.includes('gitlab')) {
        return 'gitlab';
      }
    
      const hostType = hostRules.hostType({ url: url });
    
      if (!hostType) {
        return null;
      }
    
      if (GITLAB_API_USING_HOST_TYPES.includes(hostType)) {
        return 'gitlab';
      }
      if (GITHUB_API_USING_HOST_TYPES.includes(hostType)) {
        return 'github';
      }
    
      return null;
    }