fix: ignore custom port when converting ssh repo URL to https
This commit is contained in:
		
							parent
							
								
									dc19dfa2e9
								
							
						
					
					
						commit
						4af8548366
					
				| @ -48,9 +48,14 @@ module.exports = async ({cwd, env, options: {repositoryUrl, branch}}) => { | ||||
|     if (gitCredentials) { | ||||
|       // If credentials are set via environment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
 | ||||
|       const [match, auth, host, path] = /^(?!.+:\/\/)(?:(.*)@)?(.*?):(.*)$/.exec(repositoryUrl) || []; | ||||
|       const {port, hostname, ...parsed} = parse( | ||||
|         match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl | ||||
|       ); | ||||
| 
 | ||||
|       return format({ | ||||
|         ...parse(match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl), | ||||
|         ...parsed, | ||||
|         auth: gitCredentials, | ||||
|         host: `${hostname}${protocol === 'ssh:' ? '' : port ? `:${port}` : ''}`, | ||||
|         protocol: protocol && /http[^s]/.test(protocol) ? 'http' : 'https', | ||||
|       }); | ||||
|     } | ||||
|  | ||||
| @ -140,6 +140,19 @@ test('Return the "http" formatted URL if "gitCredentials" is defined and reposit | ||||
|   ); | ||||
| }); | ||||
| 
 | ||||
| test('Return the "http" formatted URL if "gitCredentials" is defined and repositoryUrl is a "http" URL with custom port', async t => { | ||||
|   const {cwd} = await gitRepo(); | ||||
| 
 | ||||
|   t.is( | ||||
|     await getAuthUrl({ | ||||
|       cwd, | ||||
|       env: {...env, GIT_CREDENTIALS: 'user:pass'}, | ||||
|       options: {branch: 'master', repositoryUrl: 'http://host.null:8080/owner/repo.git'}, | ||||
|     }), | ||||
|     'http://user:pass@host.null:8080/owner/repo.git' | ||||
|   ); | ||||
| }); | ||||
| 
 | ||||
| test('Return the "https" formatted URL if "gitCredentials" is defined and repositoryUrl is a "git+https" URL', async t => { | ||||
|   const {cwd} = await gitRepo(); | ||||
| 
 | ||||
| @ -166,6 +179,19 @@ test('Return the "http" formatted URL if "gitCredentials" is defined and reposit | ||||
|   ); | ||||
| }); | ||||
| 
 | ||||
| test('Return the "http" formatted URL if "gitCredentials" is defined and 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:2222/owner/repo.git'}, | ||||
|     }), | ||||
|     'https://user:pass@host.null/owner/repo.git' | ||||
|   ); | ||||
| }); | ||||
| 
 | ||||
| test('Return the "https" formatted URL if "gitCredentials" is defined with "GH_TOKEN"', async t => { | ||||
|   const {cwd} = await gitRepo(); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user