Skip to content

Commit 5c874f3

Browse files
committed
make token optional
1 parent 1d5e89e commit 5c874f3

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

config.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ export class ConfigProvider {
33

44
get githubToken() {
55
return this.#githubToken ??
6-
(this.#githubToken = getEnvOrThrow("GITHUB_TOKEN"));
6+
(this.#githubToken = Deno.env.get("GITHUB_TOKEN"));
77
}
88
}
9-
10-
function getEnvOrThrow(name: string) {
11-
const value = Deno.env.get(name);
12-
if (!value) {
13-
throw new Error(`Requires definition of env var: ${name}`);
14-
}
15-
return value;
16-
}

lib/github-api-client.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,22 @@ export type GitHubApiClient = ExtractInterface<RealGitHubApiClient>;
4444

4545
export class RealGitHubApiClient {
4646
readonly #fileFetcher: FileFetcher;
47-
readonly #token: string;
47+
readonly #token: string | undefined;
4848

49-
constructor(fileFetcher: FileFetcher, token: string) {
49+
constructor(fileFetcher: FileFetcher, token: string | undefined) {
5050
this.#fileFetcher = fileFetcher;
5151
this.#token = token;
5252
}
5353

5454
#getHeaders(): HeadersInit {
55-
return {
55+
const obj: Record<string, string> = {
5656
"Accept": "application/vnd.github+json",
5757
"X-GitHub-Api-Version": "2022-11-28",
58-
"Authorization": `Bearer ${this.#token}`,
5958
};
59+
if (this.#token) {
60+
obj["Authorization"] = `Bearer ${this.#token}`;
61+
}
62+
return obj;
6063
}
6164

6265
async listWorkflowRuns(

0 commit comments

Comments
 (0)