diff --git a/.claude/scripts/pr-feedback.sh b/.claude/scripts/pr-feedback.sh new file mode 100644 index 0000000..36ead53 --- /dev/null +++ b/.claude/scripts/pr-feedback.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# pr-feedback.sh — print open, bot-authored PRs that have UNADDRESSED "changes +# requested" feedback, so the notification cron can dispatch an implementer per PR +# to address it. Prints one TSV line per PR needing action: +# \t\t\t +# +# A PR is listed when its latest CHANGES_REQUESTED review is NEWER than the bot's +# last "" marker comment (so already-handled feedback is +# not re-dispatched even though GitHub keeps reviewDecision=CHANGES_REQUESTED until +# you re-review), AND it is not currently labeled `claude-addressing` (a guard so +# overlapping firings don't double-dispatch). The implementer posts the marker +# comment after pushing its fix, which advances the cursor past the request. +# +# Repo derived from the git remote; override with $1. Bot login via $BOT_LOGIN. +# Invoke as `bash .claude/scripts/pr-feedback.sh` (pre-approve that exact command). +set -euo pipefail + +repo="${1:-$(gh repo view --json nameWithOwner -q .nameWithOwner)}" +bot="${BOT_LOGIN:-robercano-ghbot}" +marker="" + +gh pr list -R "$repo" --state open \ + --json number,headRefName,author,labels \ + --jq '.[] | select(.author.login=="'"$bot"'") | [.number, .headRefName, ([.labels[].name]|join(","))] | @tsv' \ +| while IFS=$'\t' read -r num branch labels; do + case ",$labels," in *,claude-addressing,*) continue;; esac + + cr=$(gh api "repos/$repo/pulls/$num/reviews" \ + --jq '[.[]|select(.state=="CHANGES_REQUESTED")]|sort_by(.submitted_at)|last|select(.!=null)|"\(.submitted_at)\t\(.user.login)"' \ + 2>/dev/null || true) + if [ -z "$cr" ]; then continue; fi + tcr="${cr%%$'\t'*}" + reviewer="${cr#*$'\t'}" + + ta=$(gh api "repos/$repo/issues/$num/comments" \ + --jq '[.[]|select(.user.login=="'"$bot"'" and (.body|contains("'"$marker"'")))]|sort_by(.created_at)|last|.created_at // empty' \ + 2>/dev/null || true) + + if [ -z "$ta" ] || [[ "$tcr" > "$ta" ]]; then + printf '%s\t%s\t%s\t%s\n' "$num" "$branch" "$reviewer" "$tcr" + fi + done diff --git a/.claude/settings.json b/.claude/settings.json index dbf5483..b72447a 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -30,6 +30,8 @@ "Read(//**)", "Bash(bash .claude/scripts/gate.sh:*)", + "Bash(bash .claude/scripts/notify-poll.sh:*)", + "Bash(bash .claude/scripts/pr-feedback.sh:*)", "Bash(git status:*)", "Bash(git diff:*)",