Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/setkernel/skills/request-review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ description: Ask two agent seats to review a person's pull request - request the
`sh "${CLAUDE_PLUGIN_ROOT}/skills/request-review/request-review.sh" <owner>/<repo> <n>`
3. Report its output as it is: on exit 0, the seats requested and the PR URL; on exit 1, the
reason, and who was asked and who failed.
After a push that answers a change request, run it again: it first asks again every seat whose
change request stands on an older commit, then fills up to two seats as before.
4. Don't work around a refusal: no `gh pr edit --add-reviewer`, no label by hand, no retry with
other logins. Never approve, merge or comment on the PR, and never edit its body.
52 changes: 38 additions & 14 deletions plugins/setkernel/skills/request-review/request-review.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# member other than Raghav or the author who is a requested reviewer. With two seats on the PR the
# label goes on and it exits 0; a re-run asks nobody new. Fewer than two after every candidate: no
# label, exit 1. It never approves, merges, comments or edits the PR body. POSIX sh, gh and jq only.
#
# Run it again after a push (#82): a seat whose change request stands on an older commit is asked
# again first, since the gate holds the PR until that seat reviews the new head. GitHub's
# latestOpinionatedReviews says whose change request stands (a later comment doesn't lift it).
set -u
org=setkernel
team=seats
Expand Down Expand Up @@ -66,9 +70,41 @@ now=$(requested) || die "cannot read the requested reviewers of $url"
have=$(seats "$now")

asked='' failed=''
# ask <login>: one REST call; a login GitHub dropped is asked once more. Updates now, have, asked, failed.
ask() {
asked="$asked $1"
ok=
for try in 1 2; do
if ! gh api -X POST "repos/$repo/pulls/$num/requested_reviewers" -f "reviewers[]=$1" >/dev/null; then
echo "request-review: GitHub refused $1; trying the next candidate." >&2
break
fi
now=$(requested) || die "cannot read the requested reviewers of $url"
printf '%s\n' "$now" | grep -Fqx -e "$1" && { ok=1; break; }
[ "$try" = 1 ] && echo "request-review: $1 was dropped; asking once more." >&2
done
[ -n "$ok" ] || failed="$failed $1"
have=$(seats "$now")
}

# Seats whose change request stands on an older commit than the head: ask them again first.
stale=$(gh api graphql -F num="$num" -f owner="${repo%/*}" -f name="${repo#*/}" -f query='
query($owner: String!, $name: String!, $num: Int!) { repository(owner: $owner, name: $name) {
pullRequest(number: $num) { headRefOid latestOpinionatedReviews(first: 100) {
nodes { state author { login } commit { oid } } } } } }' \
--jq '.data.repository.pullRequest | .headRefOid as $h | .latestOpinionatedReviews.nodes[]
| select(.state == "CHANGES_REQUESTED" and .author != null and .commit.oid != $h) | .author.login') ||
die "cannot read whose change request stands on $url"
for login in $(seats "$stale"); do
[ "$login" = "$me" ] && continue
printf '%s\n' "$now" | grep -Fqx -e "$login" && continue
echo "request-review: asking $login again: their change request stands on an older commit." >&2
ask "$login"
done

if [ "$(count "$have")" -lt "$want" ]; then
# Least busy first, random among ties; a load the search can't count goes last.
printf '%s\n%s\n' "$me" "$have" | grep . >"$tmpd/skip"
printf '%s\n%s\n%s\n' "$me" "$have" "$stale" | grep . >"$tmpd/skip"
order=$(grep -Fvx -f "$tmpd/skip" "$tmpd/pool" |
while read -r login; do
load=$(gh api -X GET search/issues --jq .total_count \
Expand All @@ -77,19 +113,7 @@ if [ "$(count "$have")" -lt "$want" ]; then
done | awk 'BEGIN { srand() } { print $1, rand(), $2 }' | sort -k1,1n -k2,2n | cut -d' ' -f3)
for login in $order; do
[ "$(count "$have")" -ge "$want" ] && break
asked="$asked $login"
ok=
for try in 1 2; do
if ! gh api -X POST "repos/$repo/pulls/$num/requested_reviewers" -f "reviewers[]=$login" >/dev/null; then
echo "request-review: GitHub refused $login; trying the next candidate." >&2
break
fi
now=$(requested) || die "cannot read the requested reviewers of $url"
printf '%s\n' "$now" | grep -Fqx -e "$login" && { ok=1; break; }
[ "$try" = 1 ] && echo "request-review: $login was dropped; asking once more." >&2
done
[ -n "$ok" ] || failed="$failed $login"
have=$(seats "$now")
ask "$login"
done
fi

Expand Down
9 changes: 8 additions & 1 deletion plugins/setkernel/skills/ship-pr/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ description: Take the current work to a reviewable pull request the setkernel wa
5. Open the PR with `gh pr create`: **What**, **Why**, **How verified** (the verify table),
**Needs owner** (anything only Raghav can do). Link the issue: `Closes setkernel/<repo>#N`.
End with your signature line if Who did it gives you one.
6. Watch CI (`gh pr checks --watch`); fix failures you caused. Do not merge.
6. Once the PR is open and its checks are running, ask two seats to review it: run
`sh "${CLAUDE_PLUGIN_ROOT}/skills/request-review/request-review.sh" <owner>/<repo> <n>` and
report its output (who was asked, or why it stopped), as the `request-review` skill says.
Inside an sk-agent run it refuses, since sk-agent asks its own peers: say so and go on.
7. Watch CI (`gh pr checks --watch`); fix failures you caused. Do not merge.
8. After each push that answers a change request, run the same script again and report its output:
it asks again every seat whose change request stands on an older commit, since the gate holds
the PR until that seat reviews the new head.
16 changes: 16 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ case "\$*" in
printf '%s\n' zz-author zz-me realRaghavGupta zz-a zz-b zz-c ;;
"api repos/example/app/pulls/1") cat "$rs/pr.json" ;;
"api repos/example/app/pulls/1/requested_reviewers --jq .users[].login") cat "$rs/requested" ;;
"api graphql "*) cat "$rs/stale" 2>/dev/null; [ ! -f "$rs/nostale" ] || { echo "gh: Something went wrong (HTTP 502)" >&2; exit 1; } ;;
*" search/issues "*) l=\${*##*review-requested:}; l=\${l%% *}; cat "$rs/load-\$l" 2>/dev/null || echo 0 ;;
*"POST repos/example/app/pulls/1/requested_reviewers -f reviewers[]="*)
l=\${*##*=}
Expand Down Expand Up @@ -1026,6 +1027,21 @@ expect 1 "only 1 of 2 seats on https://github.com/example/app/pull/1; no agent-r
"with fewer than two seats it exits 1 and says who was asked and who failed" -- rr_run
expect 0 "^0$" "and adds no label" -- posts issues/1/labels

# After a push (#82): a seat whose change request stands on an older commit is asked again first.
rr_pr open false '' && echo zz-a >"$rs/stale"
expect 0 "asking zz-a again: their change request stands on an older commit" \
"a re-run after a push asks a seat with a standing change request again" -- rr_run
expect 0 "^zz-a zz-b $" "first, then the least busy other seat" -- sh -c "tr '\n' ' ' <'$rs/requested'"
rr_pr open false '' && printf '%s\n' zz-a zz-c >"$rs/stale"
expect 0 "^Review requested from zz-a zz-c on" "two standing change requests: both are asked again" -- rr_run
expect 0 "^2$" "and nobody new" -- posts pulls/1/requested_reviewers
rr_pr open false '' && printf '%s\n' zz-me zz-author realRaghavGupta >"$rs/stale"
expect 0 "^Review requested from zz-b zz-c on" "the caller, the author and Raghav are not asked again" -- rr_run
rr_pr open false '' && : >"$rs/nostale"
expect 1 "cannot read whose change request stands on https://github.com/example/app/pull/1" \
"a failed read of the reviews stops it before asking anyone" -- rr_run
expect 0 "^0$" "and posts nothing" -- posts ''

# The suite passes with SETKERNEL_GUARD_NO_PUSH=1 in its environment (as in sk-agent runs). One nested run, not recursive.
if [ -z "${SETKERNEL_TESTS_NESTED:-}" ]; then
expect 0 "passed" "the suite passes with SETKERNEL_GUARD_NO_PUSH=1 inherited" -- env SETKERNEL_TESTS_NESTED=1 SETKERNEL_GUARD_NO_PUSH=1 $sh_cmd "$root/tests/run.sh"
Expand Down
Loading