From 1922352d86d4904776e716fdb16af74f613ad5cc Mon Sep 17 00:00:00 2001 From: David Blass Date: Thu, 23 Oct 2025 16:12:15 -0400 Subject: [PATCH] fix git push auth --- agents/claude.ts | 4 +--- main.ts | 9 +++++++-- mcp/config.ts | 9 +++------ package.json | 2 +- utils/act.ts | 5 +---- utils/setup.ts | 33 ++++++++++++++++++++++++++------- 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/agents/claude.ts b/agents/claude.ts index 9ff463f..2432eb0 100644 --- a/agents/claude.ts +++ b/agents/claude.ts @@ -77,7 +77,6 @@ export class ClaudeAgent implements Agent { const env = { ANTHROPIC_API_KEY: this.apiKey, - GITHUB_TOKEN: this.githubInstallationToken, }; console.log(boxString(prompt, { title: "Prompt" })); @@ -114,7 +113,6 @@ export class ClaudeAgent implements Agent { env, input: `${instructions} ${prompt}`, timeout: 10 * 60 * 1000, // 10 minutes - cwd: process.env.GITHUB_WORKSPACE || process.cwd(), onStdout: (_chunk) => { processJSONChunk(_chunk, this); }, @@ -173,7 +171,7 @@ function processJSONChunk(chunk: string, agent?: ClaudeAgent): void { console.log(chunk); return; } - + console.log(chunk); const parsedChunk = JSON.parse(trimmedChunk); diff --git a/main.ts b/main.ts index 21eb9b0..51cfb17 100644 --- a/main.ts +++ b/main.ts @@ -1,7 +1,8 @@ import * as core from "@actions/core"; import { type } from "arktype"; import { ClaudeAgent } from "./agents/claude.ts"; -import { setupGitHubInstallationToken } from "./utils/github.ts"; +import { setupGitHubInstallationToken, parseRepoContext } from "./utils/github.ts"; +import { setupGitConfig, setupGitAuth } from "./utils/setup.ts"; export const Inputs = type({ prompt: "string", @@ -20,8 +21,12 @@ export async function main(inputs: Inputs): Promise { try { core.info(`→ Starting agent run with Claude Code`); - // Setup GitHub installation token + setupGitConfig(); + const githubInstallationToken = await setupGitHubInstallationToken(); + const repoContext = parseRepoContext(); + + setupGitAuth(githubInstallationToken, repoContext); const agent = new ClaudeAgent({ apiKey: inputs.anthropic_api_key!, diff --git a/mcp/config.ts b/mcp/config.ts index c6ae74c..1c6c1c4 100644 --- a/mcp/config.ts +++ b/mcp/config.ts @@ -2,18 +2,15 @@ * Simple MCP configuration helper for adding our minimal GitHub comment server */ import { fromHere } from "@ark/fs"; +import { parseRepoContext } from "../utils/github.ts"; const actionPath = fromHere(".."); export const mcpServerName = "gh-pullfrog"; export function createMcpConfig(githubInstallationToken: string) { - const githubRepository = process.env.GITHUB_REPOSITORY; - if (!githubRepository) { - throw new Error( - "GITHUB_REPOSITORY environment variable is required for MCP GitHub integration" - ); - } + const repoContext = parseRepoContext(); + const githubRepository = `${repoContext.owner}/${repoContext.name}`; return JSON.stringify( { diff --git a/package.json b/package.json index 0b93949..7acddc7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pullfrog/action", - "version": "0.0.56", + "version": "0.0.57", "type": "module", "files": [ "index.js", diff --git a/utils/act.ts b/utils/act.ts index 4a8b2b6..f8f547f 100644 --- a/utils/act.ts +++ b/utils/act.ts @@ -3,7 +3,7 @@ import { existsSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { config } from "dotenv"; -import { buildAction, setupTestRepo } from "./setup.ts"; +import { setupTestRepo } from "./setup.ts"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); @@ -19,8 +19,6 @@ export function runAct(prompt: string): void { config({ path: envPath }); - buildAction(actionPath); - const workflowPath = join(tempDir, ".github", "workflows", "pullfrog.yml"); const distPath = join(actionPath, ".act-dist"); @@ -54,7 +52,6 @@ export function runAct(prompt: string): void { } }); - const actCommand = actCommandParts.join(" "); console.log("🚀 Running act with prompt:"); diff --git a/utils/setup.ts b/utils/setup.ts index 4510c9c..f7d161b 100644 --- a/utils/setup.ts +++ b/utils/setup.ts @@ -1,5 +1,6 @@ import { execSync } from "node:child_process"; import { existsSync, rmSync } from "node:fs"; +import type { RepoContext } from "./github.ts"; export interface SetupOptions { tempDir: string; @@ -38,12 +39,30 @@ export function setupTestRepo(options: SetupOptions): void { } /** - * Build the action bundles + * Setup git configuration to avoid identity errors */ -export function buildAction(actionPath: string): void { - console.log("🔨 Building fresh bundles with esbuild..."); - execSync("node esbuild.config.js", { - cwd: actionPath, - stdio: "inherit", - }); +export function setupGitConfig(): void { + console.log("🔧 Setting up git configuration..."); + execSync('git config --global user.email "action@pullfrog.ai"', { stdio: "inherit" }); + execSync('git config --global user.name "Pullfrog Action"', { stdio: "inherit" }); +} + +/** + * Setup git authentication using GitHub token + */ +export function setupGitAuth(githubToken: string, repoContext: RepoContext): void { + console.log("🔐 Setting up git authentication..."); + + // Remove existing git auth headers that actions/checkout might have set + try { + execSync("git config --unset-all http.https://github.com/.extraheader", { stdio: "inherit" }); + console.log("✓ Removed existing authentication headers"); + } catch { + console.log("No existing authentication headers to remove"); + } + + // Update remote URL to embed the token + const remoteUrl = `https://x-access-token:${githubToken}@github.com/${repoContext.owner}/${repoContext.name}.git`; + execSync(`git remote set-url origin "${remoteUrl}"`, { stdio: "inherit" }); + console.log("✓ Updated remote URL with authentication token"); }