diff --git a/src/handlers/front-controller.ts b/src/handlers/front-controller.ts index 20ae5070..c4ced799 100644 --- a/src/handlers/front-controller.ts +++ b/src/handlers/front-controller.ts @@ -14,7 +14,7 @@ export async function delegate(context: Context) { // Check if the comment is requesting to solve the issue if (body.toLowerCase().includes("solve this issue")) { // Initialize tools and completion system - const explore = new ExploreDir(); + const explore = new ExploreDir(context); try { // First clone the repository diff --git a/src/tools/create-pr/index.ts b/src/tools/create-pr/index.ts index e5a8d961..bb0bb9e1 100644 --- a/src/tools/create-pr/index.ts +++ b/src/tools/create-pr/index.ts @@ -61,10 +61,13 @@ export class CreatePr implements Tool { this._context.logger.info("Committing changes"); await this._terminal.runCommand(`git commit -m "${title}"`); - // Push to remote + // Push to remote using token const currentBranch = (await this._terminal.runCommand("git rev-parse --abbrev-ref HEAD")).trim(); this._context.logger.info(`Pushing branch ${currentBranch} to remote`); - await this._terminal.runCommand(`git push origin ${currentBranch}`); + const token = this._context.env.PERSONAL_AGENT_PAT_CLASSIC; + const repo = this._context.payload.repository.name; + const owner = this._context.payload.repository.owner.login; + await this._terminal.runCommand(`git push https://x-access-token:${token}@github.com/${owner}/${repo}.git ${currentBranch}`); } catch (error) { console.log("Error:", error); const gitError = error instanceof Error ? error : new Error(String(error)); diff --git a/src/tools/explore-dir/index.ts b/src/tools/explore-dir/index.ts index f6cc9c83..003a7407 100644 --- a/src/tools/explore-dir/index.ts +++ b/src/tools/explore-dir/index.ts @@ -1,5 +1,6 @@ import { Terminal } from "../terminal"; import { Tool, ToolResult, DirectoryExploreResult, FunctionParameters } from "../../types/tool"; +import { Context } from "../../types/context"; export class ExploreDir implements Tool { readonly name = "exploreDir"; @@ -35,8 +36,10 @@ export class ExploreDir implements Tool { private _shellInterface: Terminal; private _currentDir: string; private _tempDir: string | null = null; + private _context: Context; - constructor(workDir: string = "") { + constructor(context: Context, workDir: string = "") { + this._context = context; this._shellInterface = new Terminal(); this._currentDir = workDir; } @@ -143,7 +146,8 @@ export class ExploreDir implements Tool { private async _cloneRepo(repo: string, owner: string, issueNumber: number): Promise { this._currentDir = await this._makeTempDir(); - const command = `git clone https://github.com/${owner}/${repo}.git ${this._currentDir} && cd ${this._currentDir} && git checkout -b issue-${issueNumber}`; + const token = this._context.env.PERSONAL_AGENT_PAT_CLASSIC; + const command = `git clone https://x-access-token:${token}@github.com/${owner}/${repo}.git ${this._currentDir} && cd ${this._currentDir} && git checkout -b issue-${issueNumber}`; await this._shellInterface.runCommand(command); } }