Clean up init
This commit is contained in:
@@ -39287,18 +39287,26 @@ var init_buildPullfrogFooter = __esm({
|
||||
// mcp/shared.ts
|
||||
function initMcpContext(state) {
|
||||
mcpInitContext = state;
|
||||
cachedMcpContext = void 0;
|
||||
}
|
||||
function getMcpContext() {
|
||||
async function getMcpContext() {
|
||||
if (!mcpInitContext) {
|
||||
throw new Error("MCP context not initialized. Call initializeMcpContext first.");
|
||||
}
|
||||
return {
|
||||
if (cachedMcpContext) {
|
||||
return cachedMcpContext;
|
||||
}
|
||||
const repoContext = parseRepoContext();
|
||||
const octokit = new Octokit2({
|
||||
auth: getGitHubInstallationToken()
|
||||
});
|
||||
cachedMcpContext = {
|
||||
...mcpInitContext,
|
||||
...parseRepoContext(),
|
||||
octokit: new Octokit2({
|
||||
auth: getGitHubInstallationToken()
|
||||
})
|
||||
...repoContext,
|
||||
octokit,
|
||||
repo: mcpInitContext.repo
|
||||
};
|
||||
return cachedMcpContext;
|
||||
}
|
||||
function isProgressCommentDisabled() {
|
||||
return mcpInitContext?.payload.disableProgressComment === true;
|
||||
@@ -39382,7 +39390,7 @@ function sanitizeTool(tool2) {
|
||||
parameters: wrappedSchema
|
||||
};
|
||||
}
|
||||
var mcpInitContext, tool, addTools, contextualize, handleToolSuccess, handleToolError;
|
||||
var mcpInitContext, cachedMcpContext, tool, addTools, contextualize, handleToolSuccess, handleToolError;
|
||||
var init_shared3 = __esm({
|
||||
"mcp/shared.ts"() {
|
||||
"use strict";
|
||||
@@ -39400,7 +39408,7 @@ var init_shared3 = __esm({
|
||||
contextualize = (executor) => {
|
||||
return async (params) => {
|
||||
try {
|
||||
const ctx = getMcpContext();
|
||||
const ctx = await getMcpContext();
|
||||
const result = await executor(params, ctx);
|
||||
return handleToolSuccess(result);
|
||||
} catch (error41) {
|
||||
@@ -39491,7 +39499,7 @@ function setProgressCommentId(id) {
|
||||
progressCommentIdInitialized = true;
|
||||
}
|
||||
async function reportProgress({ body }) {
|
||||
const ctx = getMcpContext();
|
||||
const ctx = await getMcpContext();
|
||||
const bodyWithFooter = addFooter(body, ctx.payload);
|
||||
const existingCommentId = getProgressCommentId();
|
||||
if (existingCommentId) {
|
||||
@@ -39536,7 +39544,7 @@ async function deleteProgressComment() {
|
||||
if (!existingCommentId) {
|
||||
return false;
|
||||
}
|
||||
const ctx = getMcpContext();
|
||||
const ctx = await getMcpContext();
|
||||
await ctx.octokit.rest.issues.deleteComment({
|
||||
owner: ctx.owner,
|
||||
repo: ctx.name,
|
||||
@@ -39588,7 +39596,7 @@ async function ensureProgressCommentUpdated(payload) {
|
||||
}
|
||||
let resolvedPayload;
|
||||
try {
|
||||
const ctx = getMcpContext();
|
||||
const ctx = await getMcpContext();
|
||||
resolvedPayload = ctx.payload;
|
||||
} catch {
|
||||
resolvedPayload = payload;
|
||||
@@ -99850,6 +99858,7 @@ var agents = {
|
||||
import { mkdtemp as mkdtemp2 } from "node:fs/promises";
|
||||
import { tmpdir as tmpdir2 } from "node:os";
|
||||
import { join as join8 } from "node:path";
|
||||
init_dist_src5();
|
||||
init_out4();
|
||||
init_external();
|
||||
init_comment();
|
||||
@@ -124356,36 +124365,40 @@ function containsSecrets(content, secrets) {
|
||||
|
||||
// mcp/git.ts
|
||||
init_shared3();
|
||||
var CreateBranch = type({
|
||||
branchName: type.string.describe(
|
||||
"The name of the branch to create (e.g., 'pullfrog/123-fix-bug')"
|
||||
),
|
||||
baseBranch: type.string.describe("The base branch to create from (e.g., 'main')").default("main")
|
||||
});
|
||||
var CreateBranchTool = tool({
|
||||
name: "create_branch",
|
||||
description: "Create a new git branch from the specified base branch. The branch will be created locally and pushed to the remote repository.",
|
||||
parameters: CreateBranch,
|
||||
execute: contextualize(async ({ branchName, baseBranch }) => {
|
||||
if (containsSecrets(branchName)) {
|
||||
throw new Error(
|
||||
"Branch creation blocked: secrets detected in branch name. Please remove any sensitive information (API keys, tokens, passwords) before creating a branch."
|
||||
);
|
||||
}
|
||||
log.info(`Creating branch ${branchName} from ${baseBranch}`);
|
||||
$("git", ["fetch", "origin", baseBranch, "--depth=1"]);
|
||||
$("git", ["checkout", "-B", baseBranch, `origin/${baseBranch}`]);
|
||||
$("git", ["checkout", "-b", branchName]);
|
||||
$("git", ["push", "-u", "origin", branchName]);
|
||||
log.info(`Successfully created and pushed branch ${branchName}`);
|
||||
return {
|
||||
success: true,
|
||||
branchName,
|
||||
baseBranch,
|
||||
message: `Branch ${branchName} created from ${baseBranch} and pushed to remote`
|
||||
};
|
||||
})
|
||||
});
|
||||
function CreateBranchTool(ctx) {
|
||||
const defaultBranch = ctx.repo.default_branch || "main";
|
||||
const CreateBranch = type({
|
||||
branchName: type.string.describe(
|
||||
"The name of the branch to create (e.g., 'pullfrog/123-fix-bug')"
|
||||
),
|
||||
baseBranch: type.string.describe(`The base branch to create from (defaults to '${defaultBranch}')`).default(defaultBranch)
|
||||
});
|
||||
return tool({
|
||||
name: "create_branch",
|
||||
description: "Create a new git branch from the specified base branch. The branch will be created locally and pushed to the remote repository.",
|
||||
parameters: CreateBranch,
|
||||
execute: contextualize(async ({ branchName, baseBranch }) => {
|
||||
const resolvedBaseBranch = baseBranch || ctx.repo.default_branch || "main";
|
||||
if (containsSecrets(branchName)) {
|
||||
throw new Error(
|
||||
"Branch creation blocked: secrets detected in branch name. Please remove any sensitive information (API keys, tokens, passwords) before creating a branch."
|
||||
);
|
||||
}
|
||||
log.info(`Creating branch ${branchName} from ${resolvedBaseBranch}`);
|
||||
$("git", ["fetch", "origin", resolvedBaseBranch, "--depth=1"]);
|
||||
$("git", ["checkout", "-B", resolvedBaseBranch, `origin/${resolvedBaseBranch}`]);
|
||||
$("git", ["checkout", "-b", branchName]);
|
||||
$("git", ["push", "-u", "origin", branchName]);
|
||||
log.info(`Successfully created and pushed branch ${branchName}`);
|
||||
return {
|
||||
success: true,
|
||||
branchName,
|
||||
baseBranch: resolvedBaseBranch,
|
||||
message: `Branch ${branchName} created from ${resolvedBaseBranch} and pushed to remote`
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
var CommitFiles = type({
|
||||
message: type.string.describe("The commit message"),
|
||||
files: type.string.array().describe(
|
||||
@@ -124440,27 +124453,31 @@ var PushBranch = type({
|
||||
branchName: type.string.describe("The branch name to push (defaults to current branch)").optional(),
|
||||
force: type.boolean.describe("Force push (use with caution)").default(false)
|
||||
});
|
||||
var PushBranchTool = tool({
|
||||
name: "push_branch",
|
||||
description: "Push the current branch (or specified branch) to the remote repository. Never force push unless explicitly requested.",
|
||||
parameters: PushBranch,
|
||||
execute: contextualize(async ({ branchName, force }) => {
|
||||
const branch = branchName || $("git", ["rev-parse", "--abbrev-ref", "HEAD"], { log: false });
|
||||
if (force) {
|
||||
log.warning(`Force pushing branch ${branch} - this will overwrite remote history`);
|
||||
$("git", ["push", "--force", "origin", branch]);
|
||||
} else {
|
||||
log.info(`Pushing branch ${branch} to remote`);
|
||||
$("git", ["push", "origin", branch]);
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
branch,
|
||||
force,
|
||||
message: `Successfully pushed branch ${branch} to remote`
|
||||
};
|
||||
})
|
||||
});
|
||||
function PushBranchTool(ctx) {
|
||||
const remote = ctx.pushRemote;
|
||||
return tool({
|
||||
name: "push_branch",
|
||||
description: "Push the current branch (or specified branch) to the remote repository. Never force push unless explicitly requested.",
|
||||
parameters: PushBranch,
|
||||
execute: contextualize(async ({ branchName, force }) => {
|
||||
const branch = branchName || $("git", ["rev-parse", "--abbrev-ref", "HEAD"], { log: false });
|
||||
log.info(`Pushing branch ${branch} to ${remote}`);
|
||||
if (force) {
|
||||
log.warning(`Force pushing - this will overwrite remote history`);
|
||||
$("git", ["push", "--force", "-u", remote, branch]);
|
||||
} else {
|
||||
$("git", ["push", "-u", remote, branch]);
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
branch,
|
||||
remote,
|
||||
force,
|
||||
message: `Successfully pushed branch ${branch} to ${remote}`
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// mcp/issue.ts
|
||||
init_out4();
|
||||
@@ -125043,6 +125060,7 @@ async function startMcpHttpServer(state) {
|
||||
name: ghPullfrogMcpName,
|
||||
version: "0.0.1"
|
||||
});
|
||||
const ctx = await getMcpContext();
|
||||
const tools = [
|
||||
SelectModeTool,
|
||||
CreateCommentTool,
|
||||
@@ -125060,9 +125078,9 @@ async function startMcpHttpServer(state) {
|
||||
GetCheckSuiteLogsTool,
|
||||
DebugShellCommandTool,
|
||||
AddLabelsTool,
|
||||
CreateBranchTool,
|
||||
CreateBranchTool(ctx),
|
||||
CommitFilesTool,
|
||||
PushBranchTool
|
||||
PushBranchTool(ctx)
|
||||
];
|
||||
if (!isProgressCommentDisabled()) {
|
||||
tools.push(ReportProgressTool);
|
||||
@@ -125156,7 +125174,6 @@ init_github();
|
||||
// utils/setup.ts
|
||||
import { execSync } from "node:child_process";
|
||||
init_cli();
|
||||
init_github();
|
||||
function setupGitConfig() {
|
||||
const repoDir = process.cwd();
|
||||
log.info("\u{1F527} Setting up git configuration...");
|
||||
@@ -125176,9 +125193,10 @@ function setupGitConfig() {
|
||||
);
|
||||
}
|
||||
}
|
||||
function setupGitAuth(ctx) {
|
||||
function setupGit(ctx) {
|
||||
const { githubInstallationToken: githubInstallationToken2, payload } = ctx;
|
||||
const repoDir = process.cwd();
|
||||
log.info("\u{1F510} Setting up git authentication...");
|
||||
log.info("\u{1F527} Setting up git configuration...");
|
||||
try {
|
||||
execSync("git config --local --unset-all http.https://github.com/.extraheader", {
|
||||
cwd: repoDir,
|
||||
@@ -125188,24 +125206,39 @@ function setupGitAuth(ctx) {
|
||||
} catch {
|
||||
log.debug("No existing authentication headers to remove");
|
||||
}
|
||||
const remoteUrl = `https://x-access-token:${ctx.githubInstallationToken}@github.com/${ctx.repoContext.owner}/${ctx.repoContext.name}.git`;
|
||||
$("git", ["remote", "set-url", "origin", remoteUrl], { cwd: repoDir });
|
||||
log.info("\u2713 Updated remote URL with authentication token (scoped to repo)");
|
||||
}
|
||||
function setupGitBranch(payload) {
|
||||
$("git", ["config", "--local", "credential.helper", ""], { cwd: repoDir });
|
||||
$("git", ["config", "--local", "--add", "credential.helper", "!gh auth git-credential"], {
|
||||
cwd: repoDir,
|
||||
env: { GH_TOKEN: githubInstallationToken2 }
|
||||
});
|
||||
log.info("\u2713 Configured gh as credential helper");
|
||||
if (payload.event.is_pr !== true || !payload.event.issue_number) {
|
||||
log.debug("Not a PR event, staying on default branch");
|
||||
return;
|
||||
return { pushRemote: "origin" };
|
||||
}
|
||||
const prNumber = payload.event.issue_number;
|
||||
const repoDir = process.cwd();
|
||||
log.info(`\u{1F33F} Checking out PR #${prNumber}...`);
|
||||
const token = getGitHubInstallationToken();
|
||||
$("gh", ["pr", "checkout", prNumber.toString()], {
|
||||
cwd: repoDir,
|
||||
env: { GH_TOKEN: token }
|
||||
env: { GH_TOKEN: githubInstallationToken2 }
|
||||
});
|
||||
log.info(`\u2713 Successfully checked out PR #${prNumber}`);
|
||||
const pushRemote = detectPushRemote();
|
||||
if (pushRemote !== "origin") {
|
||||
log.info(`\u{1F374} Fork PR detected, will push to remote: ${pushRemote}`);
|
||||
}
|
||||
return { pushRemote };
|
||||
}
|
||||
function detectPushRemote() {
|
||||
try {
|
||||
const branch = $("git", ["rev-parse", "--abbrev-ref", "HEAD"], { log: false });
|
||||
const upstream = $("git", ["rev-parse", "--abbrev-ref", `${branch}@{upstream}`], {
|
||||
log: false
|
||||
});
|
||||
return upstream.split("/")[0];
|
||||
} catch {
|
||||
return "origin";
|
||||
}
|
||||
}
|
||||
|
||||
// utils/timer.ts
|
||||
@@ -125245,13 +125278,11 @@ async function main(inputs) {
|
||||
const partialCtx = await initializeContext(inputs, payload);
|
||||
const ctx = partialCtx;
|
||||
timer.checkpoint("initializeContext");
|
||||
setupGitAuth({
|
||||
githubInstallationToken: ctx.githubInstallationToken,
|
||||
repoContext: ctx.repoContext
|
||||
});
|
||||
const { pushRemote } = setupGit(ctx);
|
||||
ctx.pushRemote = pushRemote;
|
||||
timer.checkpoint("setupGit");
|
||||
await setupTempDirectory(ctx);
|
||||
timer.checkpoint("setupTempDirectory");
|
||||
setupGitBranch(ctx.payload);
|
||||
await startMcpServer(ctx);
|
||||
mcpServerClose = ctx.mcpServerClose;
|
||||
timer.checkpoint("startMcpServer");
|
||||
@@ -125349,6 +125380,21 @@ async function initializeContext(inputs, payload) {
|
||||
setupGitConfig();
|
||||
const githubInstallationToken2 = await setupGitHubInstallationToken();
|
||||
const repoContext = parseRepoContext();
|
||||
const octokit = new Octokit2({
|
||||
auth: githubInstallationToken2
|
||||
});
|
||||
let repo;
|
||||
try {
|
||||
const response = await octokit.repos.get({
|
||||
owner: repoContext.owner,
|
||||
repo: repoContext.name
|
||||
});
|
||||
repo = response.data;
|
||||
} catch {
|
||||
repo = {
|
||||
default_branch: "main"
|
||||
};
|
||||
}
|
||||
const { agentName, agent: agent2 } = await resolveAgent(
|
||||
inputs,
|
||||
payload,
|
||||
@@ -125360,6 +125406,7 @@ async function initializeContext(inputs, payload) {
|
||||
inputs,
|
||||
githubInstallationToken: githubInstallationToken2,
|
||||
repoContext,
|
||||
repo,
|
||||
agentName,
|
||||
agent: agent2,
|
||||
payload: resolvedPayload,
|
||||
@@ -125448,7 +125495,9 @@ async function startMcpServer(ctx) {
|
||||
const { url: url2, close } = await startMcpHttpServer({
|
||||
payload: ctx.payload,
|
||||
modes: allModes,
|
||||
agentName: ctx.agentName
|
||||
agentName: ctx.agentName,
|
||||
repo: ctx.repo,
|
||||
pushRemote: ctx.pushRemote
|
||||
});
|
||||
ctx.mcpServerUrl = url2;
|
||||
ctx.mcpServerClose = close;
|
||||
|
||||
Reference in New Issue
Block a user