From afaf32464607c0552afd8d45aacd5b8a06c400bb Mon Sep 17 00:00:00 2001 From: Mario Campos Date: Thu, 29 Oct 2026 09:49:40 -0500 Subject: [PATCH] Move `resolveToken` to `pr-checks/api-client.ts` --- pr-checks/api-client.ts | 11 +++++++++++ pr-checks/post-comment.test.ts | 3 +-- pr-checks/post-comment.ts | 13 +------------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pr-checks/api-client.ts b/pr-checks/api-client.ts index b8f914d81..8f990362b 100644 --- a/pr-checks/api-client.ts +++ b/pr-checks/api-client.ts @@ -8,3 +8,14 @@ export function getApiClient(token: string): ApiClient { const opts = githubUtils.getOctokitOptions(token); return new githubUtils.GitHub(opts); } + +/** Resolves the GitHub API token to use, from `GH_TOKEN` or `GITHUB_TOKEN`. */ +export function resolveToken(env: NodeJS.ProcessEnv): string { + const token = env.GH_TOKEN?.trim() || env.GITHUB_TOKEN?.trim(); + if (!token) { + throw new Error( + "Missing authentication token. Set GH_TOKEN or GITHUB_TOKEN.", + ); + } + return token; +} diff --git a/pr-checks/post-comment.test.ts b/pr-checks/post-comment.test.ts index 7babddcff..8c1ad5d83 100644 --- a/pr-checks/post-comment.test.ts +++ b/pr-checks/post-comment.test.ts @@ -7,12 +7,11 @@ Tests for post-comment.ts. import * as assert from "node:assert/strict"; import { describe, it } from "node:test"; -import { type ApiClient } from "./api-client"; +import { type ApiClient, resolveToken } from "./api-client"; import { findExistingComment, type Options, parseOptions, - resolveToken, setComment, } from "./post-comment"; diff --git a/pr-checks/post-comment.ts b/pr-checks/post-comment.ts index 3f8abe40b..81c42f25a 100644 --- a/pr-checks/post-comment.ts +++ b/pr-checks/post-comment.ts @@ -17,7 +17,7 @@ The `.github/actions/post-comment` action requires callers to supply this value import assert from "node:assert/strict"; import { parseArgs } from "node:util"; -import { type ApiClient, getApiClient } from "./api-client"; +import { type ApiClient, getApiClient, resolveToken } from "./api-client"; /** Represents the command-line options. */ export interface Options { @@ -55,17 +55,6 @@ export function parseOptions(argv?: string[]): Options { }; } -/** Resolves the GitHub API token to use, from `GH_TOKEN` or `GITHUB_TOKEN`. */ -export function resolveToken(env: NodeJS.ProcessEnv): string { - const token = env.GH_TOKEN?.trim() || env.GITHUB_TOKEN?.trim(); - if (!token) { - throw new Error( - "Missing authentication token. Set GH_TOKEN or GITHUB_TOKEN.", - ); - } - return token; -} - /** * Finds the first comment on the given issue/pull request whose body starts with `marker`, if any. */