mirror of
https://github.com/ivuorinen/gh-codeql-report.git
synced 2026-02-05 11:45:23 +00:00
Initial commit
This commit is contained in:
26
src/lib/auth.ts
Normal file
26
src/lib/auth.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
/**
|
||||
* Get GitHub token from GITHUB_TOKEN env var, or fall back to gh CLI
|
||||
*/
|
||||
export function getGitHubToken(): string {
|
||||
// First, try GITHUB_TOKEN environment variable
|
||||
const envToken = process.env.GITHUB_TOKEN;
|
||||
if (envToken) {
|
||||
return envToken;
|
||||
}
|
||||
|
||||
// Fall back to gh CLI
|
||||
try {
|
||||
const token = execSync('gh auth token', { encoding: 'utf-8' }).trim();
|
||||
if (token) {
|
||||
return token;
|
||||
}
|
||||
} catch (_error) {
|
||||
// gh CLI not available or not authenticated
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
'GitHub token not found. Please set GITHUB_TOKEN environment variable or authenticate with `gh auth login`',
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user