Skip to content

Commit dbfd510

Browse files
committed
Make token parameter reusable
1 parent 4acf6eb commit dbfd510

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

pr-checks/api-client.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ParseArgsConfig } from "node:util";
2+
13
import * as githubUtils from "@actions/github/lib/utils";
24
import { type Octokit } from "@octokit/core";
35
import { type PaginateInterface } from "@octokit/plugin-paginate-rest";
@@ -11,3 +13,16 @@ export function getApiClient(token: string): ApiClient {
1113
const opts = githubUtils.getOctokitOptions(token);
1214
return new githubUtils.GitHub(opts);
1315
}
16+
17+
export interface TokenOption {
18+
/** The token to use to authenticate to the GitHub API. */
19+
token?: string;
20+
}
21+
22+
/** Command-line argument parser settings for the token parameter. */
23+
export const TOKEN_OPTION_CONFIG = {
24+
// The token to use to authenticate to the API.
25+
token: {
26+
type: "string",
27+
},
28+
} satisfies ParseArgsConfig["options"];

pr-checks/sync-checks.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ import { parseArgs } from "node:util";
77

88
import * as yaml from "yaml";
99

10-
import { type ApiClient, getApiClient } from "./api-client";
10+
import {
11+
type ApiClient,
12+
getApiClient,
13+
TOKEN_OPTION_CONFIG,
14+
TokenOption,
15+
} from "./api-client";
1116
import {
1217
OLDEST_SUPPORTED_MAJOR_VERSION,
1318
PR_CHECK_EXCLUDED_FILE,
1419
} from "./config";
1520

1621
/** Represents the command-line options. */
17-
export interface Options {
18-
/** The token to use to authenticate to the GitHub API. */
19-
token?: string;
22+
export interface Options extends TokenOption {
2023
/** The git ref to use the checks for. */
2124
ref?: string;
2225
/** Whether to actually apply the changes or not. */
@@ -205,10 +208,7 @@ async function updateBranch(
205208
async function main(): Promise<void> {
206209
const { values: options } = parseArgs({
207210
options: {
208-
// The token to use to authenticate to the API.
209-
token: {
210-
type: "string",
211-
},
211+
...TOKEN_OPTION_CONFIG,
212212
// The git ref for which to retrieve the check runs.
213213
ref: {
214214
type: "string",

0 commit comments

Comments
 (0)