diff --git a/.github/workflows/review-reusable.yml b/.github/workflows/review-reusable.yml index 746bd47..cc547e5 100644 --- a/.github/workflows/review-reusable.yml +++ b/.github/workflows/review-reusable.yml @@ -213,7 +213,7 @@ jobs: repository: ${{ inputs.repository_owner }}/${{ inputs.repository_name }} ref: refs/pull/${{ inputs.pull_number }}/head path: pr-worktree - fetch-depth: 1 + fetch-depth: 0 persist-credentials: false - uses: actions/setup-node@v4 with: diff --git a/src/logger.ts b/src/logger.ts index d1f55fc..72773bf 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -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]" + } }); diff --git a/src/review/conflictResolver.ts b/src/review/conflictResolver.ts index 21143db..49f26a7 100644 --- a/src/review/conflictResolver.ts +++ b/src/review/conflictResolver.ts @@ -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) diff --git a/src/review/processor.ts b/src/review/processor.ts index 9669696..b72e73b 100644 --- a/src/review/processor.ts +++ b/src/review/processor.ts @@ -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) ); } } diff --git a/test/conflict-resolver.test.ts b/test/conflict-resolver.test.ts index d40736f..c6cbbcd 100644 --- a/test/conflict-resolver.test.ts +++ b/test/conflict-resolver.test.ts @@ -3,6 +3,7 @@ import test from "node:test"; import { buildConflictPushArgs, canAutoResolveConflicts, + describeConflictResolutionFailure, diffSnapshotInventories } from "../src/review/conflictResolver.js"; @@ -32,6 +33,25 @@ test("only a passing conflicted writable current head is eligible", () => { assert.equal(canAutoResolveConflicts({ ...eligible, enabled: false }), false); }); +test("conflict failures are actionable without exposing raw command output", () => { + assert.match( + describeConflictResolutionFailure(new Error("fatal: refusing to merge unrelated histories")), + /did not contain enough Git history/ + ); + assert.match( + describeConflictResolutionFailure(new Error("remote: Write access to repository not granted")), + /Allow edits from maintainers/ + ); + assert.match( + describeConflictResolutionFailure(new Error("rejected: stale info")), + /Run \/conflict again/ + ); + assert.doesNotMatch( + describeConflictResolutionFailure(new Error("secret-token-value")), + /secret-token-value/ + ); +}); + test("external fork conflict pushes use a head-SHA force lease", () => { assert.deepEqual(buildConflictPushArgs({ baseRepository: "forumlify/public", diff --git a/test/workflow-security.test.ts b/test/workflow-security.test.ts index 63d706e..de2a757 100644 --- a/test/workflow-security.test.ts +++ b/test/workflow-security.test.ts @@ -7,6 +7,7 @@ test("conflict repair checks out fork heads without persisting GitHub credential const caller = await fs.readFile(".github/workflows/review.yml", "utf8"); assert.match(workflow, /inputs\.auto_resolve_conflicts == 'true'/); assert.doesNotMatch(workflow, /pull_head_repository == format\('\{0\}\/\{1\}'/); + assert.match(workflow, /fetch-depth:\s*0/); assert.doesNotMatch(workflow, /allow-unsafe-pr-checkout:\s*true/); assert.match(workflow, /GHBOT_GOOSE_BINARY:\s*\$\{\{ runner\.temp \}\}\/goose\/bin\/goose/); assert.match(caller, /pull_head_repository:\s*\$\{\{ github\.event\.pull_request\.head\.repo\.full_name \|\| '' \}\}/);