@@ -15,17 +15,15 @@ import { calculateDateRange } from "@/lib/date-utils";
1515// Load environment variables from .env file
1616loadEnv ( ) ;
1717
18- // Validate required environment variables
19- const requiredEnvVars = [ "GITHUB_TOKEN" , "OPENROUTER_API_KEY" ] ;
20- const missingEnvVars = requiredEnvVars . filter ( ( envVar ) => ! process . env [ envVar ] ) ;
21-
22- if ( missingEnvVars . length > 0 ) {
23- console . error (
24- `Error: Missing required environment variables: ${ missingEnvVars . join (
25- ", " ,
26- ) } `,
27- ) ;
28- process . exit ( 1 ) ;
18+ // Helper to validate environment variables
19+ function validateEnvVars ( requiredVars : string [ ] ) {
20+ const missingVars = requiredVars . filter ( ( envVar ) => ! process . env [ envVar ] ) ;
21+ if ( missingVars . length > 0 ) {
22+ console . error (
23+ `Error: Missing required environment variables: ${ missingVars . join ( ", " ) } ` ,
24+ ) ;
25+ process . exit ( 1 ) ;
26+ }
2927}
3028
3129import { Command } from "@commander-js/extra-typings" ;
@@ -76,6 +74,9 @@ program
7674 false ,
7775 )
7876 . action ( async ( options ) => {
77+ // Validate required environment variables for ingestion
78+ validateEnvVars ( [ "GITHUB_TOKEN" ] ) ;
79+
7980 try {
8081 // Dynamically import the config
8182 const configPath = join ( import . meta. dir , options . config ) ;
@@ -140,6 +141,9 @@ program
140141 false ,
141142 )
142143 . action ( async ( options ) => {
144+ // Validate required environment variables for processing
145+ validateEnvVars ( [ "GITHUB_TOKEN" ] ) ;
146+
143147 try {
144148 // Dynamically import the config
145149 const configPath = join ( import . meta. dir , options . config ) ;
@@ -200,6 +204,9 @@ program
200204 . option ( "-d, --days <number>" , "Number of days to look back from before date" )
201205 . option ( "--all" , "Process all data since contributionStartDate" , false )
202206 . action ( async ( options ) => {
207+ // Validate required environment variables for export
208+ validateEnvVars ( [ "GITHUB_TOKEN" ] ) ;
209+
203210 try {
204211 // Dynamically import the config
205212 const configPath = join ( import . meta. dir , options . config ) ;
@@ -288,6 +295,8 @@ program
288295 . option ( "--weekly" , "Generate weekly summaries" )
289296 . option ( "--monthly" , "Generate monthly summaries" )
290297 . action ( async ( options ) => {
298+ // Validate required environment variables for AI summaries
299+ validateEnvVars ( [ "GITHUB_TOKEN" , "OPENROUTER_API_KEY" ] ) ;
291300 try {
292301 // Dynamically import the config
293302 const configPath = join ( import . meta. dir , options . config ) ;
0 commit comments