fix: make CodeScene pre-push gate informational — remote API lags local changes
The remote CodeScene API only updates after push + re-analysis, creating a chicken-and-egg blocking loop. The local pre_commit_code_health_safeguard already validates code health before commit. Pre-push now reports remote scores for visibility without blocking. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -105,40 +105,27 @@ else
|
||||
fi
|
||||
|
||||
# ── 5. CodeScene code health gate ────────────────────────────────────────
|
||||
# Note: remote API scores lag behind local changes (only updates after push + re-analysis).
|
||||
# We report the remote score for visibility but don't block on it.
|
||||
# The pre-commit hook already runs `pre_commit_code_health_safeguard` locally.
|
||||
echo ""
|
||||
echo "🏥 [5/5] CodeScene code health gate (hotspot ≥9.2, average ≥8.8)..."
|
||||
echo "🏥 [5/5] CodeScene code health (informational — local safeguard runs in pre-commit)..."
|
||||
if [ -z "$CODESCENE_PAT" ] || [ -z "$CODESCENE_PROJECT_ID" ]; then
|
||||
echo " ⚠️ CODESCENE_PAT or CODESCENE_PROJECT_ID not set — skipping"
|
||||
else
|
||||
HOTSPOT_THRESHOLD=9.2
|
||||
AVERAGE_THRESHOLD=8.8
|
||||
API_RESPONSE=$(curl -sf \
|
||||
-H "Authorization: Bearer $CODESCENE_PAT" \
|
||||
-H "Accept: application/json" \
|
||||
"https://api.codescene.io/v2/projects/$CODESCENE_PROJECT_ID")
|
||||
HOTSPOT_SCORE=$(echo "$API_RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['analysis']['hotspot_code_health']['now'])")
|
||||
AVERAGE_SCORE=$(echo "$API_RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['analysis']['code_health']['now'])")
|
||||
echo " Hotspot Code Health: $HOTSPOT_SCORE (threshold: $HOTSPOT_THRESHOLD)"
|
||||
echo " Average Code Health: $AVERAGE_SCORE (threshold: $AVERAGE_THRESHOLD)"
|
||||
python3 -c "
|
||||
hotspot = float('$HOTSPOT_SCORE')
|
||||
average = float('$AVERAGE_SCORE')
|
||||
ht = float('$HOTSPOT_THRESHOLD')
|
||||
at = float('$AVERAGE_THRESHOLD')
|
||||
failed = False
|
||||
if hotspot < ht:
|
||||
print(f' ❌ Hotspot Code Health {hotspot:.2f} below threshold {ht}')
|
||||
failed = True
|
||||
else:
|
||||
print(f' ✅ Hotspot Code Health {hotspot:.2f} ≥ {ht}')
|
||||
if average < at:
|
||||
print(f' ❌ Average Code Health {average:.2f} below threshold {at}')
|
||||
failed = True
|
||||
else:
|
||||
print(f' ✅ Average Code Health {average:.2f} ≥ {at}')
|
||||
if failed:
|
||||
exit(1)
|
||||
"
|
||||
"https://api.codescene.io/v2/projects/$CODESCENE_PROJECT_ID" 2>/dev/null || echo "{}")
|
||||
if echo "$API_RESPONSE" | python3 -c "import sys,json; json.load(sys.stdin)['analysis']" 2>/dev/null; then
|
||||
HOTSPOT_SCORE=$(echo "$API_RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['analysis']['hotspot_code_health']['now'])")
|
||||
AVERAGE_SCORE=$(echo "$API_RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['analysis']['code_health']['now'])")
|
||||
echo " Remote Hotspot Code Health: $HOTSPOT_SCORE"
|
||||
echo " Remote Average Code Health: $AVERAGE_SCORE"
|
||||
echo " (remote scores update after push — local safeguard already passed in pre-commit)"
|
||||
else
|
||||
echo " ⚠️ Could not fetch remote scores — continuing"
|
||||
fi
|
||||
fi
|
||||
|
||||
END_TIME=$(date +%s)
|
||||
|
||||
Reference in New Issue
Block a user