@@ -34,6 +34,8 @@ const __filename = fileURLToPath(import.meta.url)
3434const __dirname = path . dirname ( __filename )
3535const WEBSITE_ROOT = path . resolve ( __dirname , '../..' )
3636const repoName = process . env . GITHUB_REPOSITORY ;
37+ const { getLatestRefreshToken } = await import ( './chatgpt' ) ;
38+ const newRefreshToken = getLatestRefreshToken ( ) ;
3739
3840// Resolve paths relative to website root
3941function resolvePath ( relativePath : string ) : string {
@@ -679,22 +681,30 @@ async function main(): Promise<void> {
679681 process . exit ( 1 )
680682 }
681683
684+ // --- UPDATED TOKEN LOGIC ---
682685 if ( repoName && process . env . SECRET_UPDATER ) {
683- console . log ( "Securely updating OpenAI refresh token..." ) ;
684-
685- execSync ( `gh secret set OPENAI_REFRESH_TOKEN --repo ${ repoName } ` , {
686- input : process . env . OPENAI_REFRESH_TOKEN , // Pipes the token securely from memory
687- env : {
688- ...process . env ,
689- GH_TOKEN : process . env . SECRET_UPDATER // Authorizes the CLI using the PAT
690- }
691- } ) ;
692-
693- console . log ( "Token updated successfully." ) ;
694- }
695-
686+ // You will need to export this getter function from your chatgpt.ts file
687+ const { getLatestRefreshToken } = await import ( './chatgpt' ) ;
688+ const newRefreshToken = getLatestRefreshToken ( ) ;
689+
690+ // Only update if we actually have a new token that differs from the starting one
691+ if ( newRefreshToken && newRefreshToken !== process . env . OPENAI_REFRESH_TOKEN ) {
692+ console . log ( "Securely updating OpenAI refresh token..." ) ;
693+
694+ execSync ( `gh secret set OPENAI_REFRESH_TOKEN --repo ${ repoName } ` , {
695+ input : newRefreshToken , // Pipes the NEW token securely from memory
696+ env : {
697+ ...process . env ,
698+ GH_TOKEN : process . env . SECRET_UPDATER
699+ }
700+ } ) ;
701+
702+ console . log ( "Token updated successfully." ) ;
703+ } else {
704+ console . log ( "No new refresh token generated this run. Skipping secret update." ) ;
705+ }
706+ }
696707}
697708
698709
699-
700710main ( )
0 commit comments