fix: ignore custom port when converting ssh repo URL to https

This commit is contained in:
Pierre Vanduynslager
2019-10-18 16:25:40 -04:00
parent dc19dfa2e9
commit 4af8548366
2 changed files with 32 additions and 1 deletions
+6 -1
View File
@@ -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',
});
}