import { PlatformId } from '../../constants' ; import { logger } from '../../logger' ; import type { HostRule } from '../../types' ; import { getHttpUrl } from './url' ; returns export function getGitAuthenticatedEnvironmentVariables ( gitUrl , { token , hostType , matchHost } , environmentVariables ? ) { if ( ! token ) { logger . warn ( `Could not create environment variable for ${ matchHost } as token was empty` ) ; return { ... environmentVariables } ; } const gitConfigCountEnvVariable = environmentVariables ?. GIT_CONFIG_COUNT || process . env . GIT_CONFIG_COUNT ; let gitConfigCount = 0 ; if ( gitConfigCountEnvVariable ) { gitConfigCount = parseInt ( gitConfigCountEnvVariable , 10 ) ; if ( Number . isNaN ( gitConfigCount ) ) { logger . warn ( `Found GIT_CONFIG_COUNT env variable, but couldn't parse the value to an integer: ${ process . env . GIT_CONFIG_COUNT }. Ignoring it.` ) ; gitConfigCount = 0 ; } } const gitUrlWithToken = getUrlWithToken ( gitUrl , hostType , token ) ; return { ... environmentVariables , [ `GIT_CONFIG_KEY_${ gitConfigCount }` ] : `url.${ gitUrlWithToken }.insteadOf` , [ `GIT_CONFIG_VALUE_${ gitConfigCount }` ] : gitUrl , GIT_CONFIG_COUNT : ( gitConfigCount + 1 ) . toString ( ) , } ; } function getUrlWithToken ( gitUrl , hostType , authToken ) { let token = authToken ; if ( hostType === PlatformId . Gitlab ) { token = `gitlab-ci-token:${ token }` ; } return getHttpUrl ( gitUrl , token ) ; }