Skip to content

Commit f7187af

Browse files
✨ Improve waiting message logic with dots for each check
- Introduced a flag to manage the printing of the waiting message for checks. - Updated the logic to print a single line message while waiting and ensure a newline is printed when checks are found. - Improved user experience by reducing clutter in the output during the waiting period.
1 parent 803e99f commit f7187af

File tree

2 files changed

+176
-2
lines changed

2 files changed

+176
-2
lines changed

continuous_claude.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ wait_for_pr_checks() {
781781
local prev_failed_count=""
782782
local prev_review_status=""
783783
local prev_no_checks_configured=""
784+
local waiting_message_printed=false
784785

785786
while [ $iteration -lt $max_iterations ]; do
786787
local checks_json
@@ -889,17 +890,27 @@ wait_for_pr_checks() {
889890

890891
if [ "$check_count" -eq 0 ] && [ "$checks_json" != "" ] && [ "$checks_json" != "[]" ] && [ "$no_checks_configured" = "false" ]; then
891892
if [ "$iteration" -lt 18 ]; then
892-
if [ "$state_changed" = "true" ]; then
893-
echo "⏳ Waiting for checks to start... (will timeout after 3 minutes)" >&2
893+
if [ "$waiting_message_printed" = "false" ]; then
894+
echo -n "⏳ Waiting for checks to start... (will timeout after 3 minutes) " >&2
895+
waiting_message_printed=true
894896
fi
897+
echo -n "." >&2
895898
sleep 10
896899
iteration=$((iteration + 1))
897900
continue
898901
else
902+
echo "" >&2
899903
echo " ⚠️ No checks found after waiting, proceeding without checks" >&2
900904
all_completed=true
901905
all_success=true
902906
fi
907+
else
908+
# If we were waiting and now checks are found, print newline
909+
if [ "$waiting_message_printed" = "true" ]; then
910+
echo "" >&2
911+
fi
912+
# Reset waiting message flag when checks are found
913+
waiting_message_printed=false
903914
fi
904915

905916
if [ "$all_completed" = "true" ] && [ "$all_success" = "true" ] && [ "$reviews_pending" = "false" ]; then

tests/test_continuous_claude.bats

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,3 +1408,166 @@ setup() {
14081408
assert_success
14091409
assert_output --partial "(DRY RUN) PR merged: <commit title would appear here>"
14101410
}
1411+
1412+
@test "wait_for_pr_checks prints initial waiting message once" {
1413+
source "$SCRIPT_PATH"
1414+
1415+
# Mock gh to return empty checks array (waiting for checks to start)
1416+
function gh() {
1417+
if [ "$1" = "pr" ] && [ "$2" = "checks" ]; then
1418+
echo "[]"
1419+
return 0
1420+
elif [ "$1" = "pr" ] && [ "$2" = "view" ]; then
1421+
echo '{"reviewDecision": null, "reviewRequests": []}'
1422+
return 0
1423+
fi
1424+
return 1
1425+
}
1426+
1427+
# Mock sleep to avoid actual waiting
1428+
function sleep() {
1429+
return 0
1430+
}
1431+
1432+
export -f gh sleep
1433+
1434+
# Run with a short timeout to capture initial output
1435+
run timeout 1 bash -c "
1436+
source '$SCRIPT_PATH'
1437+
wait_for_pr_checks 123 'owner' 'repo' '(1/1)' 2>&1
1438+
" || true
1439+
1440+
# Should contain the initial waiting message
1441+
assert_output --partial "⏳ Waiting for checks to start"
1442+
# Should contain at least one dot
1443+
assert_output --partial "."
1444+
}
1445+
1446+
@test "wait_for_pr_checks prints dots on each waiting iteration" {
1447+
source "$SCRIPT_PATH"
1448+
1449+
# Use a counter that persists across function calls
1450+
echo "0" > "$BATS_TEST_TMPDIR/gh_call_count"
1451+
1452+
# Mock gh to return empty checks for first few calls, then checks appear
1453+
function gh() {
1454+
if [ "$1" = "pr" ] && [ "$2" = "checks" ]; then
1455+
local count=$(cat "$BATS_TEST_TMPDIR/gh_call_count")
1456+
count=$((count + 1))
1457+
echo "$count" > "$BATS_TEST_TMPDIR/gh_call_count"
1458+
1459+
if [ $count -lt 3 ]; then
1460+
echo "[]"
1461+
else
1462+
# Return checks after 3 iterations
1463+
echo '[{"state": "completed", "bucket": "success"}]'
1464+
fi
1465+
return 0
1466+
elif [ "$1" = "pr" ] && [ "$2" = "view" ]; then
1467+
echo '{"reviewDecision": "APPROVED", "reviewRequests": []}'
1468+
return 0
1469+
fi
1470+
return 1
1471+
}
1472+
1473+
# Mock sleep to avoid actual waiting
1474+
function sleep() {
1475+
return 0
1476+
}
1477+
1478+
export -f gh sleep
1479+
1480+
# Capture stderr output
1481+
run bash -c "
1482+
source '$SCRIPT_PATH'
1483+
wait_for_pr_checks 123 'owner' 'repo' '(1/1)' 2>&1
1484+
"
1485+
1486+
# Should contain multiple dots (at least 2)
1487+
local dot_count=$(echo "$output" | grep -o '\.' | wc -l | tr -d ' ')
1488+
assert [ "$dot_count" -ge 2 ]
1489+
1490+
rm -f "$BATS_TEST_TMPDIR/gh_call_count"
1491+
}
1492+
1493+
@test "wait_for_pr_checks prints newline when checks are found after waiting" {
1494+
source "$SCRIPT_PATH"
1495+
1496+
# Use a counter that persists across function calls
1497+
echo "0" > "$BATS_TEST_TMPDIR/gh_call_count"
1498+
1499+
# Mock gh to return empty checks first, then checks appear
1500+
function gh() {
1501+
if [ "$1" = "pr" ] && [ "$2" = "checks" ]; then
1502+
local count=$(cat "$BATS_TEST_TMPDIR/gh_call_count")
1503+
count=$((count + 1))
1504+
echo "$count" > "$BATS_TEST_TMPDIR/gh_call_count"
1505+
1506+
if [ $count -le 2 ]; then
1507+
echo "[]"
1508+
else
1509+
# Return checks after 2 iterations
1510+
echo '[{"state": "completed", "bucket": "success"}]'
1511+
fi
1512+
return 0
1513+
elif [ "$1" = "pr" ] && [ "$2" = "view" ]; then
1514+
echo '{"reviewDecision": "APPROVED", "reviewRequests": []}'
1515+
return 0
1516+
fi
1517+
return 1
1518+
}
1519+
1520+
# Mock sleep to avoid actual waiting
1521+
function sleep() {
1522+
return 0
1523+
}
1524+
1525+
export -f gh sleep
1526+
1527+
# Capture stderr output
1528+
run bash -c "
1529+
source '$SCRIPT_PATH'
1530+
wait_for_pr_checks 123 'owner' 'repo' '(1/1)' 2>&1
1531+
"
1532+
1533+
# Should contain the waiting message followed by dots
1534+
assert_output --partial "⏳ Waiting for checks to start"
1535+
# Should eventually show check status (indicating newline was printed)
1536+
assert_output --partial "Found"
1537+
1538+
rm -f "$BATS_TEST_TMPDIR/gh_call_count"
1539+
}
1540+
1541+
@test "wait_for_pr_checks does not print waiting message when checks found immediately" {
1542+
source "$SCRIPT_PATH"
1543+
1544+
# Mock gh to return checks immediately (no waiting)
1545+
function gh() {
1546+
if [ "$1" = "pr" ] && [ "$2" = "checks" ]; then
1547+
echo '[{"state": "completed", "bucket": "success"}]'
1548+
return 0
1549+
elif [ "$1" = "pr" ] && [ "$2" = "view" ]; then
1550+
echo '{"reviewDecision": "APPROVED", "reviewRequests": []}'
1551+
return 0
1552+
fi
1553+
return 1
1554+
}
1555+
1556+
# Mock sleep to avoid actual waiting
1557+
function sleep() {
1558+
return 0
1559+
}
1560+
1561+
export -f gh sleep
1562+
1563+
# Capture stderr output
1564+
run bash -c "
1565+
source '$SCRIPT_PATH'
1566+
wait_for_pr_checks 123 'owner' 'repo' '(1/1)' 2>&1
1567+
"
1568+
1569+
# Should NOT contain waiting message when checks are found immediately
1570+
refute_output --partial "⏳ Waiting for checks to start"
1571+
# Should show check status instead
1572+
assert_output --partial "Found"
1573+
}

0 commit comments

Comments
 (0)