From 5157064bf01be804ee2bddcd0a8b03522442ce45 Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 20 Mar 2026 19:01:56 +0000 Subject: [PATCH] fix: action-agent.sh fetches comments without bot filtering (#243) Resolve the bot username dynamically from CODEBERG_TOKEN via the /user API endpoint and filter out bot comments from the prior-context section. Additional bot accounts can be specified via CODEBERG_BOT_USERNAMES env var (comma-separated). Co-Authored-By: Claude Opus 4.6 (1M context) --- .env.example | 4 ++++ action/action-agent.sh | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index d770d2b..98940f9 100644 --- a/.env.example +++ b/.env.example @@ -18,6 +18,10 @@ CODEBERG_TOKEN= # Branch protection: this account must be in the approvals whitelist. REVIEW_BOT_TOKEN= +# Comma-separated Codeberg usernames to filter from issue comments. +# The token owner is auto-detected; add extra bot accounts here if needed. +CODEBERG_BOT_USERNAMES= + # ── Woodpecker CI ───────────────────────────────────────────────────────── WOODPECKER_TOKEN= WOODPECKER_SERVER=http://localhost:8000 diff --git a/action/action-agent.sh b/action/action-agent.sh index 80fe835..a838d30 100644 --- a/action/action-agent.sh +++ b/action/action-agent.sh @@ -126,14 +126,27 @@ if [ -n "$YAML_MODEL" ]; then log "model from front matter: ${YAML_MODEL}" fi -# --- Fetch existing comments (resume context) --- +# --- Resolve bot username(s) for comment filtering --- +_bot_login=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ + "${CODEBERG_API%%/repos*}/user" | jq -r '.login // empty' 2>/dev/null || true) + +# Build list: token owner + any extra names from CODEBERG_BOT_USERNAMES (comma-separated) +_bot_logins="${_bot_login}" +if [ -n "${CODEBERG_BOT_USERNAMES:-}" ]; then + _bot_logins="${_bot_logins:+${_bot_logins},}${CODEBERG_BOT_USERNAMES}" +fi + +# --- Fetch existing comments (resume context, excluding bot comments) --- COMMENTS_JSON=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ "${CODEBERG_API}/issues/${ISSUE}/comments?limit=50") || true PRIOR_COMMENTS="" if [ -n "$COMMENTS_JSON" ] && [ "$COMMENTS_JSON" != "null" ] && [ "$COMMENTS_JSON" != "[]" ]; then PRIOR_COMMENTS=$(printf '%s' "$COMMENTS_JSON" | \ - jq -r '.[] | "[\(.user.login) at \(.created_at[:19])]\n\(.body)\n---"' 2>/dev/null || true) + jq -r --arg bots "$_bot_logins" \ + '($bots | split(",") | map(select(. != ""))) as $bl | + .[] | select(.user.login as $u | $bl | index($u) | not) | + "[\(.user.login) at \(.created_at[:19])]\n\(.body)\n---"' 2>/dev/null || true) fi # --- Create Matrix thread for this issue ---