Remove deriveApiUrl function only used by runner
This commit is contained in:
parent
8ecbaea022
commit
dac8912e9f
6 changed files with 6 additions and 146 deletions
|
|
@ -2,7 +2,7 @@ import * as githubUtils from "@actions/github/lib/utils";
|
|||
import test, { ExecutionContext } from "ava";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
import { getApiClient } from "./api-client";
|
||||
import { getApiClient, GitHubApiCombinedDetails } from "./api-client";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import { initializeEnvironment } from "./util";
|
||||
|
||||
|
|
@ -21,72 +21,6 @@ test.beforeEach(() => {
|
|||
initializeEnvironment(pkg.version);
|
||||
});
|
||||
|
||||
test("Get the client API", async (t) => {
|
||||
doTest(
|
||||
t,
|
||||
{
|
||||
auth: "xyz",
|
||||
externalRepoAuth: "abc",
|
||||
url: "http://hucairz",
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
auth: "token xyz",
|
||||
baseUrl: "http://hucairz/api/v3",
|
||||
userAgent: `CodeQL-Action/${pkg.version}`,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("Get the client API external", async (t) => {
|
||||
doTest(
|
||||
t,
|
||||
{
|
||||
auth: "xyz",
|
||||
externalRepoAuth: "abc",
|
||||
url: "http://hucairz",
|
||||
},
|
||||
{ allowExternal: true },
|
||||
{
|
||||
auth: "token abc",
|
||||
baseUrl: "http://hucairz/api/v3",
|
||||
userAgent: `CodeQL-Action/${pkg.version}`,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("Get the client API external not present", async (t) => {
|
||||
doTest(
|
||||
t,
|
||||
{
|
||||
auth: "xyz",
|
||||
url: "http://hucairz",
|
||||
},
|
||||
{ allowExternal: true },
|
||||
{
|
||||
auth: "token xyz",
|
||||
baseUrl: "http://hucairz/api/v3",
|
||||
userAgent: `CodeQL-Action/${pkg.version}`,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("Get the client API with github url", async (t) => {
|
||||
doTest(
|
||||
t,
|
||||
{
|
||||
auth: "xyz",
|
||||
url: "https://github.com/some/invalid/url",
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
auth: "token xyz",
|
||||
baseUrl: "https://api.github.com",
|
||||
userAgent: `CodeQL-Action/${pkg.version}`,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("Get the API with an API URL directly", async (t) => {
|
||||
doTest(
|
||||
t,
|
||||
|
|
@ -106,7 +40,7 @@ test("Get the API with an API URL directly", async (t) => {
|
|||
|
||||
function doTest(
|
||||
t: ExecutionContext<unknown>,
|
||||
clientArgs: any,
|
||||
clientArgs: GitHubApiCombinedDetails,
|
||||
clientOptions: any,
|
||||
expected: any
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import * as path from "path";
|
||||
|
||||
import * as githubUtils from "@actions/github/lib/utils";
|
||||
import * as retry from "@octokit/plugin-retry";
|
||||
import consoleLogLevel from "console-log-level";
|
||||
|
|
@ -38,31 +36,15 @@ export const getApiClient = function (
|
|||
const auth =
|
||||
(allowExternal && apiDetails.externalRepoAuth) || apiDetails.auth;
|
||||
const retryingOctokit = githubUtils.GitHub.plugin(retry.retry);
|
||||
const apiURL = apiDetails.apiURL || deriveApiUrl(apiDetails.url);
|
||||
return new retryingOctokit(
|
||||
githubUtils.getOctokitOptions(auth, {
|
||||
baseUrl: apiURL,
|
||||
baseUrl: apiDetails.apiURL,
|
||||
userAgent: `CodeQL-Action/${pkg.version}`,
|
||||
log: consoleLogLevel({ level: "debug" }),
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
// Once the runner is deleted, this can also be removed since the GitHub API URL is always available in an environment variable on Actions.
|
||||
function deriveApiUrl(githubUrl: string): string {
|
||||
const url = new URL(githubUrl);
|
||||
|
||||
// If we detect this is trying to connect to github.com
|
||||
// then return with a fixed canonical URL.
|
||||
if (url.hostname === "github.com" || url.hostname === "api.github.com") {
|
||||
return "https://api.github.com";
|
||||
}
|
||||
|
||||
// Add the /api/v3 API prefix
|
||||
url.pathname = path.join(url.pathname, "api", "v3");
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
export function getApiDetails() {
|
||||
return {
|
||||
auth: getRequiredInput("token"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue