Skip to content

Commit afaf324

Browse files
committed
Move resolveToken to pr-checks/api-client.ts
1 parent c069d49 commit afaf324

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

‎pr-checks/api-client.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ export function getApiClient(token: string): ApiClient {
88
const opts = githubUtils.getOctokitOptions(token);
99
return new githubUtils.GitHub(opts);
1010
}
11+
12+
/** Resolves the GitHub API token to use, from `GH_TOKEN` or `GITHUB_TOKEN`. */
13+
export function resolveToken(env: NodeJS.ProcessEnv): string {
14+
const token = env.GH_TOKEN?.trim() || env.GITHUB_TOKEN?.trim();
15+
if (!token) {
16+
throw new Error(
17+
"Missing authentication token. Set GH_TOKEN or GITHUB_TOKEN.",
18+
);
19+
}
20+
return token;
21+
}

‎pr-checks/post-comment.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ Tests for post-comment.ts.
77
import * as assert from "node:assert/strict";
88
import { describe, it } from "node:test";
99

10-
import { type ApiClient } from "./api-client";
10+
import { type ApiClient, resolveToken } from "./api-client";
1111
import {
1212
findExistingComment,
1313
type Options,
1414
parseOptions,
15-
resolveToken,
1615
setComment,
1716
} from "./post-comment";
1817

‎pr-checks/post-comment.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The `.github/actions/post-comment` action requires callers to supply this value
1717
import assert from "node:assert/strict";
1818
import { parseArgs } from "node:util";
1919

20-
import { type ApiClient, getApiClient } from "./api-client";
20+
import { type ApiClient, getApiClient, resolveToken } from "./api-client";
2121

2222
/** Represents the command-line options. */
2323
export interface Options {
@@ -55,17 +55,6 @@ export function parseOptions(argv?: string[]): Options {
5555
};
5656
}
5757

58-
/** Resolves the GitHub API token to use, from `GH_TOKEN` or `GITHUB_TOKEN`. */
59-
export function resolveToken(env: NodeJS.ProcessEnv): string {
60-
const token = env.GH_TOKEN?.trim() || env.GITHUB_TOKEN?.trim();
61-
if (!token) {
62-
throw new Error(
63-
"Missing authentication token. Set GH_TOKEN or GITHUB_TOKEN.",
64-
);
65-
}
66-
return token;
67-
}
68-
6958
/**
7059
* Finds the first comment on the given issue/pull request whose body starts with `marker`, if any.
7160
*/

0 commit comments

Comments
 (0)