fix: add trailing .git
to repositoryUrl
only if it's present in the configured URL
This commit is contained in:
parent
7c9ec41dd7
commit
cb1f80cb56
@ -40,13 +40,11 @@ module.exports = async ({repositoryUrl, branch}) => {
|
|||||||
const gitCredentials = ['GL_TOKEN', 'GITLAB_TOKEN'].includes(envVar)
|
const gitCredentials = ['GL_TOKEN', 'GITLAB_TOKEN'].includes(envVar)
|
||||||
? `gitlab-ci-token:${process.env[envVar]}`
|
? `gitlab-ci-token:${process.env[envVar]}`
|
||||||
: 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';
|
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
|
// If credentials are set via anvironment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
|
||||||
return gitCredentials
|
return gitCredentials ? {...parsed, ...{token: gitCredentials}}.toString(protocol) : repositoryUrl;
|
||||||
? format({...parse(`${gitUrlParse(repositoryUrl).toString(protocol)}.git`), ...{auth: gitCredentials}})
|
|
||||||
: repositoryUrl;
|
|
||||||
}
|
}
|
||||||
return repositoryUrl;
|
return repositoryUrl;
|
||||||
};
|
};
|
||||||
|
@ -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 => {
|
test.serial('Handle "https" URL with group and subgroup', async t => {
|
||||||
t.is(
|
t.is(
|
||||||
await getAuthUrl({repositoryUrl: 'https://host.null/group/subgroup/owner/repo.git'}),
|
await getAuthUrl({repositoryUrl: 'https://host.null/group/subgroup/owner/repo.git'}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user