diff --git a/lib/get-git-auth-url.js b/lib/get-git-auth-url.js index f753b323..f06ba477 100644 --- a/lib/get-git-auth-url.js +++ b/lib/get-git-auth-url.js @@ -40,13 +40,11 @@ module.exports = async ({repositoryUrl, branch}) => { const gitCredentials = ['GL_TOKEN', 'GITLAB_TOKEN'].includes(envVar) ? `gitlab-ci-token:${process.env[envVar]}` : process.env[envVar]; - const {protocols} = gitUrlParse(repositoryUrl); + const {protocols, ...parsed} = gitUrlParse(repositoryUrl); const protocol = protocols.includes('https') ? 'https' : protocols.includes('http') ? 'http' : 'https'; // If credentials are set via anvironment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is - return gitCredentials - ? format({...parse(`${gitUrlParse(repositoryUrl).toString(protocol)}.git`), ...{auth: gitCredentials}}) - : repositoryUrl; + return gitCredentials ? {...parsed, ...{token: gitCredentials}}.toString(protocol) : repositoryUrl; } return repositoryUrl; }; diff --git a/test/get-git-auth-url.test.js b/test/get-git-auth-url.test.js index 5c961e3e..420457e7 100644 --- a/test/get-git-auth-url.test.js +++ b/test/get-git-auth-url.test.js @@ -37,6 +37,10 @@ test.serial( } ); +test.serial('Do not add trailing ".git" if not present in the origian URL', async t => { + t.is(await getAuthUrl({repositoryUrl: 'git@host.null:owner/repo'}), 'git@host.null:owner/repo'); +}); + test.serial('Handle "https" URL with group and subgroup', async t => { t.is( await getAuthUrl({repositoryUrl: 'https://host.null/group/subgroup/owner/repo.git'}),