mirror of
https://github.com/github/codeql-action.git
synced 2026-01-03 13:10:06 +08:00
only insert external repos token if supplied
This commit is contained in:
@@ -20,7 +20,7 @@ export interface GitHubApiDetails {
|
||||
}
|
||||
|
||||
export interface GitHubApiExternalRepoDetails {
|
||||
externalRepoAuth: string;
|
||||
externalRepoAuth: string | undefined;
|
||||
url: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,3 +108,35 @@ test("checkoutExternalQueries", async (t) => {
|
||||
t.false(fs.existsSync(path.join(tmpDir, repoName, commit2Sha, "b")));
|
||||
});
|
||||
});
|
||||
|
||||
test("buildCheckoutURL", (t) => {
|
||||
t.deepEqual(
|
||||
externalQueries.buildCheckoutURL("foo/bar", {
|
||||
url: "https://github.com",
|
||||
externalRepoAuth: undefined,
|
||||
}),
|
||||
"https://github.com/foo/bar"
|
||||
);
|
||||
t.deepEqual(
|
||||
externalQueries.buildCheckoutURL("foo/bar", {
|
||||
url: "https://github.example.com/",
|
||||
externalRepoAuth: undefined,
|
||||
}),
|
||||
"https://github.example.com/foo/bar"
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
externalQueries.buildCheckoutURL("foo/bar", {
|
||||
url: "https://github.com",
|
||||
externalRepoAuth: "abc",
|
||||
}),
|
||||
"https://x-access-token:abc@github.com/foo/bar"
|
||||
);
|
||||
t.deepEqual(
|
||||
externalQueries.buildCheckoutURL("foo/bar", {
|
||||
url: "https://github.example.com/",
|
||||
externalRepoAuth: "abc",
|
||||
}),
|
||||
"https://x-access-token:abc@github.example.com/foo/bar"
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -96,9 +96,7 @@ async function run() {
|
||||
|
||||
const apiDetails = {
|
||||
auth: actionsUtil.getRequiredInput("token"),
|
||||
externalRepoAuth:
|
||||
actionsUtil.getOptionalInput("external-repository-token") ??
|
||||
actionsUtil.getRequiredInput("token"),
|
||||
externalRepoAuth: actionsUtil.getOptionalInput("external-repository-token"),
|
||||
url: actionsUtil.getRequiredEnvParam("GITHUB_SERVER_URL"),
|
||||
};
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ program
|
||||
|
||||
const apiDetails = {
|
||||
auth: cmd.githubAuth,
|
||||
externalRepoAuth: cmd.externalRepositoryToken ?? cmd.githubAuth,
|
||||
externalRepoAuth: cmd.externalRepositoryToken,
|
||||
url: parseGithubUrl(cmd.githubUrl),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user