updated prepare.ts so Claude Code token written
This commit is contained in:
@@ -18,6 +18,7 @@ import { createPrompt } from "../create-prompt";
|
||||
import { createClient } from "../github/api/client";
|
||||
import { fetchGitHubData } from "../github/data/fetcher";
|
||||
import { parseGitHubContext } from "../github/context";
|
||||
import { setupOAuthCredentials } from "../claude/oauth-setup";
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
@@ -27,18 +28,25 @@ async function run() {
|
||||
|
||||
// Check if OAuth credentials are provided and API key is empty (OAuth mode)
|
||||
if (claudeCredentials && !anthropicApiKey) {
|
||||
// Parse the credentials to extract the access token
|
||||
// Write the credentials to the file system for Claude Code
|
||||
try {
|
||||
const parsedCredentials = JSON.parse(claudeCredentials);
|
||||
if (parsedCredentials.claudeAiOauth?.accessToken) {
|
||||
// Output the access token for the base action to use
|
||||
core.setOutput("claude_oauth_token", parsedCredentials.claudeAiOauth.accessToken);
|
||||
console.log("OAuth access token extracted for Claude AI Max subscription");
|
||||
} else {
|
||||
throw new Error("Invalid credentials format: missing claudeAiOauth.accessToken");
|
||||
await setupOAuthCredentials(claudeCredentials);
|
||||
console.log("OAuth credentials written to ~/.claude/.credentials.json");
|
||||
|
||||
// Also extract the token for any other uses
|
||||
try {
|
||||
const parsedCredentials = JSON.parse(claudeCredentials);
|
||||
if (parsedCredentials.claudeAiOauth?.accessToken) {
|
||||
// Output the access token for the base action to use
|
||||
core.setOutput("claude_oauth_token", parsedCredentials.claudeAiOauth.accessToken);
|
||||
console.log("OAuth access token extracted for Claude AI Max subscription");
|
||||
}
|
||||
} catch (parseError) {
|
||||
// Log but don't fail - credentials are already written
|
||||
console.log("Could not extract OAuth token for output:", parseError);
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to parse OAuth credentials: ${error instanceof Error ? error.message : String(error)}`);
|
||||
throw new Error(`Failed to setup OAuth credentials: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user