+19
-5
@@ -1,6 +1,7 @@
|
||||
import { execSync } from "node:child_process";
|
||||
import { existsSync, rmSync } from "node:fs";
|
||||
import type { Context } from "../main.ts";
|
||||
import { checkoutPrBranch } from "../mcp/checkout.ts";
|
||||
import { log } from "./cli.ts";
|
||||
import { $ } from "./shell.ts";
|
||||
|
||||
@@ -72,11 +73,11 @@ export function setupGitConfig(): void {
|
||||
|
||||
/**
|
||||
* Setup git authentication for the repository.
|
||||
* PR checkout is handled dynamically by the checkout_pr MCP tool.
|
||||
* For PR events, uses the shared checkoutPrBranch helper (also used by checkout_pr MCP tool).
|
||||
*
|
||||
* FORK PR ARCHITECTURE (handled by checkout_pr tool):
|
||||
* FORK PR ARCHITECTURE:
|
||||
* - origin: always points to BASE REPO (where PR targets)
|
||||
* - checkout_pr sets per-branch pushRemote config for fork PRs
|
||||
* - checkoutPrBranch sets per-branch pushRemote config for fork PRs
|
||||
* - diff operations use: git diff origin/<base>..HEAD
|
||||
*/
|
||||
export async function setupGit(ctx: Context): Promise<void> {
|
||||
@@ -95,8 +96,21 @@ export async function setupGit(ctx: Context): Promise<void> {
|
||||
log.debug("no existing authentication headers to remove");
|
||||
}
|
||||
|
||||
// authenticate origin - needed for all fetch operations including PR fetches
|
||||
// non-PR events: set up origin with token, stay on default branch
|
||||
if (ctx.payload.event.is_pr !== true || !ctx.payload.event.issue_number) {
|
||||
const originUrl = `https://x-access-token:${ctx.githubInstallationToken}@github.com/${ctx.owner}/${ctx.name}.git`;
|
||||
$("git", ["remote", "set-url", "origin", originUrl], { cwd: repoDir });
|
||||
log.info("✓ Updated origin URL with authentication token");
|
||||
return;
|
||||
}
|
||||
|
||||
// PR event: checkout PR branch using shared helper
|
||||
const prNumber = ctx.payload.event.issue_number;
|
||||
|
||||
// ensure origin is configured with auth token before checkout
|
||||
const originUrl = `https://x-access-token:${ctx.githubInstallationToken}@github.com/${ctx.owner}/${ctx.name}.git`;
|
||||
$("git", ["remote", "set-url", "origin", originUrl], { cwd: repoDir });
|
||||
log.info("✓ updated origin URL with authentication token");
|
||||
|
||||
// use shared checkout helper (handles fork remotes, push config, etc.)
|
||||
await checkoutPrBranch(ctx, prNumber);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user