From eee0e7a898e0625f2b6e99af5f2408a3e44306a1 Mon Sep 17 00:00:00 2001 From: nitesh404240 Date: Thu, 30 Oct 2025 23:33:57 +0530 Subject: [PATCH] feat(utils): add GH_TOKEN and .env fallback support for getGitHubToken Enhanced getGitHubToken to improve flexibility and local development support. - Added fallback to GH_TOKEN environment variable - Added ability to read GITHUB_TOKEN from a .env file in the project root - Improved error message when no token is found This update ensures authentication works in both CI environments and local setups without requiring manual environment variable configuration. --- scripts/docs/src/utils.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/scripts/docs/src/utils.ts b/scripts/docs/src/utils.ts index cdcb27552..89b97f7de 100644 --- a/scripts/docs/src/utils.ts +++ b/scripts/docs/src/utils.ts @@ -20,11 +20,25 @@ export function getRepoRoot(): string { throw new Error("Could not find project root"); } -export function getGitHubToken() { - const token = process.env.GITHUB_TOKEN; +export function getGitHubToken(): string { + let token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN; if (!token) { - throw new Error("GITHUB_TOKEN environment variable is required."); + const envPath = path.join(process.cwd(), ".env"); + if (existsSync(envPath)) { + const content = readFileSync(envPath, "utf-8"); + const match = content.match(/^GITHUB_TOKEN\s*=\s*(.+)$/m); + if (match) token = match[1].trim(); + } + } + + if (!token) { + throw new Error( + `Missing GitHub authentication token. +Please set one of the following: +- GITHUB_TOKEN or GH_TOKEN environment variable +- Or add GITHUB_TOKEN to a .env file in the project root` + ); } return token;