Skip to content

Commit 66bdc83

Browse files
anvansterclaude
andcommitted
fix(pr_context): resolve base ref in CI (origin/ fallback) + workflow
The dogfood Action failed: in a PR checkout the base branch exists only as a remote-tracking ref (origin/main), not a local branch, so `git diff main...HEAD` errored with "unknown revision". Two fixes: 1. pr_context now resolves the base ref — tries the bare ref first (works locally), falls back to origin/<ref> (works in CI). Users can pass plain "main" anywhere. 2. Workflow passes origin/<base> explicitly so it works with the already-published 0.17.5 binary (which lacks the auto-resolution), and no longer hides stderr — failures now show in the Actions log with a ::warning:: annotation instead of a silent "review failed". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4c13546 commit 66bdc83

2 files changed

Lines changed: 49 additions & 6 deletions

File tree

.github/workflows/codegraph-pr.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,25 @@ jobs:
3535
run: |
3636
# Resolve the npm-installed binary for this platform
3737
BIN="$(npm root -g)/@astudioplus/codegraph-mcp/bin/codegraph-server-linux-x64"
38-
chmod +x "$BIN"
39-
"$BIN" \
40-
--graph-only \
41-
--run-tool codegraph_pr_context \
42-
--tool-args "{\"baseBranch\":\"${{ github.base_ref }}\",\"format\":\"markdown\"}" \
43-
> review.md 2>/dev/null || echo "CodeGraph review failed" > review.md
38+
# stderr → log (visible in the Actions run); stdout → comment body
39+
# Use origin/<base> — in a PR checkout the base branch exists as
40+
# a remote-tracking ref, not a local branch. (codegraph 0.17.6+
41+
# auto-resolves this, but origin/ works on all versions.)
42+
if "$BIN" \
43+
--graph-only \
44+
--run-tool codegraph_pr_context \
45+
--tool-args "{\"baseBranch\":\"origin/${{ github.base_ref }}\",\"format\":\"markdown\"}" \
46+
> review.md 2> review.err; then
47+
echo "CodeGraph review succeeded"
48+
else
49+
echo "::warning::CodeGraph review failed — see stderr below"
50+
cat review.err
51+
{
52+
echo "## 🔍 CodeGraph PR Review"
53+
echo ""
54+
echo "Review could not be generated for this PR. <sub>(CodeGraph)</sub>"
55+
} > review.md
56+
fi
4457
4558
- name: Post or update PR comment
4659
uses: actions/github-script@v7

crates/codegraph-server/src/mcp/server.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3341,6 +3341,36 @@ impl McpServer {
33413341
.map(|p| p.to_string_lossy().to_string())
33423342
.unwrap_or_else(|| ".".to_string());
33433343

3344+
// Resolve the base ref. In CI (GitHub Actions etc.) the
3345+
// checkout is a detached HEAD and the base branch only
3346+
// exists as a remote-tracking ref (origin/main), not a
3347+
// local branch. Try the bare ref first (works locally),
3348+
// then fall back to origin/<ref> (works in CI).
3349+
let base = {
3350+
let probe = tokio::process::Command::new("git")
3351+
.args(["rev-parse", "--verify", "--quiet", base])
3352+
.current_dir(&workspace_root)
3353+
.output()
3354+
.await;
3355+
let bare_ok = probe.map(|o| o.status.success()).unwrap_or(false);
3356+
if bare_ok {
3357+
base.to_string()
3358+
} else {
3359+
let remote = format!("origin/{}", base);
3360+
let probe2 = tokio::process::Command::new("git")
3361+
.args(["rev-parse", "--verify", "--quiet", &remote])
3362+
.current_dir(&workspace_root)
3363+
.output()
3364+
.await;
3365+
if probe2.map(|o| o.status.success()).unwrap_or(false) {
3366+
remote
3367+
} else {
3368+
base.to_string() // let the diff surface the error
3369+
}
3370+
}
3371+
};
3372+
let base = base.as_str();
3373+
33443374
// ── Step 1: git diff --name-only for file list ──
33453375
let name_output = tokio::process::Command::new("git")
33463376
.args(["diff", "--name-only", &format!("{}...HEAD", base)])

0 commit comments

Comments
 (0)