mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 10:23:14 +00:00
fix: Catch base branch error (#421)
This commit is contained in:
parent
2b1f301848
commit
4053f18df5
1 changed files with 30 additions and 12 deletions
|
|
@ -71,6 +71,32 @@ async function getChangedFiles(
|
|||
}
|
||||
}
|
||||
|
||||
async function getBaseBranchName(
|
||||
sandbox: Sandbox,
|
||||
repoRoot: string,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const baseBranchNameRes = await sandbox.process.executeCommand(
|
||||
"git config init.defaultBranch",
|
||||
repoRoot,
|
||||
);
|
||||
if (baseBranchNameRes.exitCode !== 0) {
|
||||
const errorFields = getSandboxErrorFields(baseBranchNameRes);
|
||||
logger.error("Failed to get base branch name", {
|
||||
...(errorFields ?? baseBranchNameRes),
|
||||
});
|
||||
return "";
|
||||
}
|
||||
return baseBranchNameRes.result.trim();
|
||||
} catch (e) {
|
||||
const errorFields = getSandboxErrorFields(e);
|
||||
logger.error("Failed to get base branch name.", {
|
||||
...(errorFields ? { errorFields } : { e }),
|
||||
});
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export async function initializeState(
|
||||
state: ReviewerGraphState,
|
||||
config: GraphConfig,
|
||||
|
|
@ -88,19 +114,11 @@ export async function initializeState(
|
|||
|
||||
let baseBranchName = state.targetRepository.branch;
|
||||
if (!baseBranchName) {
|
||||
const baseBranchNameRes = await sandbox.process.executeCommand(
|
||||
"git config init.defaultBranch",
|
||||
repoRoot,
|
||||
);
|
||||
if (baseBranchNameRes.exitCode !== 0) {
|
||||
throw new Error(
|
||||
`Failed to get base branch name: ${JSON.stringify(baseBranchNameRes, null, 2)}`,
|
||||
);
|
||||
}
|
||||
baseBranchName = baseBranchNameRes.result.trim();
|
||||
baseBranchName = await getBaseBranchName(sandbox, repoRoot);
|
||||
}
|
||||
|
||||
const changedFiles = await getChangedFiles(sandbox, baseBranchName, repoRoot);
|
||||
const changedFiles = baseBranchName
|
||||
? await getChangedFiles(sandbox, baseBranchName, repoRoot)
|
||||
: "";
|
||||
|
||||
logger.info("Finished getting state for reviewer");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue