Skip to content
Snippets Groups Projects
Select Git revision
  • 4d904e821668dc360e5b93c5334609f158fcdc6d
  • main default protected
  • release/v2.6.x
  • dependabot/github_actions/ci-641206964f
  • conform-k8s-1.33
  • rfc-external-artifact
  • release/v2.5.x
  • release/v2.4.x
  • remove-notation-validation
  • release/v2.3.x
  • release/v2.2.x
  • RFC
  • fix-commit-log
  • flux-audit
  • release/v2.1.x
  • context-ns
  • ksm-dashboard
  • rfc-passwordless-git-auth
  • release/v2.0.x
  • rfc-gating
  • release/v0.27.4
  • v2.6.4 protected
  • v2.6.3 protected
  • v2.6.2 protected
  • v2.6.1 protected
  • v2.6.0 protected
  • v2.5.1 protected
  • v2.5.0 protected
  • v2.4.0 protected
  • v2.3.0 protected
  • v2.2.3 protected
  • v2.2.2 protected
  • v2.2.1 protected
  • v2.2.0 protected
  • v2.1.2 protected
  • v2.1.1 protected
  • v2.1.0 protected
  • v2.0.1 protected
  • v2.0.0 protected
  • v2.0.0-rc.5 protected
  • v2.0.0-rc.4 protected
41 results

gogit_test.go

Blame
  • index.ts 2.86 KiB
    import URL from 'url';
    import type { AllConfig } from '../../config/types';
    import type { PlatformId } from '../../constants';
    import { PLATFORM_NOT_FOUND } from '../../constants/error-messages';
    import { logger } from '../../logger';
    import type { HostRule } from '../../types';
    import { setGitAuthor, setNoVerify, setPrivateKey } from '../../util/git';
    import * as hostRules from '../../util/host-rules';
    import platforms from './api';
    import { setPlatformScmApi } from './scm';
    import type { Platform } from './types';
    
    export * from './types';
    
    export const getPlatformList = (): string[] => Array.from(platforms.keys());
    export const getPlatforms = (): Map<string, Platform> => platforms;
    
    let _platform: Platform | undefined;
    
    const handler: ProxyHandler<Platform> = {
      get(_target: Platform, prop: keyof Platform) {
        if (!_platform) {
          throw new Error(PLATFORM_NOT_FOUND);
        }
        return _platform[prop];
      },
    };
    
    export const platform = new Proxy<Platform>({} as any, handler);
    
    export function setPlatformApi(name: PlatformId): void {
      if (!platforms.has(name)) {
        throw new Error(
          `Init: Platform "${name}" not found. Must be one of: ${getPlatformList().join(
            ', '
          )}`
        );
      }
      _platform = platforms.get(name);
      setPlatformScmApi(name);
    }
    
    export async function initPlatform(config: AllConfig): Promise<AllConfig> {
      setPrivateKey(config.gitPrivateKey);
      setNoVerify(config.gitNoVerify ?? []);
      // TODO: `platform` (#7154)
      setPlatformApi(config.platform!);
      // TODO: types
      const platformInfo = await platform.initPlatform(config);
      const returnConfig: any = { ...config, ...platformInfo };
      // istanbul ignore else
      if (config?.gitAuthor) {
        logger.debug(`Using configured gitAuthor (${config.gitAuthor})`);
        returnConfig.gitAuthor = config.gitAuthor;
      } else if (platformInfo?.gitAuthor) {
        logger.debug(`Using platform gitAuthor: ${String(platformInfo.gitAuthor)}`);
        returnConfig.gitAuthor = platformInfo.gitAuthor;
      }
      // This is done for validation and will be overridden later once repo config is incorporated
      setGitAuthor(returnConfig.gitAuthor);
      const platformRule: HostRule = {
        // TODO: null check (#7154)
        matchHost: URL.parse(returnConfig.endpoint).hostname!,
      };
      // There might have been platform-specific modifications to the token
      if (returnConfig.token) {
        config.token = returnConfig.token;
      }
      (
        ['token', 'username', 'password'] as ('token' | 'username' | 'password')[]