only insert external repos token if supplied

This commit is contained in:
Robert
2021-01-19 15:28:05 +00:00
parent b0adc415a0
commit cb574a7d60
13 changed files with 92 additions and 23 deletions
+18 -5
View File
@@ -29,13 +29,10 @@ export async function checkoutExternalRepository(
}
if (!fs.existsSync(checkoutLocation)) {
const repoCloneURL = new URL(apiDetails.url);
repoCloneURL.username = "x-access-token";
repoCloneURL.password = apiDetails.externalRepoAuth;
repoCloneURL.pathname += `/${repository}`;
const repoCloneURL = buildCheckoutURL(repository, apiDetails);
await new toolrunner.ToolRunner(await safeWhich.safeWhich("git"), [
"clone",
repoCloneURL.toString(),
repoCloneURL,
checkoutLocation,
]).exec();
await new toolrunner.ToolRunner(await safeWhich.safeWhich("git"), [
@@ -48,3 +45,19 @@ export async function checkoutExternalRepository(
return checkoutLocation;
}
export function buildCheckoutURL(
repository: string,
apiDetails: GitHubApiExternalRepoDetails
): string {
const repoCloneURL = new URL(apiDetails.url);
if (apiDetails.externalRepoAuth !== undefined) {
repoCloneURL.username = "x-access-token";
repoCloneURL.password = apiDetails.externalRepoAuth;
}
if (!repoCloneURL.pathname.endsWith("/")) {
repoCloneURL.pathname += "/";
}
repoCloneURL.pathname += `${repository}`;
return repoCloneURL.toString();
}