mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 20:53:15 +00:00
feat: If session id exists, pull latest changes on branch (#57)
This commit is contained in:
parent
525dc1156b
commit
b0eff07d22
2 changed files with 33 additions and 9 deletions
|
|
@ -12,6 +12,7 @@ import {
|
|||
configureGitUserInRepo,
|
||||
getBranchName,
|
||||
getRepoAbsolutePath,
|
||||
pullLatestChanges,
|
||||
} from "../utils/git/index.js";
|
||||
import { getSandboxErrorFields } from "../utils/sandbox-error-fields.js";
|
||||
|
||||
|
|
@ -63,6 +64,13 @@ export async function initialize(
|
|||
throw new Error("Configuration object not found.");
|
||||
}
|
||||
const { sandboxSessionId } = state;
|
||||
const { targetRepository } = state;
|
||||
if (!targetRepository) {
|
||||
throw new Error(
|
||||
"Missing required target repository. Please provide a git repository in state or configuration.",
|
||||
);
|
||||
}
|
||||
const absoluteRepoDir = getRepoAbsolutePath(targetRepository);
|
||||
|
||||
if (sandboxSessionId) {
|
||||
try {
|
||||
|
|
@ -74,6 +82,7 @@ export async function initialize(
|
|||
sandboxSessionId,
|
||||
TIMEOUT_EXTENSION_OPT,
|
||||
);
|
||||
await pullLatestChanges(absoluteRepoDir, newSandbox);
|
||||
return {
|
||||
sandboxSessionId: newSandbox.sandboxId,
|
||||
};
|
||||
|
|
@ -83,13 +92,6 @@ export async function initialize(
|
|||
}
|
||||
}
|
||||
|
||||
const { targetRepository } = state;
|
||||
if (!targetRepository) {
|
||||
throw new Error(
|
||||
"Missing required target repository. Please provide a git repository in state or configuration.",
|
||||
);
|
||||
}
|
||||
|
||||
logger.info("Creating sandbox...");
|
||||
const sandbox = await Sandbox.create(
|
||||
SANDBOX_TEMPLATE_ID,
|
||||
|
|
@ -104,8 +106,6 @@ export async function initialize(
|
|||
}
|
||||
logger.info("Repository cloned successfully.");
|
||||
|
||||
const absoluteRepoDir = getRepoAbsolutePath(targetRepository);
|
||||
|
||||
logger.info(`Configuring git user for repository at "${absoluteRepoDir}"...`);
|
||||
await configureGitUserInRepo(absoluteRepoDir, sandbox);
|
||||
logger.info("Git user configured successfully.");
|
||||
|
|
|
|||
|
|
@ -449,3 +449,27 @@ export async function createPullRequest({
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function pullLatestChanges(
|
||||
absoluteRepoDir: string,
|
||||
sandbox: Sandbox,
|
||||
): Promise<CommandResult | false> {
|
||||
try {
|
||||
const gitPullOutput = await sandbox.commands.run("git pull", {
|
||||
cwd: absoluteRepoDir,
|
||||
});
|
||||
await sandbox.setTimeout(TIMEOUT_MS);
|
||||
return gitPullOutput;
|
||||
} catch (e) {
|
||||
const errorFields = getSandboxErrorFields(e);
|
||||
logger.error(`Failed to pull latest changes`, {
|
||||
...(errorFields && { errorFields }),
|
||||
...(e instanceof Error && {
|
||||
name: e.name,
|
||||
message: e.message,
|
||||
stack: e.stack,
|
||||
}),
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue