fix: prepare complete history for conflict repair

This commit is contained in:
lezi-fun committed 2026-08-14 11:57:41 +08:00
1 parent 0e914c6bc6
commit c2f39d452b
6 files changed
+78 -8

No files matched your search

+5 -1
View File
@@ -2,5 +2,9 @@ import pino from "pino";
import { config } from "./config.js";
export const logger = pino({
level: config.logLevel
level: config.logLevel,
redact: {
paths: ["gitToken", "*.gitToken", "GHBOT_GIT_TOKEN", "*.GHBOT_GIT_TOKEN"],
censor: "[REDACTED]"
}
});
+27
View File
@@ -305,6 +305,33 @@ export function buildConflictPushArgs(params: {
];
}
export function describeConflictResolutionFailure(error: unknown): string {
const message = error instanceof Error ? error.message.toLowerCase() : "";
if (message.includes("refusing to merge unrelated histories") || message.includes("shallow")) {
return "Conflict repair could not prepare the merge because the PR checkout did not contain enough Git history. No commit was pushed.";
}
if (
message.includes("write access to repository not granted") ||
message.includes("permission denied") ||
message.includes("authentication failed") ||
message.includes("status code: 403")
) {
return "GitHub rejected the conflict-resolution push to the contributor fork. Confirm that ‘Allow edits from maintainers’ is still enabled and that the GitHub App can write through that permission. No commit was pushed.";
}
if (
message.includes("force-with-lease") ||
message.includes("stale info") ||
message.includes("fetch first") ||
message.includes("non-fast-forward")
) {
return "The contributor branch changed before the resolved commit could be pushed, so the safe force lease rejected the update. Run /conflict again on the latest head. No commit was pushed.";
}
if (message.includes("final goose confirmation rejected") || message.includes("validation command")) {
return "goose produced a candidate resolution, but the configured validation or final safety confirmation rejected it. No commit was pushed.";
}
return "goose could not safely complete and validate the conflict resolution. The Actions log contains the exact failure stage, and no commit was pushed.";
}
function isSafeGitHubRepository(value: string): boolean {
return value.split("/").length === 2 && value.split("/").every((part) => (
part !== "." && part !== ".." && /^[A-Za-z0-9_.-]+$/.test(part)
+24 -6
View File
@@ -23,7 +23,11 @@ import {
} from "./policy.js";
import { compactFilesForReview } from "./prompt.js";
import { loadRepositoryKnowledge } from "../repository/knowledge.js";
import { canAutoResolveConflicts, resolvePullRequestConflicts } from "./conflictResolver.js";
import {
canAutoResolveConflicts,
describeConflictResolutionFailure,
resolvePullRequestConflicts
} from "./conflictResolver.js";
const reviewer = new GooseReviewer();
const CHECK_RUN_NAME = "ghbot review";
@@ -210,13 +214,13 @@ export async function processPullRequest(
return;
}
} catch (error) {
logger.error({ error, owner, repo, pullNumber }, "Automatic conflict resolution failed safely.");
logger.error({ err: error, owner, repo, pullNumber }, "Automatic conflict resolution failed safely.");
await withRetry("github.issues.createComment.conflictResolutionFailed", async () => {
return octokit.rest.issues.createComment({
owner,
repo,
issue_number: pullNumber,
body: "Automated review passed, but goose could not safely resolve and validate the merge conflicts. No conflict-resolution commit was pushed."
body: `Automated review passed, but ${describeConflictResolutionFailure(error)}`
});
});
return;
@@ -639,7 +643,14 @@ export async function processConflictComment(
});
if (!permission.permission || !new Set(["admin", "maintain", "write"]).has(permission.permission)) {
logger.info(
{ ...params, commentBody: undefined, permission: permission.permission },
{
owner: params.owner,
repo: params.repo,
pullNumber: params.pullNumber,
commentId: params.commentId,
commenterLogin: params.commenterLogin,
permission: permission.permission
},
"Ignoring conflict command because commenter does not have write permission."
);
await postPermissionDeniedComment(octokit, {
@@ -720,11 +731,18 @@ export async function processConflictComment(
: "The PR changed or no resolvable conflict remained before push, so no commit was created."
);
} catch (error) {
logger.error({ error, ...params, commentBody: undefined }, "Manual conflict resolution failed safely.");
logger.error({
err: error,
owner: params.owner,
repo: params.repo,
pullNumber: params.pullNumber,
commentId: params.commentId,
commenterLogin: params.commenterLogin
}, "Manual conflict resolution failed safely.");
await postConflictCommandComment(
octokit,
params,
"goose could not safely resolve and validate the conflicts. No conflict-resolution commit was pushed."
describeConflictResolutionFailure(error)
);
}
}