Skip to content

Commit dac8912

Browse files
committed
Remove deriveApiUrl function only used by runner
1 parent 8ecbaea commit dac8912

File tree

6 files changed

+6
-146
lines changed

6 files changed

+6
-146
lines changed

lib/api-client.js

Lines changed: 1 addition & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api-client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api-client.test.js

Lines changed: 0 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api-client.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api-client.test.ts

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as githubUtils from "@actions/github/lib/utils";
22
import test, { ExecutionContext } from "ava";
33
import * as sinon from "sinon";
44

5-
import { getApiClient } from "./api-client";
5+
import { getApiClient, GitHubApiCombinedDetails } from "./api-client";
66
import { setupTests } from "./testing-utils";
77
import { initializeEnvironment } from "./util";
88

@@ -21,72 +21,6 @@ test.beforeEach(() => {
2121
initializeEnvironment(pkg.version);
2222
});
2323

24-
test("Get the client API", async (t) => {
25-
doTest(
26-
t,
27-
{
28-
auth: "xyz",
29-
externalRepoAuth: "abc",
30-
url: "http://hucairz",
31-
},
32-
undefined,
33-
{
34-
auth: "token xyz",
35-
baseUrl: "http://hucairz/api/v3",
36-
userAgent: `CodeQL-Action/${pkg.version}`,
37-
}
38-
);
39-
});
40-
41-
test("Get the client API external", async (t) => {
42-
doTest(
43-
t,
44-
{
45-
auth: "xyz",
46-
externalRepoAuth: "abc",
47-
url: "http://hucairz",
48-
},
49-
{ allowExternal: true },
50-
{
51-
auth: "token abc",
52-
baseUrl: "http://hucairz/api/v3",
53-
userAgent: `CodeQL-Action/${pkg.version}`,
54-
}
55-
);
56-
});
57-
58-
test("Get the client API external not present", async (t) => {
59-
doTest(
60-
t,
61-
{
62-
auth: "xyz",
63-
url: "http://hucairz",
64-
},
65-
{ allowExternal: true },
66-
{
67-
auth: "token xyz",
68-
baseUrl: "http://hucairz/api/v3",
69-
userAgent: `CodeQL-Action/${pkg.version}`,
70-
}
71-
);
72-
});
73-
74-
test("Get the client API with github url", async (t) => {
75-
doTest(
76-
t,
77-
{
78-
auth: "xyz",
79-
url: "https://github.com/some/invalid/url",
80-
},
81-
undefined,
82-
{
83-
auth: "token xyz",
84-
baseUrl: "https://api.github.com",
85-
userAgent: `CodeQL-Action/${pkg.version}`,
86-
}
87-
);
88-
});
89-
9024
test("Get the API with an API URL directly", async (t) => {
9125
doTest(
9226
t,
@@ -106,7 +40,7 @@ test("Get the API with an API URL directly", async (t) => {
10640

10741
function doTest(
10842
t: ExecutionContext<unknown>,
109-
clientArgs: any,
43+
clientArgs: GitHubApiCombinedDetails,
11044
clientOptions: any,
11145
expected: any
11246
) {

src/api-client.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as path from "path";
2-
31
import * as githubUtils from "@actions/github/lib/utils";
42
import * as retry from "@octokit/plugin-retry";
53
import consoleLogLevel from "console-log-level";
@@ -38,31 +36,15 @@ export const getApiClient = function (
3836
const auth =
3937
(allowExternal && apiDetails.externalRepoAuth) || apiDetails.auth;
4038
const retryingOctokit = githubUtils.GitHub.plugin(retry.retry);
41-
const apiURL = apiDetails.apiURL || deriveApiUrl(apiDetails.url);
4239
return new retryingOctokit(
4340
githubUtils.getOctokitOptions(auth, {
44-
baseUrl: apiURL,
41+
baseUrl: apiDetails.apiURL,
4542
userAgent: `CodeQL-Action/${pkg.version}`,
4643
log: consoleLogLevel({ level: "debug" }),
4744
})
4845
);
4946
};
5047

51-
// Once the runner is deleted, this can also be removed since the GitHub API URL is always available in an environment variable on Actions.
52-
function deriveApiUrl(githubUrl: string): string {
53-
const url = new URL(githubUrl);
54-
55-
// If we detect this is trying to connect to github.com
56-
// then return with a fixed canonical URL.
57-
if (url.hostname === "github.com" || url.hostname === "api.github.com") {
58-
return "https://api.github.com";
59-
}
60-
61-
// Add the /api/v3 API prefix
62-
url.pathname = path.join(url.pathname, "api", "v3");
63-
return url.toString();
64-
}
65-
6648
export function getApiDetails() {
6749
return {
6850
auth: getRequiredInput("token"),

0 commit comments

Comments
 (0)