From 6782ba86ce924295ac33d2ba69f4fff565a04ec7 Mon Sep 17 00:00:00 2001 From: Trond Einar Snekvik Date: Fri, 3 Nov 2023 12:00:07 +0100 Subject: [PATCH] Fall back to GitHub CLI for local authentication (#23) If GITHUB_TOKEN is not defined, this will query the `gh` utility for a PAT, so the index can be generated locally without passing the env variable to the command. --- scripts/generate-index-json.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/generate-index-json.ts b/scripts/generate-index-json.ts index 1e7d0cb..9097e4f 100644 --- a/scripts/generate-index-json.ts +++ b/scripts/generate-index-json.ts @@ -20,6 +20,7 @@ import type { Application, } from '../site/src/schema'; import { ParsedOrgFile, readOrgIndexFiles } from './orgFiles'; +import { execSync } from 'child_process'; const nordicOrgs: string[] = ['nrfconnect', 'nordic', 'nordicplayground']; const partnerOrgs: string[] = ['golioth']; @@ -29,7 +30,8 @@ function notUndefined(value: T | undefined): value is T { } function initialiseGitHubApi() { - const authToken = process.env.GITHUB_TOKEN; + const authToken = + process.env.GITHUB_TOKEN ?? execSync('gh auth token', { encoding: 'utf-8' }).trim(); if (!authToken) { throw new Error(