Skip to content

Commit 8d9efb0

Browse files
committed
Make auth property on GitHubApiDetails optional
1 parent 79611c1 commit 8d9efb0

4 files changed

Lines changed: 41 additions & 38 deletions

File tree

‎lib/entry-points.js‎

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

‎src/api-client.ts‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from "@actions/core";
22
import * as githubUtils from "@actions/github/lib/utils";
3+
import type { OctokitOptions } from "@octokit/core";
34
import * as retry from "@octokit/plugin-retry";
45
import { RequestRequestOptions } from "@octokit/types";
56
import {
@@ -133,22 +134,24 @@ function createApiClientWithDetails(
133134
(allowExternal && apiDetails.externalRepoAuth) || apiDetails.auth;
134135
const retryingOctokit = githubUtils.GitHub.plugin(retry.retry);
135136
const requestOptions = makeProxyRequestOptions(proxy);
136-
return new retryingOctokit(
137-
githubUtils.getOctokitOptions(auth, {
138-
baseUrl: apiDetails.apiURL,
139-
userAgent: `CodeQL-Action/${getActionVersion()}`,
140-
log: {
141-
debug: core.debug,
142-
info: core.info,
143-
warn: core.warning,
144-
error: core.error,
145-
},
146-
request: requestOptions,
147-
retry: {
148-
doNotRetry: DO_NOT_RETRY_STATUSES,
149-
},
150-
}),
151-
);
137+
138+
const opts: OctokitOptions = {
139+
auth: auth !== undefined ? `token ${auth}` : undefined,
140+
baseUrl: apiDetails.apiURL,
141+
userAgent: `CodeQL-Action/${getActionVersion()}`,
142+
log: {
143+
debug: core.debug,
144+
info: core.info,
145+
warn: core.warning,
146+
error: core.error,
147+
},
148+
request: requestOptions,
149+
retry: {
150+
doNotRetry: DO_NOT_RETRY_STATUSES,
151+
},
152+
};
153+
154+
return new retryingOctokit(opts);
152155
}
153156

154157
/**

‎src/codeql.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function mockReleaseApi({
126126
});
127127
}
128128

129-
function mockApiDetails(apiDetails: GitHubApiDetails) {
129+
function mockApiDetails(apiDetails: Required<GitHubApiDetails>) {
130130
// This is a workaround to mock `api.getApiDetails()` since it doesn't seem to be possible to
131131
// mock this directly. The difficulty is that `getApiDetails()` is called locally in
132132
// `api-client.ts`, but `sinon.stub(api, "getApiDetails")` only affects calls to

‎src/github.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export type GitHubInstance = {
3838
/** Represents a {@link GitHubInstance} with a token for accessing the API. */
3939
export type GitHubApiDetails = GitHubInstance & {
4040
/** The token to use for accessing the API of the GitHub instance. */
41-
auth: string;
41+
auth?: string;
4242
};
4343

4444
/**

0 commit comments

Comments
 (0)