fix: do not convert ssh repositoryUrl to https
				
					
				
			This commit is contained in:
		
							parent
							
								
									8b8e40c91e
								
							
						
					
					
						commit
						b89523105c
					
				| @ -47,10 +47,18 @@ module.exports = async ({cwd, env, options: {repositoryUrl, branch}}) => { | |||||||
|     const envVar = Object.keys(GIT_TOKENS).find(envVar => !isUndefined(env[envVar])); |     const envVar = Object.keys(GIT_TOKENS).find(envVar => !isUndefined(env[envVar])); | ||||||
|     const gitCredentials = `${GIT_TOKENS[envVar] || ''}${env[envVar] || ''}`; |     const gitCredentials = `${GIT_TOKENS[envVar] || ''}${env[envVar] || ''}`; | ||||||
|     const {protocols, ...parsed} = gitUrlParse(repositoryUrl); |     const {protocols, ...parsed} = gitUrlParse(repositoryUrl); | ||||||
|     const protocol = protocols.includes('https') ? 'https' : protocols.includes('http') ? 'http' : 'https'; |     const protocol = protocols.includes('https') | ||||||
|  |       ? 'https' | ||||||
|  |       : protocols.includes('http') | ||||||
|  |         ? 'http' | ||||||
|  |         : protocols.includes('ssh') | ||||||
|  |           ? 'ssh' | ||||||
|  |           : 'https'; | ||||||
| 
 | 
 | ||||||
|     // If credentials are set via anvironment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
 |     // If credentials are set via anvironment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
 | ||||||
|     return gitCredentials ? {...parsed, protocols: [protocol], user: gitCredentials}.toString(protocol) : repositoryUrl; |     return gitCredentials && ['https', 'http'].includes(protocol) | ||||||
|  |       ? {...parsed, protocols: [protocol], user: gitCredentials}.toString(protocol) | ||||||
|  |       : repositoryUrl; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return repositoryUrl; |   return repositoryUrl; | ||||||
|  | |||||||
| @ -265,3 +265,16 @@ test('Do not add git credential to repositoryUrl if push is allowed', async t => | |||||||
|     repositoryUrl |     repositoryUrl | ||||||
|   ); |   ); | ||||||
| }); | }); | ||||||
|  | 
 | ||||||
|  | test('Do not add git credentials if repositoryUrl is a "ssh" URL', async t => { | ||||||
|  |   const {cwd} = await gitRepo(); | ||||||
|  | 
 | ||||||
|  |   t.is( | ||||||
|  |     await getAuthUrl({ | ||||||
|  |       cwd, | ||||||
|  |       env: {...env, GIT_CREDENTIALS: 'user:pass'}, | ||||||
|  |       options: {branch: 'master', repositoryUrl: 'ssh://git@host.null/owner/repo.git'}, | ||||||
|  |     }), | ||||||
|  |     'ssh://git@host.null/owner/repo.git' | ||||||
|  |   ); | ||||||
|  | }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user