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:
parent
f4abe63b1b
commit
9fa4846581
4 changed files with 26 additions and 8 deletions
|
|
@ -1244,8 +1244,7 @@ Instructions:
|
||||||
|
|
||||||
REVIEW_SHA=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
REVIEW_SHA=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
||||||
"${API}/pulls/${PR_NUMBER}" | jq -r '.head.sha') || true
|
"${API}/pulls/${PR_NUMBER}" | jq -r '.head.sha') || true
|
||||||
REVIEW_COMMENT=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
REVIEW_COMMENT=$(codeberg_api_all "/issues/${PR_NUMBER}/comments" | \
|
||||||
"${API}/issues/${PR_NUMBER}/comments?limit=50" | \
|
|
||||||
jq -r --arg sha "$REVIEW_SHA" \
|
jq -r --arg sha "$REVIEW_SHA" \
|
||||||
'[.[] | select(.body | contains("<!-- reviewed: " + $sha))] | last // empty') || true
|
'[.[] | select(.body | contains("<!-- reviewed: " + $sha))] | last // empty') || true
|
||||||
|
|
||||||
|
|
|
||||||
22
lib/env.sh
22
lib/env.sh
|
|
@ -56,6 +56,28 @@ codeberg_api() {
|
||||||
"${CODEBERG_API}${path}" "$@"
|
"${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 helper
|
||||||
woodpecker_api() {
|
woodpecker_api() {
|
||||||
local path="$1"
|
local path="$1"
|
||||||
|
|
|
||||||
|
|
@ -112,8 +112,7 @@ inject_review_into_dev_session() {
|
||||||
[ "${current_phase}" = "PHASE:awaiting_review" ] || return 0
|
[ "${current_phase}" = "PHASE:awaiting_review" ] || return 0
|
||||||
|
|
||||||
local review_comment
|
local review_comment
|
||||||
review_comment=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
review_comment=$(codeberg_api_all "/issues/${pr_num}/comments" | \
|
||||||
"${API_BASE}/issues/${pr_num}/comments?limit=50" | \
|
|
||||||
jq -r --arg sha "${pr_sha}" \
|
jq -r --arg sha "${pr_sha}" \
|
||||||
'[.[] | select(.body | contains("<!-- reviewed: " + $sha))] | last // empty') || true
|
'[.[] | select(.body | contains("<!-- reviewed: " + $sha))] | last // empty') || true
|
||||||
if [ -z "${review_comment}" ] || [ "${review_comment}" = "null" ]; then
|
if [ -z "${review_comment}" ] || [ "${review_comment}" = "null" ]; then
|
||||||
|
|
|
||||||
|
|
@ -187,8 +187,7 @@ fi
|
||||||
|
|
||||||
# --- Check for existing reviews ---
|
# --- Check for existing reviews ---
|
||||||
status "checking existing reviews"
|
status "checking existing reviews"
|
||||||
ALL_COMMENTS=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
ALL_COMMENTS=$(codeberg_api_all "/issues/${PR_NUMBER}/comments")
|
||||||
"${API_BASE}/issues/${PR_NUMBER}/comments?limit=50")
|
|
||||||
|
|
||||||
# Check review-comment watermarks — skip if a comment with <!-- reviewed: SHA --> exists
|
# Check review-comment watermarks — skip if a comment with <!-- reviewed: SHA --> exists
|
||||||
COMMENT_REVIEWED=$(echo "$ALL_COMMENTS" | \
|
COMMENT_REVIEWED=$(echo "$ALL_COMMENTS" | \
|
||||||
|
|
@ -797,8 +796,7 @@ if [ "$FOLLOWUP_COUNT" -gt 0 ]; then
|
||||||
FU_DETAILS=$(printf '%s' "$fu" | jq -r '.details')
|
FU_DETAILS=$(printf '%s' "$fu" | jq -r '.details')
|
||||||
|
|
||||||
# Check for duplicate
|
# Check for duplicate
|
||||||
EXISTING=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
EXISTING=$(codeberg_api_all "/issues?state=open&labels=tech-debt" | \
|
||||||
"${API_BASE}/issues?state=open&labels=tech-debt&limit=50" | \
|
|
||||||
jq -r --arg t "$FU_TITLE" '[.[] | select(.title == $t)] | length')
|
jq -r --arg t "$FU_TITLE" '[.[] | select(.title == $t)] | length')
|
||||||
|
|
||||||
if [ "${EXISTING:-0}" -gt 0 ]; then
|
if [ "${EXISTING:-0}" -gt 0 ]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue