Skip to content

Commit 2969833

Browse files
anvansterclaude
andauthored
fix(pr_context): CI base-ref resolution + workflow stderr visibility
pr_context now resolves the base ref for CI: tries the bare ref first (works locally), falls back to origin/<ref> (works in detached-HEAD PR checkouts). The codegraph-pr workflow passes origin/<base> explicitly and surfaces stderr instead of hiding it behind a silent failure. Validated by dogfooding the action on this PR — posted an accurate review comment (2 files, blast radius, test gaps, reviewer). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a56a0e0 commit 2969833

2 files changed

Lines changed: 51 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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
/// happen in the Rust binary — the JS wrapper handles PostHog ingestion.
1212
///
1313
/// Silently dropped if serialization fails (never blocks the server).
14+
/// The wrapper parses these lines from stderr; stdout stays reserved for
15+
/// the JSON-RPC channel.
1416
fn emit_tel(value: serde_json::Value) {
1517
if let Ok(json) = serde_json::to_string(&value) {
1618
eprintln!("TEL: {json}");
@@ -3339,6 +3341,36 @@ impl McpServer {
33393341
.map(|p| p.to_string_lossy().to_string())
33403342
.unwrap_or_else(|| ".".to_string());
33413343

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+
33423374
// ── Step 1: git diff --name-only for file list ──
33433375
let name_output = tokio::process::Command::new("git")
33443376
.args(["diff", "--name-only", &format!("{}...HEAD", base)])

0 commit comments

Comments
 (0)