mirror of
https://github.com/github/codeql-action.git
synced 2026-11-10 14:56:01 +00:00
Move resolveToken to pr-checks/api-client.ts
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user