diff --git a/.github/workflows/coordination-claims.yml b/.github/workflows/coordination-claims.yml index 5257ebd1d..3c8fec9c5 100644 --- a/.github/workflows/coordination-claims.yml +++ b/.github/workflows/coordination-claims.yml @@ -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." diff --git a/tools/coordination_claims.py b/tools/coordination_claims.py index b02ab8251..f4d70352c 100644 --- a/tools/coordination_claims.py +++ b/tools/coordination_claims.py @@ -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):