@senior: opscode events are not in the PR #5
+35
-28
@@ -437,41 +437,48 @@ jobs:
|
||||
|
||||
prbody=$(printf '%s\n\n---\nResolves #%s · 🤖 @%s' "$prdesc" "$NUM" "$NAME")
|
||||
owner=${GITHUB_REPOSITORY%%/*}
|
||||
mapfile -t brs < <(git ls-remote --heads origin "ai/issue-$NUM" "ai/issue-$NUM-*" 2>/dev/null \
|
||||
| sed -E 's#.*refs/heads/##' | sort -u)
|
||||
|
||||
links=""; count=0
|
||||
for br in "${brs[@]}"; do
|
||||
[ -z "$br" ] && continue
|
||||
ahead=$(git rev-list --count "origin/main..origin/$br" 2>/dev/null || echo 0)
|
||||
[ "${ahead:-0}" -eq 0 ] && continue
|
||||
# NOTE: Gitea ignores the ?head= filter, so match the head branch client-side.
|
||||
url=$(curl -sS "${hdr[@]}" "$API/pulls?state=open&limit=50" \
|
||||
| jq -r --arg br "$br" 'if type=="array" then (map(select(.head.ref==$br)) | .[0].html_url // empty) else empty end' 2>/dev/null)
|
||||
if [ -z "$url" ]; then
|
||||
slug=${br#ai/issue-$NUM}; slug=${slug#-}
|
||||
[ -z "$slug" ] && title="@$NAME: $TITLE" || title="@$NAME: $slug"
|
||||
resp=$(curl -sS -X POST "${hdr[@]}" "$API/pulls" \
|
||||
-d "$(jq -nc --arg t "$title" --arg h "$br" --arg n "$NUM" --arg b "$prbody" \
|
||||
'{title:$t, head:$h, base:"main", body:$b}')")
|
||||
echo "PR create ($br): $resp"
|
||||
url=$(printf '%s' "$resp" | jq -r '.html_url // empty' 2>/dev/null)
|
||||
fi
|
||||
[ -n "$url" ] && { links="$links\n- $url"; count=$((count+1)); }
|
||||
done
|
||||
|
||||
if [ "$count" -eq 0 ]; then
|
||||
# No branch had changes — a plan / questions / analysis only.
|
||||
# One PR per run: publish ONLY this run's own branch ($BRANCH), never sibling
|
||||
# ai/issue-N-* branches. This removes the multi-PR ambiguity that left the
|
||||
# activity log stranded on the triggering issue instead of the PR thread.
|
||||
br="$BRANCH"
|
||||
ahead=$(git rev-list --count "origin/main..origin/$br" 2>/dev/null || echo 0)
|
||||
if [ "${ahead:-0}" -eq 0 ]; then
|
||||
# No changes on this branch — a plan / questions / analysis only.
|
||||
post "$(printf '🤖 **@%s**\n\n%s' "$NAME" "$reply")"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# NOTE: Gitea ignores the ?head= filter, so match the head branch client-side.
|
||||
resp=$(curl -sS "${hdr[@]}" "$API/pulls?state=open&limit=50" \
|
||||
| jq -r --arg br "$br" 'if type=="array" then (map(select(.head.ref==$br)) | .[0] // empty) else empty end' 2>/dev/null)
|
||||
url=$(printf '%s' "$resp" | jq -r '.html_url // empty' 2>/dev/null)
|
||||
prnum=$(printf '%s' "$resp" | jq -r '.number // empty' 2>/dev/null)
|
||||
if [ -z "$url" ]; then
|
||||
title="@$NAME: $TITLE"
|
||||
resp=$(curl -sS -X POST "${hdr[@]}" "$API/pulls" \
|
||||
-d "$(jq -nc --arg t "$title" --arg h "$br" --arg b "$prbody" \
|
||||
'{title:$t, head:$h, base:"main", body:$b}')")
|
||||
echo "PR create ($br): $resp"
|
||||
url=$(printf '%s' "$resp" | jq -r '.html_url // empty' 2>/dev/null)
|
||||
prnum=$(printf '%s' "$resp" | jq -r '.number // empty' 2>/dev/null)
|
||||
fi
|
||||
[ -z "$url" ] && { echo "PR open/lookup failed for $br — posting reply on issue instead"; post "$(printf '🤖 **@%s**\n\n%s' "$NAME" "$reply")"; exit 0; }
|
||||
|
||||
# Posts to the PR thread when we have a PR number, else to the origin issue ($NUM).
|
||||
prpost() {
|
||||
local n="$1"; shift; local t="$NUM"
|
||||
[ -n "$n" ] && [ "$n" != "$NUM" ] && t="$n"
|
||||
echo "posting to #$t"
|
||||
curl -sS -w 'comment -> HTTP %{http_code}\n' -X POST "${hdr[@]}" \
|
||||
"$API/issues/$t/comments" -d "$(jq -nc --arg b "$1" '{body:$b}')"
|
||||
}
|
||||
|
||||
if [ "$NEW" = "true" ]; then
|
||||
noun="PR ready for review"; [ "$count" -gt 1 ] && noun="PRs ready for review (merge sequentially)"
|
||||
post "$(printf '🤖 **@%s** — ✅ %s %s — @ffaerber please review & merge:%b' "$NAME" "$count" "$noun" "$links")"
|
||||
prpost "$prnum" "$(printf '🤖 **@%s** — ✅ PR ready for review — @ffaerber please review & merge:\n- %s' "$NAME" "$url")"
|
||||
else
|
||||
# Resume (comment is on a PR thread): include the write-up here too.
|
||||
post "$(printf '🤖 **@%s** — updated %s branch/PR:%b\n\n%s' "$NAME" "$count" "$links" "$prdesc")"
|
||||
prpost "$prnum" "$(printf '🤖 **@%s** — updated branch/PR:\n- %s\n\n%s' "$NAME" "$url" "$prdesc")"
|
||||
fi
|
||||
|
||||
# Post the agent's activity trail (tool calls + reasoning) as a separate comment so
|
||||
@@ -480,7 +487,7 @@ jobs:
|
||||
if [ -s /tmp/activity_log.md ]; then
|
||||
entries=$(wc -l < /tmp/activity_log.md 2>/dev/null || echo 0)
|
||||
log=$(cat /tmp/activity_log.md)
|
||||
post "$(printf '🤖 **@%s** — activity log (%s entries):\n<details>\n<summary>tool calls & reasoning</summary>\n\n%s\n\n</details>' "$NAME" "$entries" "$log")"
|
||||
prpost "$prnum" "$(printf '🤖 **@%s** — activity log (%s entries):\n<details>\n<summary>tool calls & reasoning</summary>\n\n%s\n\n</details>' "$NAME" "$entries" "$log")"
|
||||
fi
|
||||
|
||||
- name: Mark done with 🚀 (remove 👀)
|
||||
|
||||
Reference in New Issue
Block a user