From dbfd510456401890ff6e6340834d180ef93800fc Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Fri, 10 Apr 2026 17:09:18 +0100 Subject: [PATCH] Make `token` parameter reusable --- pr-checks/api-client.ts | 15 +++++++++++++++ pr-checks/sync-checks.ts | 16 ++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pr-checks/api-client.ts b/pr-checks/api-client.ts index 93675dba7..2622515d0 100644 --- a/pr-checks/api-client.ts +++ b/pr-checks/api-client.ts @@ -1,3 +1,5 @@ +import { ParseArgsConfig } from "node:util"; + import * as githubUtils from "@actions/github/lib/utils"; import { type Octokit } from "@octokit/core"; import { type PaginateInterface } from "@octokit/plugin-paginate-rest"; @@ -11,3 +13,16 @@ export function getApiClient(token: string): ApiClient { const opts = githubUtils.getOctokitOptions(token); return new githubUtils.GitHub(opts); } + +export interface TokenOption { + /** The token to use to authenticate to the GitHub API. */ + token?: string; +} + +/** Command-line argument parser settings for the token parameter. */ +export const TOKEN_OPTION_CONFIG = { + // The token to use to authenticate to the API. + token: { + type: "string", + }, +} satisfies ParseArgsConfig["options"]; diff --git a/pr-checks/sync-checks.ts b/pr-checks/sync-checks.ts index ef0753110..ab9d237ca 100755 --- a/pr-checks/sync-checks.ts +++ b/pr-checks/sync-checks.ts @@ -7,16 +7,19 @@ import { parseArgs } from "node:util"; import * as yaml from "yaml"; -import { type ApiClient, getApiClient } from "./api-client"; +import { + type ApiClient, + getApiClient, + TOKEN_OPTION_CONFIG, + TokenOption, +} from "./api-client"; import { OLDEST_SUPPORTED_MAJOR_VERSION, PR_CHECK_EXCLUDED_FILE, } from "./config"; /** Represents the command-line options. */ -export interface Options { - /** The token to use to authenticate to the GitHub API. */ - token?: string; +export interface Options extends TokenOption { /** The git ref to use the checks for. */ ref?: string; /** Whether to actually apply the changes or not. */ @@ -205,10 +208,7 @@ async function updateBranch( async function main(): Promise { const { values: options } = parseArgs({ options: { - // The token to use to authenticate to the API. - token: { - type: "string", - }, + ...TOKEN_OPTION_CONFIG, // The git ref for which to retrieve the check runs. ref: { type: "string",