coordination-claims: no growing body, only a maintainer's thread, keep an edit made during the run (review)

- The body is read as stored (JSON, not --jq, which added a newline that update_body kept: one more per day).
- The issue is the newest open "Coordinating who works on what" opened by an owner, member or collaborator, so a
  look-alike issue cannot take the bot over (search API author_association; #3312 qualifies).
- The body is read again before the edit; if it changed during the run, the edit is skipped with a warning.
- The "Updated" stamp is the day, not the minute, so an unchanged table is not rewritten within a day.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MoonEyes
2026-12-03 11:45:42 +01:00
parent f5bcf2588a
commit 786f52d46e
2 changed files with 17 additions and 6 deletions

View File

@ -45,15 +45,23 @@ jobs:
mkdir -p "$work"
# The newest open issue whose title starts with the name; the thread moves to a new issue when it fills up.
number=$(gh issue list --state open --limit 50 --search 'Coordinating who works on what in:title' \
--json number,title \
--jq '[.[] | select(.title | startswith("Coordinating who works on what")) | .number] | max // empty')
# Only an issue opened by an owner, member or collaborator counts, so anyone else's issue with the same title
# cannot take the bot over.
number=$(gh api -X GET search/issues -f per_page=50 \
-f q="repo:$GITHUB_REPOSITORY is:issue is:open in:title \"Coordinating who works on what\"" \
--jq '[.items[] | select((.title | startswith("Coordinating who works on what"))
and (.author_association | IN("OWNER", "MEMBER", "COLLABORATOR"))) | .number] | max // empty')
if [ -z "$number" ]; then
echo "::error::No open issue titled 'Coordinating who works on what' was found."
exit 1
fi
echo "Coordination issue: #$number"
gh issue view "$number" --json body --jq .body > "$work/body.md"
# The body exactly as stored: `--jq .body` adds a newline, and the body would grow by one each day.
read_body() {
gh issue view "$number" --json body |
python3 -I -c 'import json, sys; sys.stdout.write(json.load(sys.stdin)["body"] or "")'
}
read_body > "$work/body.md"
# The thread this one continues, if its body says so ("Continued from #N", "Continuation of #N").
previous=$(grep -oiE '(continued from|continuation of) #[0-9]+' "$work/body.md" | head -n 1 | grep -oE '[0-9]+$' || true)
@ -77,6 +85,9 @@ jobs:
if cmp -s "$work/body.md" "$work/new_body.md"; then
echo "The body of #$number is already up to date."
elif ! read_body | cmp -s - "$work/body.md"; then
# Someone edited the body while the comments were read: keep their edit; the next run redoes the table.
echo "::warning::The body of #$number changed during the run; not overwriting it."
else
gh issue edit "$number" --body-file "$work/new_body.md"
echo "Updated the claims table in #$number."

View File

@ -164,8 +164,8 @@ HEADER = "| Claimed | ID | By | Age (days) | Open PRs naming the ID |\n|---|---|
def counts_line(rows, ever, now):
unmatched = sum(1 for r in rows if not r[4])
return ("%d IDs claimed in the threads read, %d with no `done:`/`released:` line, %d of those with no open pull "
"request naming them. Updated %s UTC."
% (ever, len(rows), unmatched, now.astimezone(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M")))
"request naming them. Updated %s (UTC)."
% (ever, len(rows), unmatched, now.astimezone(datetime.timezone.utc).strftime("%Y-%m-%d")))
def render_table(rows, ever, now, budget=None):