Skip to content

Commit

Permalink
fix: git operation fails log
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Jan 11, 2025
1 parent ba2d1dd commit 059713c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/handlers/front-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/tools/create-pr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ export class CreatePr implements Tool<PullRequestResult> {
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));
Expand Down
8 changes: 6 additions & 2 deletions src/tools/explore-dir/index.ts
Original file line number Diff line number Diff line change
@@ -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<DirectoryExploreResult> {
readonly name = "exploreDir";
Expand Down Expand Up @@ -35,8 +36,10 @@ export class ExploreDir implements Tool<DirectoryExploreResult> {
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;
}
Expand Down Expand Up @@ -143,7 +146,8 @@ export class ExploreDir implements Tool<DirectoryExploreResult> {

private async _cloneRepo(repo: string, owner: string, issueNumber: number): Promise<void> {
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);
}
}

0 comments on commit 059713c

Please sign in to comment.