fix: ALL_COMMENTS fetch is capped at limit=50 — watermark search may miss reviews on high-comment PRs (#100)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
openhands 2026-03-18 08:13:43 +00:00
parent f4abe63b1b
commit 9fa4846581
4 changed files with 26 additions and 8 deletions

View file

@ -1244,8 +1244,7 @@ Instructions:
REVIEW_SHA=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
"${API}/pulls/${PR_NUMBER}" | jq -r '.head.sha') || true
REVIEW_COMMENT=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
"${API}/issues/${PR_NUMBER}/comments?limit=50" | \
REVIEW_COMMENT=$(codeberg_api_all "/issues/${PR_NUMBER}/comments" | \
jq -r --arg sha "$REVIEW_SHA" \
'[.[] | select(.body | contains("<!-- reviewed: " + $sha))] | last // empty') || true

View file

@ -56,6 +56,28 @@ codeberg_api() {
"${CODEBERG_API}${path}" "$@"
}
# Paginate a Codeberg API GET endpoint and return all items as a merged JSON array.
# Usage: codeberg_api_all /path (no existing query params)
# codeberg_api_all /path?a=b (with existing params — appends &limit=50&page=N)
codeberg_api_all() {
local path_prefix="$1"
local sep page page_items count all_items="[]"
case "$path_prefix" in
*"?"*) sep="&" ;;
*) sep="?" ;;
esac
page=1
while true; do
page_items=$(codeberg_api GET "${path_prefix}${sep}limit=50&page=${page}") || break
count=$(printf '%s' "$page_items" | jq 'length')
[ "$count" -eq 0 ] && break
all_items=$(printf '%s\n%s' "$all_items" "$page_items" | jq -s 'add')
[ "$count" -lt 50 ] && break
page=$((page + 1))
done
printf '%s' "$all_items"
}
# Woodpecker API helper
woodpecker_api() {
local path="$1"

View file

@ -112,8 +112,7 @@ inject_review_into_dev_session() {
[ "${current_phase}" = "PHASE:awaiting_review" ] || return 0
local review_comment
review_comment=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
"${API_BASE}/issues/${pr_num}/comments?limit=50" | \
review_comment=$(codeberg_api_all "/issues/${pr_num}/comments" | \
jq -r --arg sha "${pr_sha}" \
'[.[] | select(.body | contains("<!-- reviewed: " + $sha))] | last // empty') || true
if [ -z "${review_comment}" ] || [ "${review_comment}" = "null" ]; then

View file

@ -187,8 +187,7 @@ fi
# --- Check for existing reviews ---
status "checking existing reviews"
ALL_COMMENTS=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
"${API_BASE}/issues/${PR_NUMBER}/comments?limit=50")
ALL_COMMENTS=$(codeberg_api_all "/issues/${PR_NUMBER}/comments")
# Check review-comment watermarks — skip if a comment with <!-- reviewed: SHA --> exists
COMMENT_REVIEWED=$(echo "$ALL_COMMENTS" | \
@ -797,8 +796,7 @@ if [ "$FOLLOWUP_COUNT" -gt 0 ]; then
FU_DETAILS=$(printf '%s' "$fu" | jq -r '.details')
# Check for duplicate
EXISTING=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
"${API_BASE}/issues?state=open&labels=tech-debt&limit=50" | \
EXISTING=$(codeberg_api_all "/issues?state=open&labels=tech-debt" | \
jq -r --arg t "$FU_TITLE" '[.[] | select(.title == $t)] | length')
if [ "${EXISTING:-0}" -gt 0 ]; then