File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change @@ -7,12 +7,11 @@ Tests for post-comment.ts.
77import * as assert from "node:assert/strict" ;
88import { describe , it } from "node:test" ;
99
10- import { type ApiClient } from "./api-client" ;
10+ import { type ApiClient , resolveToken } from "./api-client" ;
1111import {
1212 findExistingComment ,
1313 type Options ,
1414 parseOptions ,
15- resolveToken ,
1615 setComment ,
1716} from "./post-comment" ;
1817
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ The `.github/actions/post-comment` action requires callers to supply this value
1717import assert from "node:assert/strict" ;
1818import { 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. */
2323export 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 */
You can’t perform that action at this time.
0 commit comments