@plot-pm/board 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/plot-host.sh CHANGED
@@ -133,8 +133,10 @@
133
133
  # time — `commit-status` writes that status
134
134
  # through `plot-bitbucket-commit-status.mjs`.
135
135
  # EXIT 3 is the question failing.
136
- # pr-create --title T [--body B] [--base BR] [--head BR] [--draft]
137
- # create a PR, print its URL
136
+ # pr-create --title T [--body B | --body-file F] [--base BR] [--head BR] [--draft]
137
+ # create a PR, print its URL. GitHub
138
+ # creates it over REST (`POST pulls`), which
139
+ # spends `core` and never GraphQL.
138
140
  # pr-merge <number> [--squash] [--delete-branch] --match-head <sha>
139
141
  # merge the PR. --match-head is
140
142
  # mandatory on every backend. bitbucket
@@ -529,7 +531,11 @@
529
531
  # The transition id is LOOKED UP, never guessed:
530
532
  # ids are per workflow and per issue, so a
531
533
  # hardcoded one writes to the wrong column.
532
- # pr-body <number> --body B replace the PR description
534
+ # pr-body <number> (--body B | --body-file F)
535
+ # replace the PR description. GitHub replaces
536
+ # it over REST (`PATCH pulls/<n>`), which
537
+ # spends `core` and never GraphQL. --body-file
538
+ # reads the body from a file, on both ops.
533
539
  # rate-limit both GitHub budgets from `gh api rate_limit`.
534
540
  # SUPERSEDED BY `limit`, and kept only because
535
541
  # its callers have not moved: that endpoint was
@@ -699,7 +705,7 @@ gh_marker_comment_id() { gh api --paginate "repos/{owner}/{repo}/issues/$1/comme
699
705
  # EDITS THE COMMENT `$1` HOLDS, OR POSTS `$4` TO `$3` ON `$2` (`issue` or
700
706
  # `pr`) — shared by `issue-comment` and `pr-comment`, whose tails differed
701
707
  # only in that one word.
702
- gh_edit_or_post_comment() { if [ -n "$1" ]; then gh api -X PATCH "repos/{owner}/{repo}/issues/comments/$1" -f body="$4" >/dev/null 2>"$HOST_ERR"; else gh "$2" comment "$3" --body "$4" >/dev/null 2>"$HOST_ERR"; fi; }
708
+ gh_edit_or_post_comment() { if [ -n "$1" ]; then gh api -X PATCH "repos/{owner}/{repo}/issues/comments/$1" -f body="$4" >/dev/null 2>"$HOST_ERR"; else gh api -X POST "repos/{owner}/{repo}/issues/$3/comments" -f body="$4" >/dev/null 2>"$HOST_ERR"; fi; }
703
709
 
704
710
  # Exit 3 — reserved for "the op itself cannot proceed", distinct from `die`'s
705
711
  # generic 1. A Jenkins overlay with no instance to ask is such a case: a config
@@ -725,6 +731,10 @@ CHECKS_OF='def ck: (.conclusion // "") as $k | (.status // "") as $s | (if $s !=
725
731
  MERGEABLE_OF='def mergeable_of: if .mergeable == "CONFLICTING" or .mergeable == false or .mergeStateStatus == "DIRTY" or .mergeable_state == "dirty" then "conflicting"
726
732
  elif .mergeable == "MERGEABLE" or .mergeable == true then "mergeable" else "unknown" end;'
727
733
 
734
+ # THE ONE PROJECTION of a GraphQL-shaped PR into `pr-state`'s printed line, read by
735
+ # the GraphQL arm and by `rest_pr_state`, so the two transports print one shape.
736
+ PR_STATE_OF='{number:.number,state:.state,draft:.isDraft,url:.url,mergeCommit:(.mergeCommit.oid // ""),head:(.headRefName // ""),headSha:(.headRefOid // ""),base:(.baseRefName // ""),checks:checks_of,ciChecks:ci_checks_of,checksSha:(.headRefOid // ""),mergeable:mergeable_of,mergedAt:(.mergedAt // "")}'
737
+
728
738
  # Exit 5 — the host refused to answer FOR NOW. A rate limit, primary or
729
739
  # secondary: nothing is broken, nothing needs fixing, and the same question
730
740
  # asked later will be answered.
@@ -829,7 +839,6 @@ host_cli() { # → the CLI this backend drives, or '' where none is known
829
839
  case "$1" in
830
840
  github) echo "gh" ;;
831
841
  bitbucket) echo "bb" ;;
832
- *) echo "" ;;
833
842
  esac
834
843
  }
835
844
 
@@ -2131,7 +2140,7 @@ bb_fetch_base_bounded() {
2131
2140
  GIT_TERMINAL_PROMPT=0 git fetch -q origin "+refs/heads/$base:refs/remotes/origin/$base" 2>/dev/null & pid=$!
2132
2141
  ( sleep "$BB_FETCH_BOUND_S"; kill -TERM "-$pid" 2>/dev/null ) & watcher=$!
2133
2142
  wait "$pid" 2>/dev/null; rc=$?
2134
- kill "$watcher" 2>/dev/null; wait "$watcher" 2>/dev/null; [ "$was_m" = yes ] || set +m
2143
+ kill -TERM "-$watcher" 2>/dev/null; wait "$watcher" 2>/dev/null; [ "$was_m" = yes ] || set +m
2135
2144
  return "$rc"
2136
2145
  }
2137
2146
 
@@ -2292,7 +2301,7 @@ is_lookup_miss() {
2292
2301
  # `LC_ALL=C` for the reason `is_lookup_miss` gives: the CLI localises, and an
2293
2302
  # English-only matcher would misread every other locale.
2294
2303
  is_rate_refusal() {
2295
- LC_ALL=C grep -qiE 'rate limit|secondary rate|abuse detection|403.*forbidden' <<<"$1"
2304
+ LC_ALL=C grep -qiE 'rate[ _]limit|secondary rate|abuse detection|already exceeded|403.*forbidden' <<<"$1"
2296
2305
  }
2297
2306
 
2298
2307
  # Emits the miss payload on a genuine miss and exits non-zero on anything else,
@@ -2421,7 +2430,7 @@ graphql_budget_spent() {
2421
2430
  #
2422
2431
  # NO CALLER LEARNS THE ROUTE. The answer is consumed inside this script and
2423
2432
  # never reaches stdout, and both paths normalise to one vocabulary — see
2424
- # `rest_pr_to_state`, which exists so a REST answer is indistinguishable from a
2433
+ # `rest_pr_state`, which exists so a REST answer is indistinguishable from a
2425
2434
  # GraphQL one.
2426
2435
  #
2427
2436
  # THE CHEAP PATH IS THE DEFAULT, and this function does not change that. For 93
@@ -2479,7 +2488,7 @@ graphql_budget_spent() {
2479
2488
  gh_route() { # $1=op → graphql|rest
2480
2489
  case "${1:-}" in
2481
2490
  # REST-only: no GraphQL route exists to choose, so nothing is consulted.
2482
- rate-limit|limit)
2491
+ rate-limit|limit|pr-create|pr-body)
2483
2492
  printf 'rest\n'
2484
2493
  ;;
2485
2494
  # Both transports implemented — the one op where the reasons apply.
@@ -2530,23 +2539,47 @@ gh_route() { # $1=op → graphql|rest
2530
2539
  # `--repo` may already carry it (the caller passed `-R owner/repo`). Otherwise
2531
2540
  # `gh api` fills `{owner}/{repo}` from the git remote, with no request. A path
2532
2541
  # naming no real repository answers 404, which `is_lookup_miss` reads as NONE.
2533
- gh_rest_repo() {
2534
- if [ ${#repo_args[@]} -gt 0 ]; then echo "${repo_args[1]}"; else echo '{owner}/{repo}'; fi
2542
+ gh_rest_repo() { local d='{owner}/{repo}'; echo "${repo_args[1]:-$d}"; }
2543
+
2544
+ # ONE REST ANSWER IN GRAPHQL'S VOCABULARY: `pulls/{n}` for the PR, `check-runs` and
2545
+ # `status` for the rollup, folded through the SAME `PR_STATE_OF` the GraphQL arm
2546
+ # prints. `mergeCommit` is set for a merged PR only, because REST fills
2547
+ # `merge_commit_sha` with a test-merge sha on an open one. A rollup page that
2548
+ # holds fewer rows than `total_count` adds one QUEUED row, so a missing row can
2549
+ # make the answer `pending` and never `green`. Exit 1: the PR read failed (a 404
2550
+ # is a miss); exit 2: a later read failed, which is never a miss.
2551
+ rest_pr_state() { # $1=owner/repo $2=PR number or branch; returns 3 when the branch has no PR
2552
+ local pr sha ck='{}' st='{}'
2553
+ if [[ "$2" =~ ^[0-9]+$ ]]; then pr="$(gh_api_harvest "repos/$1/pulls/$2")" || return 1
2554
+ else pr="$(gh_api_harvest "repos/$1/pulls?head=${1%%/*}:$2&state=all&per_page=1")" || return 1; pr="$(jq -ce '.[0]' <<<"$pr")" || return 3; fi
2555
+ sha="$(jq -r '.head.sha // ""' <<<"$pr")"
2556
+ ck="$(gh_api_harvest "repos/$1/commits/$sha/check-runs?per_page=100")" && st="$(gh_api_harvest "repos/$1/commits/$sha/status?per_page=100")" || return 2
2557
+ jq -cs "$CHECKS_OF$MERGEABLE_OF"'.[0] as $p | (.[1].check_runs // []) as $c | (.[2].statuses // []) as $s | (($p.merged == true) or ($p.merged_at != null)) as $m | {number: $p.number, state: (if $m then "MERGED" else ($p.state // "" | ascii_upcase) end), isDraft: ($p.draft // false), url: ($p.html_url // ""), mergeCommit: (if $m then {oid: ($p.merge_commit_sha // "")} else null end), headRefName: ($p.head.ref // ""), headRefOid: ($p.head.sha // ""), baseRefName: ($p.base.ref // ""), mergedAt: ($p.merged_at // ""), mergeable: (if $p.mergeable == true then "MERGEABLE" elif $p.mergeable == false then "CONFLICTING" else "UNKNOWN" end), mergeStateStatus: (($p.mergeable_state // "") | ascii_upcase), statusCheckRollup: ([$c[] | {name, status: ((.status // "") | ascii_upcase), conclusion: ((.conclusion // "") | ascii_upcase)}] + [$s[] | {context, state: ((.state // "") | ascii_upcase)}] + (if ((.[1].total_count // 0) > ($c | length)) or ((.[2].total_count // 0) > ($s | length)) then [{status: "QUEUED"}] else [] end))} |'"$PR_STATE_OF" <<<"$pr$ck$st"
2535
2558
  }
2536
2559
 
2537
- rest_pr_to_state() {
2538
- jq -c "$MERGEABLE_OF"'
2539
- (if (.merged == true) or (.merged_at != null) then "MERGED"
2540
- else (.state // "" | ascii_upcase) end) as $state
2541
- | { number: .number,
2542
- state: $state,
2543
- draft: (.draft // false),
2544
- url: (.html_url // ""),
2545
- mergeCommit: (.merge_commit_sha // ""), head: (.head.ref // ""), headSha: (.head.sha // ""), base: (.base.ref // ""), checks: "unknown", mergeable: mergeable_of,
2546
- mergedAt: (.merged_at // "") }
2547
- '
2560
+ # `owner/repo` from the `origin` URL, with no host call. An `ssh://` URL may carry
2561
+ # a port after the host, and an scp-style remote splits host and path at its first
2562
+ # colon. Prints nothing and exits 1 where the URL names no `owner/repo`.
2563
+ gh_origin_slug() { git config --get remote.origin.url | sed -E 's#\.git/?$##; s#^.*[:/]([^/:]+/[^/:]+)$#\1#' | grep -E '^[^/]+/[^/]+$'; }
2564
+ # THE PR TEXT FLAGS of `pr-create` and `pr-body`, parsed in one place. `--body-file`
2565
+ # reads the body from a file, so a long body never rides on the command line: on
2566
+ # 2026-11-14 a hook refused a long inline `--body` for agents in isolated worktrees.
2567
+ pr_text_args() { # $1=op, then its flags → sets title, body, base, head, draft
2568
+ local op="$1"; shift; title=""; body=""; base=""; head=""; draft=""
2569
+ while [ $# -gt 0 ]; do
2570
+ case "$1" in
2571
+ --title|--body|--base|--head) printf -v "${1#--}" '%s' "${2:?}"; shift 2 ;;
2572
+ --body-file) body="$(cat -- "${2:?}" 2>/dev/null)" || die "$op: cannot read $2"; shift 2 ;;
2573
+ --draft) draft=1; shift ;;
2574
+ *) die "$op: unknown arg $1" ;;
2575
+ esac
2576
+ done
2548
2577
  }
2549
2578
 
2579
+ # `gh` as the merger identity where a Merger app token was minted, as the
2580
+ # signed-in one where none was. The token goes into `GH_TOKEN` only.
2581
+ merger_gh() { GH_TOKEN="${merger_token:-${GH_TOKEN-}}" gh "$@"; }
2582
+
2550
2583
  # Bitbucket's --state vocabulary is not GitHub's, and this adapter used to
2551
2584
  # translate in one direction only: every response mapper turns DECLINED into
2552
2585
  # CLOSED, while the request carried the caller's GitHub word unchanged. `bb`
@@ -3025,11 +3058,15 @@ read_env_var() { # $1=name $2=file → the value, or nothing
3025
3058
  # checkout root only for a standard `git worktree add` checkout; where the
3026
3059
  # command fails, prints nothing, or its parent directory does not exist, this
3027
3060
  # falls through to "no main checkout .env" rather than inventing a path.
3061
+ #
3062
+ # An exported answer for this checkout replaces both git questions
3063
+ # (`plot_given_common_dir`); another repository's asks git.
3028
3064
  plot_env_file() {
3029
3065
  local root env_file common
3030
- root="$(git rev-parse --show-toplevel 2>/dev/null)" || root="."; env_file="$root/.env"
3066
+ . "$here/plot-desk-root.sh"
3067
+ root="$(plot_given_common_dir "$PWD" top || git rev-parse --show-toplevel 2>/dev/null)" || root="."; env_file="$root/.env"
3031
3068
  plot_env_file_qualifies "$env_file" "$1" "$2" && { printf '%s|' "$env_file"; return 0; }
3032
- common="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" && [ -n "$common" ] || return 0
3069
+ common="$(plot_given_common_dir "$PWD" || git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" && [ -n "$common" ] || return 0
3033
3070
  env_file="$(dirname "$common")/.env"
3034
3071
  plot_env_file_qualifies "$env_file" "$1" "$2" && printf "%s|the main checkout's " "$env_file"
3035
3072
  }
@@ -4033,46 +4070,22 @@ case "$op" in
4033
4070
  # learn what was just read for free.
4034
4071
  #
4035
4072
  # A number and a branch name need DIFFERENT endpoints, and their
4036
- # payload shapes differ too — see `rest_pr_to_state`, which is the one
4073
+ # payload shapes differ too — see `rest_pr_state`, which is the one
4037
4074
  # place that knows how to read either.
4038
4075
  rest_repo="$(gh_rest_repo)" || exit $?
4039
- if [[ "$ref" =~ ^[0-9]+$ ]]; then
4040
- if out="$(gh_api_harvest "repos/$rest_repo/pulls/$ref" 2>"$HOST_ERR")"; then
4041
- rm -f "$HOST_ERR"
4042
- rest_pr_to_state <<<"$out"
4043
- else
4044
- host_err
4045
- host_miss_or_fail "$err" \
4046
- '{"number":0,"state":"NONE","draft":false,"url":"","mergeCommit":""}' || exit $?
4047
- fi
4048
- else
4049
- # `?head=owner:branch` is the list form. AN EMPTY ARRAY IS AN ANSWER —
4050
- # the branch has no PR — while a call that never arrived is not, which
4051
- # is why the empty case is handled here and the failure goes through
4052
- # `host_miss_or_fail` like every other transport error.
4053
- #
4054
- # `state=all`, because the default is `open` and a merged PR would
4055
- # otherwise read as NONE — wrong in the reassuring direction.
4056
- rest_owner="${rest_repo%%/*}"
4057
- if out="$(gh_api_harvest "repos/$rest_repo/pulls?head=$rest_owner:$ref&state=all&per_page=1" 2>"$HOST_ERR")"; then
4058
- rm -f "$HOST_ERR"
4059
- if [ "$(jq -r 'length' <<<"$out" 2>/dev/null)" = "0" ]; then
4060
- echo '{"number":0,"state":"NONE","draft":false,"url":"","mergeCommit":""}'
4061
- else
4062
- jq -c '.[0]' <<<"$out" | rest_pr_to_state
4063
- fi
4064
- else
4065
- host_err
4066
- host_miss_or_fail "$err" \
4067
- '{"number":0,"state":"NONE","draft":false,"url":"","mergeCommit":""}' || exit $?
4068
- fi
4069
- fi
4076
+ none='{"number":0,"state":"NONE","draft":false,"url":"","mergeCommit":""}'
4077
+ rest_pr_state "$rest_repo" "$ref" 2>"$HOST_ERR" && rm -f "$HOST_ERR" || {
4078
+ rc=$?; host_err
4079
+ [ "$rc" -ne 3 ] || { echo "$none"; exit 0; }
4080
+ [ "$rc" -ne 2 ] || die3 "pr-state: the checks read failed: $err"
4081
+ host_miss_or_fail "$err" "$none" || exit $?
4082
+ }
4070
4083
  # mergeCommit is what lets a caller ask "which release contains this?" —
4071
4084
  # `git tag --contains <sha>` answers exactly, where dates cannot. It is ""
4072
4085
  # for anything unmerged, which is the honest answer rather than a guess.
4073
4086
  elif out="$(gh ${repo_args[@]+"${repo_args[@]}"} pr view "$ref" --json number,state,isDraft,url,mergeCommit,headRefName,headRefOid,baseRefName,statusCheckRollup,mergeable,mergeStateStatus,mergedAt 2>"$HOST_ERR")"; then
4074
4087
  rm -f "$HOST_ERR"
4075
- jq -c "$CHECKS_OF$MERGEABLE_OF"'{number:.number,state:.state,draft:.isDraft,url:.url,mergeCommit:(.mergeCommit.oid // ""),head:(.headRefName // ""),headSha:(.headRefOid // ""),base:(.baseRefName // ""),checks:checks_of,ciChecks:ci_checks_of,checksSha:(.headRefOid // ""),mergeable:mergeable_of,mergedAt:(.mergedAt // "")}' <<<"$out"
4088
+ jq -c "$CHECKS_OF$MERGEABLE_OF$PR_STATE_OF" <<<"$out"
4076
4089
  else
4077
4090
  host_err
4078
4091
  # REFUSED FOR RATE IS NOT ANSWERED. The budget gate above could not see
@@ -4381,28 +4394,30 @@ case "$op" in
4381
4394
  # decided here: `checkedReview` judges the list against the Review app's bot
4382
4395
  # login. The pages and the PR travel through stdin, never `--argjson` (the
4383
4396
  # 128 KB argv cap on Linux).
4384
- out="$(gh pr view "${1:?pr-review needs a PR number}" --json headRefOid,comments)" && st="$(gh api --paginate "repos/{owner}/{repo}/commits/$(jq -r .headRefOid <<<"$out")/statuses?per_page=100")" \
4385
- && printf '%s\n%s\n' "$out" "$st" | jq -cs '.[0] as $pr | [.[1:][][] | select(.context == "plot/review")] as $s | $s[0] as $m | {sha: $pr.headRefOid, state: ($m.state // "absent"), description: ($m.description // ""), time: ($m.updated_at // ""), bypass: any($pr.comments[]?; .body | startswith("review-bypass:")), statuses: [$s[] | {state, description: (.description // ""), time: (.updated_at // ""), writer: (.creator.login // "")}]}' \
4397
+ # REST ONLY: `gh pr view` is GraphQL, and its secondary limit refused three
4398
+ # reviews on 2026-11-08 while core stood at 4797 of 5000. Comments and
4399
+ # statuses are paginated, and a failed read is a failed answer, never an
4400
+ # empty list. The pages reach `jq` through `--slurpfile`, not `--argjson`.
4401
+ out="$(gh_api_harvest "repos/{owner}/{repo}/pulls/${1:?pr-review needs a PR number}")" && sha="$(jq -re '.head.sha' <<<"$out")" \
4402
+ && cm="$(gh api --paginate "repos/{owner}/{repo}/issues/$1/comments?per_page=100")" && st="$(gh api --paginate "repos/{owner}/{repo}/commits/$sha/statuses?per_page=100")" \
4403
+ && jq -nc --arg sha "$sha" --slurpfile cm <(printf '%s' "$cm") --slurpfile st <(printf '%s' "$st") '[$st[][] | select(.context == "plot/review")] as $s | $s[0] as $m | {sha: $sha, state: ($m.state // "absent"), description: ($m.description // ""), time: ($m.updated_at // ""), bypass: any($cm[][]; .body | startswith("review-bypass:")), statuses: [$s[] | {state, description: (.description // ""), time: (.updated_at // ""), writer: (.creator.login // "")}]}' \
4386
4404
  || die3 "pr-review: the read failed" ;;
4387
4405
 
4388
4406
  pr-create)
4389
- title=""; body=""; base=""; head=""; draft=0
4390
- while [ $# -gt 0 ]; do
4391
- case "$1" in
4392
- --title) title="${2:?}"; shift 2 ;;
4393
- --body) body="${2:?}"; shift 2 ;;
4394
- --base) base="${2:?}"; shift 2 ;;
4395
- --head) head="${2:?}"; shift 2 ;;
4396
- --draft) draft=1; shift ;;
4397
- *) die "pr-create: unknown arg $1" ;;
4398
- esac
4399
- done
4407
+ pr_text_args pr-create "$@"
4400
4408
  [ -n "$title" ] || die "pr-create needs --title"
4401
- args=(pr create --title "$title" --body "$body")
4402
- [ -n "$base" ] && args+=(--base "$base")
4403
- [ -n "$head" ] && args+=(--head "$head")
4404
- [ "$draft" = 1 ] && args+=(--draft)
4405
- if [ "$be" = "github" ]; then gh "${args[@]}"; else bb "${args[@]}"; fi
4409
+ # GITHUB OPENS THE PR OVER REST, `POST repos/<origin slug>/pulls`, and prints
4410
+ # its `html_url` as `gh pr create` printed its URL. `gh pr create` spends
4411
+ # GraphQL: on 2026-11-13 it failed three times at 0 of 5000 GraphQL while
4412
+ # REST held more than 4600 of 5000. The owner/repo is the origin remote's,
4413
+ # as `pr-merge` reads it, never `gh`'s default repo. REST needs a base and a
4414
+ # head where `gh pr create` filled them in: a missing `--head` is the
4415
+ # current branch, and a missing `--base` is this script's `default-branch`.
4416
+ # `pipefail` makes a failed POST the op's exit code, with `gh`'s own words.
4417
+ if [ "$be" = "github" ]; then
4418
+ slug="$(gh_origin_slug)" && head="${head:-$(git symbolic-ref --short HEAD)}" && base="${base:-$(bash "$here/plot-host.sh" default-branch)}" || die3 "pr-create: no owner/repo on origin or no head branch; nothing was opened"
4419
+ gh_api_harvest -X POST "repos/$slug/pulls" -f title="$title" -f head="$head" -f base="$base" -f body="$body" -F draft="$([ -n "$draft" ] && echo true || echo false)" | jq -r '.html_url'
4420
+ else bb pr create --title "$title" --body "$body" ${base:+--base "$base"} ${head:+--head "$head"} ${draft:+--draft}; fi
4406
4421
  ;;
4407
4422
 
4408
4423
  pr-merge)
@@ -4425,10 +4440,15 @@ case "$op" in
4425
4440
  # answers 5 with its one-line notice where no key is declared: the merge
4426
4441
  # then runs as the signed-in `gh` identity. The token goes straight into
4427
4442
  # GH_TOKEN — never into argv, a file, or a log line.
4428
- merger_repo=$(gh repo view --json nameWithOwner --jq '.nameWithOwner' 2>/dev/null) || die3 "pr-merge: gh repo view could not resolve owner/repo from the current checkout"
4443
+ merger_repo="$(gh_origin_slug)" || die3 "pr-merge: the origin remote names no owner/repo; nothing was merged"
4429
4444
  merger_token=$(node "$here/plot-merger-token.mjs" "$merger_repo") || { mc=$?; [ "$mc" = 5 ] || exit "$mc"; }
4430
- args=(pr merge "$num"); [ "$squash" = 1 ] && args+=(--squash) || args+=(--merge); [ "$delbranch" = 1 ] && args+=(--delete-branch)
4431
- if [ -n "$merger_token" ]; then GH_TOKEN="$merger_token" gh "${args[@]}" --match-head-commit "$pin"; else gh "${args[@]}" --match-head-commit "$pin"; fi
4445
+ # `PUT pulls/{n}/merge` with `sha` is the head pin, and GitHub answers 409
4446
+ # for a head that moved. A 405 (not mergeable) is a different answer and
4447
+ # keeps the host's own words. The branch delete is cleanup after the merge:
4448
+ # its failure warns and does not undo or fail the merge.
4449
+ if out="$(merger_gh api -X PUT "repos/{owner}/{repo}/pulls/$num/merge" -f merge_method="$([ "$squash" = 1 ] && echo squash || echo merge)" -f sha="$pin" 2>&1)"; then
4450
+ [ "$delbranch" != 1 ] || merger_gh api -X DELETE "repos/{owner}/{repo}/git/refs/heads/$(merger_gh api "repos/{owner}/{repo}/pulls/$num" --jq 'select(.head.repo.full_name == .base.repo.full_name) | .head.ref' 2>/dev/null)" >/dev/null 2>&1 || echo "plot-host: pr-merge: PR #$num merged, but its branch was not deleted" >&2
4451
+ else [[ "$out" != *"HTTP 409"* ]] || out="--match-head: head-moved — PR #$num is no longer at $pin; nothing was merged"; echo "plot-host: pr-merge: $out" >&2; exit 1; fi
4432
4452
  # Bitbucket's merge endpoint takes no head precondition (measured 2026-10-18,
4433
4453
  # see plan Notes), so the pin is enforced by re-reading the head via bb_state_row
4434
4454
  # right before merging; it matches by prefix, 7+ hex (domain's sameCommit).
@@ -5326,7 +5346,7 @@ case "$op" in
5326
5346
  # `search/jql` takes the same params as v3 but returns
5327
5347
  # `summary`/`description` as plain strings.
5328
5348
  max="${limit:-50}"
5329
- fields="summary,created,status,assignee,issuetype"
5349
+ fields="summary,created,status,assignee,issuetype,fixVersions"
5330
5350
  if [ "$state" = closed ]; then
5331
5351
  # THE CLOSED READ REQUIRES `Ticket prefixes` AND READS NOT PLOT_JIRA_JQL.
5332
5352
  # An unscoped `resolved >=` query reads the whole instance — the hazard
@@ -5421,7 +5441,7 @@ case "$op" in
5421
5441
  url: ($base + "/browse/" + .key),
5422
5442
  createdAt: (.fields.created // ""),
5423
5443
  status: (.fields.status.name // ""),
5424
- statusCategory: (.fields.status.statusCategory.name // ""), assignees: ([.fields.assignee.emailAddress // .fields.assignee.accountId] | map(select(. != null)))
5444
+ statusCategory: (.fields.status.statusCategory.name // ""), assignees: ([.fields.assignee.emailAddress // .fields.assignee.accountId] | map(select(. != null))), releases: [.fields.fixVersions[]?.name]
5425
5445
  } + (if .fields.issuetype.name then {type: .fields.issuetype.name} else {} end) + (if .fields.updated then {updatedAt: .fields.updated} else {} end) + (if ($state == "closed") or ($state == "changed" and .fields.status.statusCategory.name == "Done") then {closedAt: (.fields.resolutiondate // "")} else {} end)),
5426
5446
  (select($paged == "1") | (.nextPageToken // empty) | {nextPageToken: .})'
5427
5447
  elif [ "$be" = "github" ]; then
@@ -5452,7 +5472,7 @@ case "$op" in
5452
5472
  # several, so a state that already uses one here is refused instead of
5453
5473
  # silently losing the title filter (open issues is the lookup's only use).
5454
5474
  [ -z "$title_has" ] || [ "$gh_state" = open ] || die "issue-list: --title-has only works with --state open"
5455
- gh_json="number,title,url,createdAt,assignees,issueType"; search_args=(); ask_state="$gh_state"
5475
+ gh_json="number,title,url,createdAt,assignees,issueType,milestone"; search_args=(); ask_state="$gh_state"
5456
5476
  [ -z "$label" ] || search_args=(--label "$label")
5457
5477
  if [ "$gh_state" = changed ]; then gh_json+=",updatedAt,state,closedAt"; ask_state=all; search_args+=(--search "updated:>=$since")
5458
5478
  elif [ "$gh_state" != open ]; then gh_json+=",closedAt,labels"; search_args+=(--search "closed:>=$since")
@@ -5473,7 +5493,7 @@ case "$op" in
5473
5493
  jq -c --arg status "$gh_state" \
5474
5494
  '.[] | ((.state // $status) | ascii_downcase) as $actual |
5475
5495
  {number:.number,title:.title,url:(.url // ""),createdAt:(.createdAt // ""),
5476
- status:$actual,statusCategory:(if $actual == "open" then "To Do" else "Done" end),assignees:[.assignees[]?.login]}
5496
+ status:$actual,statusCategory:(if $actual == "open" then "To Do" else "Done" end),assignees:[.assignees[]?.login],releases:[.milestone.title? // empty]}
5477
5497
  + (if .updatedAt then {updatedAt:.updatedAt} else {} end) + (if .issueType.name? then {type:.issueType.name} else {} end)
5478
5498
  + (if $actual == "closed" then {closedAt:(.closedAt // "")} else {} end) + (if .labels then {labels:[.labels[].name]} else {} end)' <<<"$out"
5479
5499
  else
@@ -5732,7 +5752,7 @@ case "$op" in
5732
5752
  # comment per issue and closes the issue at release; nothing reads any back,
5733
5753
  # except `issue-comment-read`, the plan-state comment's one sanctioned
5734
5754
  # read-back (D6: recovering ticket lines a write has no record to redo).
5735
- # issue-label <n> <add> [<remove,...>] adds one label, creating it first where the repo lacks it, and removes only the listed ones the issue carries, in one `gh issue edit`
5755
+ # issue-label <n> <add> [<remove,...>] adds one label, creating it first where the repo lacks it, and removes only the listed ones the issue carries, all through REST
5736
5756
  # issue-comment <n> <marker> <body> edits the comment holding <marker>, else posts; an empty <marker> always posts
5737
5757
  # issue-comment-read <n> <marker> prints the marked comment's body, or nothing where none carries it
5738
5758
  # issue-close <n>
@@ -5741,7 +5761,10 @@ case "$op" in
5741
5761
  num="${1:?$op needs an issue number}"; source_said="$(issue_source)" || exit 1
5742
5762
  [ "$be" = github ] && { [ "$source_said" = git-host ] || [ "$source_said" = $'tracker\tgithub-issues' ]; } || { echo "plot-host: $op: ${source_said#*$'\t'}" >&2; exit 4; }
5743
5763
  case "$op" in
5744
- issue-label) add="${2:?issue-label needs a label}"; carried="$(gh issue view "$num" --json labels -q '.labels[].name' 2>"$HOST_ERR")" || gh_fail; keep="$(comm -12 <(printf '%s\n' "${3-}" | tr , '\n' | sort) <(printf '%s\n' "$carried" | sort) | paste -sd, -)"; gh label create "$add" --color ededed --description "Plot plan phase: ${add#plan:}" >/dev/null 2>"$HOST_ERR" || grep -qi 'already exists' "$HOST_ERR" || gh_fail; gh issue edit "$num" --add-label "$add" ${keep:+--remove-label "$keep"} >/dev/null 2>"$HOST_ERR" || gh_fail ;;
5764
+ issue-label) add="${2:?issue-label needs a label}"; carried="$(gh api --paginate "repos/{owner}/{repo}/issues/$num/labels" -q '.[].name' 2>"$HOST_ERR")" || gh_fail
5765
+ gh api -X POST "repos/{owner}/{repo}/labels" -f name="$add" -f color=ededed -f description="Plot plan phase: ${add#plan:}" >"$HOST_ERR" 2>&1 || grep -q already_exists "$HOST_ERR" || gh_fail
5766
+ gh api -X POST "repos/{owner}/{repo}/issues/$num/labels" -f "labels[]=$add" >/dev/null 2>"$HOST_ERR" || gh_fail
5767
+ while IFS= read -r l; do [ -z "$l" ] || gh api -X DELETE "repos/{owner}/{repo}/issues/$num/labels/$(jq -rn --arg s "$l" '$s|@uri')" >/dev/null 2>"$HOST_ERR" || gh_fail; done < <(comm -12 <(printf '%s\n' "${3-}" | tr , '\n' | sort) <(printf '%s\n' "$carried" | sort)) ;;
5745
5768
  issue-close) gh issue close "$num" >/dev/null 2>"$HOST_ERR" || gh_fail ;;
5746
5769
  issue-comment)
5747
5770
  cid="${2:+$(gh_marker_comment_id "$num" "$2")}" || gh_fail
@@ -5763,15 +5786,17 @@ case "$op" in
5763
5786
  printf '%s' "$body" | jq -c '.[] | {name, released: (.released // false), releaseDate: (.releaseDate // null)}' || exit 3 ;;
5764
5787
 
5765
5788
  pr-body)
5766
- num="${1:?pr-body needs a PR number}"; shift; body=""
5767
- while [ $# -gt 0 ]; do
5768
- case "$1" in
5769
- --body) body="${2:?}"; shift 2 ;;
5770
- *) die "pr-body: unknown arg $1" ;;
5771
- esac
5772
- done
5773
- [ -n "$body" ] || die "pr-body needs --body"
5774
- "$cli" pr edit "$num" --body "$body"
5789
+ num="${1:?pr-body needs a PR number}"; shift; pr_text_args pr-body "$@"
5790
+ [ -z "$title$base$head$draft" ] || die "pr-body takes only --body or --body-file"
5791
+ [ -n "$body" ] || die "pr-body needs --body or --body-file"
5792
+ # GITHUB REPLACES THE BODY OVER REST, `PATCH repos/<origin slug>/pulls/<n>`,
5793
+ # and prints its `html_url` as `gh pr edit` printed the URL. `gh pr edit`
5794
+ # spends GraphQL: on 2026-11-14 it failed twice with "GraphQL: API rate limit
5795
+ # already exceeded" while REST held budget. `pr-create` takes the same route.
5796
+ if [ "$be" = "github" ]; then
5797
+ slug="$(gh_origin_slug)" || die3 "pr-body: no owner/repo on origin; nothing was written"
5798
+ gh_api_harvest -X PATCH "repos/$slug/pulls/$num" -f body="$body" | jq -r '.html_url'
5799
+ else bb pr edit "$num" --body "$body"; fi
5775
5800
  ;;
5776
5801
 
5777
5802
  rate-limit)
@@ -6041,7 +6066,7 @@ case "$op" in
6041
6066
  # the path, so a numeric workspace survives. An empty slug is `unsupported`.
6042
6067
  [ "$be" = "github" ] || { node "$here/plot-bitbucket-commit-status.mjs" "$(node "$here/board/plot-bitbucket-slug.mjs" "$(git config --get remote.origin.url 2>/dev/null)")" "$@" || exit $?; exit 0; }
6043
6068
  node "$here/plot-commit-status.mjs" --check "$@" || exit $?
6044
- node "$here/plot-commit-status.mjs" --repo "$(gh repo view --json nameWithOwner --jq '.nameWithOwner' 2>/dev/null || echo GH_REPO_VIEW_FAILED)" "$@" || exit $?
6069
+ node "$here/plot-commit-status.mjs" --repo "$(gh_origin_slug || echo GH_REPO_VIEW_FAILED)" "$@" || exit $?
6045
6070
  ;;
6046
6071
 
6047
6072
  pr-comment)