mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-06 01:52:12 +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(
|
export async function initializeState(
|
||||||
state: ReviewerGraphState,
|
state: ReviewerGraphState,
|
||||||
config: GraphConfig,
|
config: GraphConfig,
|
||||||
|
|
@ -88,19 +114,11 @@ export async function initializeState(
|
||||||
|
|
||||||
let baseBranchName = state.targetRepository.branch;
|
let baseBranchName = state.targetRepository.branch;
|
||||||
if (!baseBranchName) {
|
if (!baseBranchName) {
|
||||||
const baseBranchNameRes = await sandbox.process.executeCommand(
|
baseBranchName = await getBaseBranchName(sandbox, repoRoot);
|
||||||
"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();
|
|
||||||
}
|
}
|
||||||
|
const changedFiles = baseBranchName
|
||||||
const changedFiles = await getChangedFiles(sandbox, baseBranchName, repoRoot);
|
? await getChangedFiles(sandbox, baseBranchName, repoRoot)
|
||||||
|
: "";
|
||||||
|
|
||||||
logger.info("Finished getting state for reviewer");
|
logger.info("Finished getting state for reviewer");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue