@plot-pm/board 0.19.1 → 0.21.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
@@ -74,9 +74,18 @@
74
74
  # empty answer sends the reaper to a weaker
75
75
  # reading, so only a recognised lookup miss is
76
76
  # empty.
77
+ # pr-review <number> one JSON line `{"sha","state","bypass"}`: the PR's
78
+ # head sha, the newest `plot/review` status on it
79
+ # (`success|failure|pending|error`, or `absent`),
80
+ # and whether a comment starts `review-bypass:`.
81
+ # Bitbucket EXITS 4 (unaskable). EXIT 3 is the
82
+ # question failing.
77
83
  # pr-create --title T [--body B] [--base BR] [--head BR] [--draft]
78
84
  # create a PR, print its URL
79
- # pr-merge <number> [--squash] [--delete-branch] [--match-head <sha>]
85
+ # pr-merge <number> [--squash] [--delete-branch] --match-head <sha>
86
+ # github: --match-head is mandatory, refused
87
+ # with no pin. bitbucket: cannot pin, refused
88
+ # (exit 4) when one is given.
80
89
  # pr-ready <number> take a PR out of draft
81
90
  # merge the PR
82
91
  # pr-list [--state open|merged|closed|all] [--limit N] [--rich|--rich-open]
@@ -255,7 +264,26 @@
255
264
  # human click as merely pending forever.
256
265
  # NOTHING on bitbucket (bb has no run listing) —
257
266
  # unavailable, never "no run".
258
- # issue-list [--limit N] open tracker issues as JSON lines:
267
+ # issue-list [--limit N] [--state open|closed] [--since <iso>] [--page-token T] [--paged]
268
+ # tracker issues as JSON lines, open by default.
269
+ # `--state closed` needs `--since` (a date, or
270
+ # a date and `THH:MM`) and adds `closedAt` to
271
+ # each row, in no promised order — the caller
272
+ # sorts: GitHub keeps what closed at or after
273
+ # `since`; Jira requires `Ticket prefixes`,
274
+ # reads `since`'s time in the reader's Jira
275
+ # profile zone (JQL takes no offset), and reads
276
+ # one page of 100, printing
277
+ # `{"nextPageToken":"…"}` as a last line for the
278
+ # caller to pass back as `--page-token`. The
279
+ # closed read and an open read given `--paged`
280
+ # print that line, and on Jira ask 100 rows a
281
+ # page; an open read without `--paged` prints
282
+ # issue rows alone. EXIT 4 where the closed read
283
+ # cannot be asked at all: Bitbucket (`bb issue
284
+ # list` prints no closing date) and Jira with no
285
+ # `Ticket prefixes`, both before any bb or curl.
286
+ # Open issues:
259
287
  # {"number":N,"title":"…","url":"…",
260
288
  # "createdAt":"…","status":"…",
261
289
  # "statusCategory":"…"}
@@ -279,10 +307,8 @@
279
307
  # abandoned work beside finished work.
280
308
  # READ-ONLY. Plot writes no label, no assignee
281
309
  # and no close-on-merge, because a copy of
282
- # tracker state ages into a lie. The one write
283
- # that exists is `issue-status`, and it records
284
- # a status Plot itself just caused rather than
285
- # mirroring one the tracker holds.
310
+ # tracker state ages into a lie. The two
311
+ # writes are `issue-status` and `issue-open`.
286
312
  # `url` is "" when the host omits it, and a
287
313
  # consumer renders the number as plain text
288
314
  # rather than inventing an address — the rule
@@ -343,7 +369,15 @@
343
369
  # as issue-list. Jira answers 404 for a missing
344
370
  # key, which is exit 3 here (the tracker moved),
345
371
  # never an empty body.
346
- # issue-status <key> <status> THE ONE WRITE TO A TRACKER: record one status
372
+ # issue-open <request-json> (jira)
373
+ # issue-open <title> <body> [--label <label>...] (github-issues)
374
+ # THE SECOND OF TWO WRITES TO A TRACKER: open
375
+ # one issue. Prints Jira's JSON answer or the
376
+ # new GitHub issue's address. The connector
377
+ # builds the Jira request, including the
378
+ # `Tracker issue type` key's word (default
379
+ # `Task`). Exit 4 with the reason elsewhere.
380
+ # issue-status <key> <status> THE FIRST OF TWO WRITES: record one status
347
381
  # against one issue, and nothing else. No
348
382
  # create, no close, no comment, no label — a
349
383
  # plan referencing an issue is Plot's record,
@@ -414,6 +448,43 @@
414
448
  # Actions, ekzweb is Bitbucket + Jenkins.
415
449
  # Jenkins reports no limit, so it answers
416
450
  # `predicted`.
451
+ # commit-status <sha> <state> <context> <description> <url>
452
+ # GITHUB AND BITBUCKET. On GitHub, writes a
453
+ # commit status via `POST
454
+ # /repos/{owner}/{repo}/statuses/{sha}`,
455
+ # authenticated as a GitHub App installation —
456
+ # NOT the signed-in `gh` user — so the review
457
+ # verdict carries its own identity rather than
458
+ # whoever's laptop ran this. The App ID and a
459
+ # path to its private key come from the
460
+ # `Review app` config key (`<app id> <key
461
+ # path>`, read via plot-config.sh); a relative
462
+ # key path resolves against the repository
463
+ # root. EXIT 4, naming the key, where `Review
464
+ # app` is absent or its key file cannot be
465
+ # read — a configuration gap, not a transient:
466
+ # this script mints no token against a default
467
+ # App and asks no `gh`-signed-in identity in
468
+ # its place. On Bitbucket, writes a build status
469
+ # via `POST /2.0/repositories/{workspace}
470
+ # /{repo_slug}/commit/{sha}/statuses/build`,
471
+ # authenticated with a dedicated account's App
472
+ # password — BITBUCKET_REVIEW_USER and
473
+ # BITBUCKET_REVIEW_APP_PASSWORD, read from the
474
+ # environment or this repository's `.env`, NOT
475
+ # from `bb`'s own signed-in identity — mapping
476
+ # GitHub's state word to Bitbucket's
477
+ # (success→SUCCESSFUL, failure→FAILED). EXIT 4,
478
+ # naming both variables, where neither is
479
+ # configured; EXIT 4 naming `unsupported` where
480
+ # the workspace/repo cannot be resolved from
481
+ # `origin` or `state` has no mapping. A backend
482
+ # with no arm at all exits 4 too. `state` is one
483
+ # of GitHub's own words
484
+ # (success|failure|error|pending); `context`
485
+ # groups repeat statuses on one sha (this
486
+ # estate's caller passes `plot/review`). A call
487
+ # that reaches the API and fails exits 3.
417
488
  #
418
489
  # TRANSPORT IS NOT A CALLER'S CONCERN. Where a host offers a question over more
419
490
  # than one transport — GitHub's REST against its GraphQL — the choice is made
@@ -451,6 +522,16 @@ plot_tmpfile HOST_ERR host-err || { echo "plot-host: no temp file could be made
451
522
 
452
523
  die() { echo "plot-host: $*" >&2; exit 1; }
453
524
 
525
+ # Rows in one page of an issue read: `maxResults` on Jira, and the rows `gh issue
526
+ # list` fetches per request inside its one process.
527
+ ISSUE_PAGE_ROWS=100
528
+
529
+ # Reports the host CLI's own words from the last call and exits 3 — a question
530
+ # that failed, as opposed to exit 4 (cannot be asked) or an answered empty list.
531
+ # An empty message or a recognised lookup miss is an answer; anything else exits 3.
532
+ miss_or_exit3() { [ -z "$1" ] || is_lookup_miss "$1" || { echo "plot-host: $1" >&2; exit 3; }; }
533
+ gh_fail() { echo "plot-host: $(cat "$HOST_ERR" 2>/dev/null)" >&2; rm -f "$HOST_ERR"; exit 3; }
534
+
454
535
  # Exit 3 — reserved for "the op itself cannot proceed", distinct from `die`'s
455
536
  # generic 1. A Jenkins overlay with no instance to ask is such a case: a config
456
537
  # error a person must fix, not a transient the board should retry past.
@@ -1307,102 +1388,6 @@ ci_scheme() {
1307
1388
  ci_raw | awk '{print tolower($1)}'
1308
1389
  }
1309
1390
 
1310
- # Whether a candidate token is a host `jen -I` could be given.
1311
- #
1312
- # A URL passes whole. Otherwise it must be dot-separated labels ending in an
1313
- # alphabetic TLD, carrying no path separator and no `@`.
1314
- #
1315
- # THE FINAL FILTER IS THE FILE EXTENSION, and that is a measurement rather than
1316
- # a preference. `ci.yml` and `package.json` both match the dotted-label pattern,
1317
- # while `.ch` and `.io` are real two-letter TLDs — so TLD LENGTH cannot separate
1318
- # a host from a filename in either direction, and a `CI:` value naming a
1319
- # workflow file (`github-actions (see .github/workflows/ci.yml)`) is the
1320
- # measured case that would otherwise be read as a server.
1321
- ci_looks_like_host() {
1322
- case "$1" in
1323
- https://*|http://*) return 0 ;;
1324
- */*|*@*) return 1 ;;
1325
- esac
1326
- printf '%s\n' "$1" \
1327
- | grep -qE '^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*\.[a-z]{2,}$' || return 1
1328
- case "$1" in
1329
- *.yml|*.yaml|*.json|*.md|*.sh|*.js|*.ts|*.mjs|*.cjs|*.toml|*.xml|*.txt|*.lock|*.gradle) return 1 ;;
1330
- esac
1331
- return 0
1332
- }
1333
-
1334
- # Where this repository's CI lives: the `Jenkins instance` key, then
1335
- # `$JENKINS_INSTANCE`, then a host read out of the `CI` value. Empty when none
1336
- # of the three names one.
1337
- #
1338
- # THE ORDER IS NOT THE TRACKER'S, and the reason is information content.
1339
- # `tracker_base_url()` lets `$PLOT_JIRA_BASE_URL` win over its config value
1340
- # because both carry the same shape — a URL. Here the key carries MORE than the
1341
- # prose can express: `jenkins_instance()` (`:665`) returns `<slug>/<job/path>`,
1342
- # and the container path is a fact no file in a repository states
1343
- # (`stack.ts:98` calls the host *"the SLUG half"*). A prose-derived slug alone
1344
- # degrades `jenkins_build_map()` to root-scope listing, where its own comment
1345
- # says *"every branch reads `none`"* — and `quaweb` is nested
1346
- # (`job/quaweb/job/release`), so that renders an empty board for the exact
1347
- # repository this serves. So the explicit key is the primary and the prose is
1348
- # the fallback, never the other way round.
1349
- #
1350
- # IT EXTRACTS A HOST, NOT A REMAINDER. "Everything after the first token" was
1351
- # measured against all three real values and fails on every one:
1352
- # `at jenkins-ci-ewz… (Bitbucket PRs…`, `pipelines in .build/pipelines/ …`,
1353
- # `(e.g. continuous-build…)`. None is a host, and handing `jen -I` a sentence
1354
- # is worse than handing it nothing. `Tracker:` gets away with the naive split
1355
- # because its value is a scheme and a URL; `CI:` is prose in every repository
1356
- # that declares it.
1357
- #
1358
- # A BACKTICKED SPAN IS PREFERRED because the backticks are a deliberate act —
1359
- # the writer pointed at the value. It must still look like a host: one real
1360
- # repository marks up a PATH (`` `.build/pipelines/` ``), which is not a server.
1361
- #
1362
- # BACKTICKS ARE STRIPPED AND NO SCHEME IS NORMALISED ON. `ewz` writes a bare
1363
- # host in backticks and the probe used a full `https://` URL; `jen -I` accepts
1364
- # either, so inventing a canonical form would break whichever caller passes the
1365
- # other one.
1366
- #
1367
- # EMPTY IS AN ANSWER, not a failure: `Jenkins (e.g. continuous-build, …)` names
1368
- # no instance. Read the exit code, never the emptiness.
1369
- ci_instance() {
1370
- local instance candidate
1371
- instance=$(bash "$here/plot-config.sh" get "Jenkins instance" "" 2>/dev/null || echo "")
1372
- [ -n "$instance" ] || instance="${JENKINS_INSTANCE:-}"
1373
- if [ -n "$instance" ]; then
1374
- printf '%s' "$instance"
1375
- return
1376
- fi
1377
-
1378
- local value
1379
- value="$(ci_raw)"
1380
-
1381
- # The backticked spans, in order: `tr` puts each on its own line, so the
1382
- # even-numbered lines are what sat between a pair of backticks.
1383
- while IFS= read -r candidate; do
1384
- [ -n "$candidate" ] || continue
1385
- if ci_looks_like_host "$candidate"; then
1386
- printf '%s' "$candidate"
1387
- return
1388
- fi
1389
- done <<EOF
1390
- $(printf '%s\n' "$value" | tr '\`' '\n' | awk 'NR % 2 == 0')
1391
- EOF
1392
-
1393
- # Otherwise the first bare token that looks like a host. Punctuation that
1394
- # ends a clause is split off so `(jenkins.acme.dev)` reads as the host.
1395
- while IFS= read -r candidate; do
1396
- [ -n "$candidate" ] || continue
1397
- if ci_looks_like_host "$candidate"; then
1398
- printf '%s' "$candidate"
1399
- return
1400
- fi
1401
- done <<EOF
1402
- $(printf '%s\n' "$value" | tr -d '\`' | tr ' \t,()[]<>"'"'" '\n')
1403
- EOF
1404
- }
1405
-
1406
1391
  # Fetch Jenkins build statuses for every branch in a multibranch job, in ONE
1407
1392
  # call, and return them as a JSON object keyed by DECODED branch name.
1408
1393
  #
@@ -2080,7 +2065,7 @@ rest_pr_to_state() {
2080
2065
  state: $state,
2081
2066
  draft: (.draft // false),
2082
2067
  url: (.html_url // ""),
2083
- mergeCommit: (.merge_commit_sha // ""), headSha: (.head.sha // ""), checks: "unknown" }
2068
+ mergeCommit: (.merge_commit_sha // ""), headSha: (.head.sha // ""), base: (.base.ref // ""), checks: "unknown" }
2084
2069
  '
2085
2070
  }
2086
2071
 
@@ -2239,7 +2224,6 @@ bb_lacks_issue_command() {
2239
2224
 
2240
2225
  # Cached capability state — empty until first call to bb_require_json.
2241
2226
  BB_CAP_CHECKED=""
2242
- BB_CAP_HAS_JSON=""
2243
2227
  BB_CAP_IDENTITY="" # "craftamap/0.6.0" or "quatico/1.2.3" or "unknown/<ver>"
2244
2228
  BB_CAP_PROBE_RC="" # the exit code `bb pr list --help --json` returned
2245
2229
  BB_CAP_PROBE_MATCH="" # the line that matched a rejection pattern, if one did
@@ -2349,7 +2333,6 @@ bb_require_json() {
2349
2333
 
2350
2334
  # Allow tests to skip this (their stubs may not implement --help)
2351
2335
  if [ -n "${PLOT_BB_SKIP_CAP_CHECK:-}" ]; then
2352
- BB_CAP_HAS_JSON=1
2353
2336
  BB_CAP_IDENTITY="stub/test"
2354
2337
  return 0
2355
2338
  fi
@@ -2357,7 +2340,6 @@ bb_require_json() {
2357
2340
  BB_CAP_IDENTITY="$(bb_identify)"
2358
2341
 
2359
2342
  if ! bb_test_json_support; then
2360
- BB_CAP_HAS_JSON=0
2361
2343
  # THE OBSERVATION FIRST, THE IDENTITY WHERE ONE IS KNOWN.
2362
2344
  #
2363
2345
  # The plan asked for the observation and for dropping the provenance CLAIM
@@ -2373,7 +2355,6 @@ bb_require_json() {
2373
2355
  die3 "bb ($BB_CAP_IDENTITY): bb pr list --help --json exited ${BB_CAP_PROBE_RC:-?}${BB_CAP_PROBE_MATCH:+, matched: $BB_CAP_PROBE_MATCH} — this bb does not support --json for PR commands"
2374
2356
  fi
2375
2357
 
2376
- BB_CAP_HAS_JSON=1
2377
2358
  return 0
2378
2359
  }
2379
2360
 
@@ -2626,8 +2607,6 @@ jira_curl() {
2626
2607
  # $1 = path (e.g. /rest/api/2/search/jql?...), remaining args appended to curl.
2627
2608
  # Config is assumed present — jira_require_config ran in the caller's shell.
2628
2609
  local path="$1"; shift
2629
- local base
2630
- base="$(tracker_base_url)"
2631
2610
  # -sS: quiet progress, but keep errors. -w writes the HTTP status on its own
2632
2611
  # line AFTER the body so the caller can split the two. --user does the Basic
2633
2612
  # base64 for us; the token never appears in argv of any child process here.
@@ -2635,7 +2614,7 @@ jira_curl() {
2635
2614
  --user "${JIRA_EMAIL}:${JIRA_API_TOKEN}" \
2636
2615
  -H 'Accept: application/json' \
2637
2616
  -w '\n%{http_code}' \
2638
- "$base$path" "$@"
2617
+ "$(tracker_base_url)$path" "$@"
2639
2618
  local rc=$?
2640
2619
  # JIRA IS COUNTED HERE AND NOT BY A WRAPPER, because it is reached through
2641
2620
  # `curl` rather than a CLI of its own — and shadowing `curl` would count every
@@ -2719,6 +2698,10 @@ jira_check() {
2719
2698
  printf '%s' "$body"
2720
2699
  }
2721
2700
 
2701
+ # jira_curl, then jira_check: the response body on stdout, or exit 3 with the
2702
+ # reason on stderr. Every Jira op asks through this pair and through nothing else.
2703
+ jira_ask() { local raw rc; raw="$(jira_curl "$@")"; rc=$?; jira_check "$raw" "$rc"; }
2704
+
2722
2705
  # --- pr-list truncation detection (#333) ------------------------------------
2723
2706
  #
2724
2707
  # `pr-list` returns a bulk page that two consumers (plot-fleet-scan.sh:474 and
@@ -3011,7 +2994,12 @@ plot_on_exit budget_memo_clear
3011
2994
  # account cannot be read still share one real budget, and dropping their lines
3012
2995
  # would under-count the machine — the failure this plan exists to remove. They
3013
2996
  # group together under one honest name instead.
2997
+ #
2998
+ # JIRA IS KEYED BY `jira_budget_account`, the key `budget_record_jira` writes,
2999
+ # and `PLOT_BUDGET_ACCOUNT` does not override it, because that writer reads no
3000
+ # override either.
3014
3001
  budget_account() {
3002
+ [ "${1:-}" != jira ] || { jira_budget_account; return; }
3015
3003
  if [ -n "${PLOT_BUDGET_ACCOUNT:-}" ]; then printf '%s\n' "$PLOT_BUDGET_ACCOUNT"; return; fi
3016
3004
  local who=''
3017
3005
  case "$1" in
@@ -3572,9 +3560,9 @@ case "$op" in
3572
3560
  # mergeCommit is what lets a caller ask "which release contains this?" —
3573
3561
  # `git tag --contains <sha>` answers exactly, where dates cannot. It is ""
3574
3562
  # for anything unmerged, which is the honest answer rather than a guess.
3575
- elif out="$(gh ${repo_args[@]+"${repo_args[@]}"} pr view "$ref" --json number,state,isDraft,url,mergeCommit,headRefOid,statusCheckRollup 2>"$HOST_ERR")"; then
3563
+ elif out="$(gh ${repo_args[@]+"${repo_args[@]}"} pr view "$ref" --json number,state,isDraft,url,mergeCommit,headRefOid,baseRefName,statusCheckRollup 2>"$HOST_ERR")"; then
3576
3564
  rm -f "$HOST_ERR"
3577
- jq -c "$CHECKS_OF"'{number:.number,state:.state,draft:.isDraft,url:.url,mergeCommit:(.mergeCommit.oid // ""),headSha:(.headRefOid // ""),checks:checks_of,checksSha:(.headRefOid // "")}' <<<"$out"
3565
+ jq -c "$CHECKS_OF"'{number:.number,state:.state,draft:.isDraft,url:.url,mergeCommit:(.mergeCommit.oid // ""),headSha:(.headRefOid // ""),base:(.baseRefName // ""),checks:checks_of,checksSha:(.headRefOid // "")}' <<<"$out"
3578
3566
  else
3579
3567
  err="$(cat "$HOST_ERR" 2>/dev/null)"; rm -f "$HOST_ERR"
3580
3568
  # REFUSED FOR RATE IS NOT ANSWERED. The budget gate above could not see
@@ -3611,7 +3599,7 @@ case "$op" in
3611
3599
  if [[ "$ref" =~ ^[0-9]+$ ]]; then
3612
3600
  if out="$(bb ${repo_args[@]+"${repo_args[@]}"} pr view "$ref" --json 2>"$HOST_ERR")"; then
3613
3601
  rm -f "$HOST_ERR"
3614
- jq -c '{number:.id,state:(if .state=="DECLINED" then "CLOSED" else .state end),draft:(.draft // false),url:.links.html.href,mergeCommit:(.merge_commit.hash // "")}' <<<"$out"
3602
+ jq -c '{number:.id,state:(if .state=="DECLINED" then "CLOSED" else .state end),draft:(.draft // false),url:.links.html.href,mergeCommit:(.merge_commit.hash // ""),base:(.destination.branch.name // "")}' <<<"$out"
3615
3603
  else
3616
3604
  err="$(cat "$HOST_ERR" 2>/dev/null)"; rm -f "$HOST_ERR"
3617
3605
  host_miss_or_fail "$err" '{"number":0,"state":"NONE","draft":false,"url":"","mergeCommit":""}' || exit $?
@@ -3662,7 +3650,7 @@ case "$op" in
3662
3650
  # costs no extra call.
3663
3651
  jq -c --arg b "$ref" '[.[] | select(.source.branch.name==$b)][0] // null
3664
3652
  | if .==null then {number:0,state:"NONE",draft:false,url:"",mergeCommit:""}
3665
- else {number:.id,state:(if .state=="DECLINED" then "CLOSED" else .state end),draft:(.draft // false),url:.links.html.href,mergeCommit:(.merge_commit.hash // "")} end' <<<"$out"
3653
+ else {number:.id,state:(if .state=="DECLINED" then "CLOSED" else .state end),draft:(.draft // false),url:.links.html.href,mergeCommit:(.merge_commit.hash // ""),base:(.destination.branch.name // "")} end' <<<"$out"
3666
3654
  else
3667
3655
  err="$(cat "$HOST_ERR" 2>/dev/null)"; rm -f "$HOST_ERR"
3668
3656
  host_miss_or_fail "$err" '{"number":0,"state":"NONE","draft":false,"url":"","mergeCommit":""}' || exit $?
@@ -3784,12 +3772,7 @@ case "$op" in
3784
3772
  # A lookup miss is an answer: no PR, so no merge commit. Anything else
3785
3773
  # is the question failing, and silence must not read as "carried
3786
3774
  # nothing" — the caller distinguishes the two by the exit code.
3787
- if [ -z "$err" ] || is_lookup_miss "$err"; then
3788
- :
3789
- else
3790
- echo "plot-host: $err" >&2
3791
- exit 3
3792
- fi
3775
+ miss_or_exit3 "$err"
3793
3776
  fi
3794
3777
  else
3795
3778
  bb_require_json
@@ -3800,12 +3783,7 @@ case "$op" in
3800
3783
  | map(.merge_commit.hash // empty) | first // empty' <<<"$out"
3801
3784
  else
3802
3785
  err="$(cat "$HOST_ERR" 2>/dev/null)"; rm -f "$HOST_ERR"
3803
- if [ -z "$err" ] || is_lookup_miss "$err"; then
3804
- :
3805
- else
3806
- echo "plot-host: $err" >&2
3807
- exit 3
3808
- fi
3786
+ miss_or_exit3 "$err"
3809
3787
  fi
3810
3788
  fi
3811
3789
  ;;
@@ -3860,6 +3838,12 @@ case "$op" in
3860
3838
  fi
3861
3839
  ;;
3862
3840
 
3841
+ pr-review)
3842
+ [ "$be" = "github" ] || { echo "plot-host: pr-review: bitbucket is not supported yet" >&2; exit 4; }
3843
+ out="$(gh pr view "${1:?pr-review needs a PR number}" --json headRefOid,comments)" && st="$(gh api "repos/{owner}/{repo}/commits/$(jq -r .headRefOid <<<"$out")/statuses")" \
3844
+ && jq -c --argjson st "$st" '{sha: .headRefOid, state: ([$st[] | select(.context == "plot/review")][0].state // "absent"), bypass: any(.comments[]?; .body | startswith("review-bypass:"))}' <<<"$out" \
3845
+ || { echo "plot-host: pr-review: the read failed" >&2; exit 3; } ;;
3846
+
3863
3847
  pr-create)
3864
3848
  title=""; body=""; base=""; head=""; draft=0
3865
3849
  while [ $# -gt 0 ]; do
@@ -3899,12 +3883,19 @@ case "$op" in
3899
3883
  *) die "pr-merge: unknown arg $1" ;;
3900
3884
  esac
3901
3885
  done
3902
- if [ "$be" = "github" ]; then
3903
- args=(pr merge "$num")
3904
- [ "$squash" = 1 ] && args+=(--squash) || args+=(--merge)
3905
- [ "$delbranch" = 1 ] && args+=(--delete-branch)
3906
- [ -n "$pin" ] && args+=(--match-head-commit "$pin")
3907
- gh "${args[@]}"
3886
+ if [ "$be" = "github" ] && [ -z "$pin" ]; then echo "plot-host: pr-merge: github needs --match-head <sha>; nothing was merged" >&2; exit 1
3887
+ elif [ "$be" = "github" ]; then
3888
+ # A declared `Merger app` merges, so a signed-in identity with
3889
+ # `bypass_mode: always` on the ruleset does not (#1730).
3890
+ # `plot-merger-token.mjs` refuses by name (exit 4) where the key is
3891
+ # malformed, unreadable, or names the same App id as `Writer app`, and
3892
+ # answers 5 with its one-line notice where no key is declared: the merge
3893
+ # then runs as the signed-in `gh` identity. The token goes straight into
3894
+ # GH_TOKEN — never into argv, a file, or a log line.
3895
+ merger_repo=$(gh repo view --json nameWithOwner --jq '.nameWithOwner' 2>/dev/null)
3896
+ merger_token=$(node "$here/plot-merger-token.mjs" "$merger_repo") || { mc=$?; [ "$mc" = 5 ] || exit "$mc"; }
3897
+ args=(pr merge "$num"); [ "$squash" = 1 ] && args+=(--squash) || args+=(--merge); [ "$delbranch" = 1 ] && args+=(--delete-branch)
3898
+ if [ -n "$merger_token" ]; then GH_TOKEN="$merger_token" gh "${args[@]}" --match-head-commit "$pin"; else gh "${args[@]}" --match-head-commit "$pin"; fi
3908
3899
  elif [ -n "$pin" ]; then echo "plot-host: pr-merge --match-head: bitbucket cannot pin a merge to a commit; nothing was merged" >&2; exit 4
3909
3900
  else
3910
3901
  args=(pr merge "$num")
@@ -4626,13 +4617,21 @@ case "$op" in
4626
4617
  # of them reproduces `an-outage-is-not-an-answer` — a board that says "no
4627
4618
  # issues" because it could not reach the tracker is stating a fact it does
4628
4619
  # not have.
4629
- limit=""
4620
+ limit=""; state="open"; since=""; page_token=""; paged=""
4630
4621
  while [ $# -gt 0 ]; do
4631
4622
  case "$1" in
4632
4623
  --limit) limit="${2:?}"; shift 2 ;;
4624
+ --state) state="${2:?}"; shift 2 ;;
4625
+ --since) since="${2:?}"; shift 2 ;;
4626
+ --page-token) page_token="${2:?}"; shift 2 ;;
4627
+ --paged) paged=1; shift ;;
4633
4628
  *) die "issue-list: unknown arg $1" ;;
4634
4629
  esac
4635
4630
  done
4631
+ # `--since` is spliced into a JQL string and a search qualifier, so its shape
4632
+ # is checked here: a value outside it is a usage error, never a query.
4633
+ [[ "$state" =~ ^(open|closed|inbox)$ ]] || die "issue-list: --state is open, closed or inbox, not '$state'"
4634
+ [ "$state" != closed ] || [[ "$since" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}(T[0-9]{2}:[0-9]{2}[0-9:.]*Z?)?$ ]] || die "issue-list: --state closed needs --since <iso>"
4636
4635
  limit_args=()
4637
4636
  [ -n "$limit" ] && limit_args=(--limit "$limit")
4638
4637
  # WHO LISTS THESE ISSUES IS ASKED ONCE, HERE, BEFORE THE ARMS — after the
@@ -4640,13 +4639,10 @@ case "$op" in
4640
4639
  # rather than as a tracker refusal. The arms below then dispatch on the
4641
4640
  # ANSWER, never on a second reading of the config.
4642
4641
  source_said="$(issue_source)" || exit 1
4643
- if [ "${source_said%%$'\t'*}" = "nobody" ]; then
4644
- # Exit 4, the code this op already documents as *this host cannot be
4645
- # asked at all* — a configuration a person fixes, not a call to retry.
4646
- # NOTHING HAS BEEN SPENT: no `gh`, no `bb`, no curl has run yet.
4647
- echo "plot-host: ${source_said#*$'\t'}" >&2
4648
- exit 4
4649
- fi
4642
+ # Exit 4, the code this op already documents as *this host cannot be
4643
+ # asked at all* — a configuration a person fixes, not a call to retry.
4644
+ # NOTHING HAS BEEN SPENT: no `gh`, no `bb`, no curl has run yet.
4645
+ [ "${source_said%%$'\t'*}" != nobody ] || { echo "plot-host: ${source_said#*$'\t'}" >&2; exit 4; }
4650
4646
  if [ "$source_said" = $'tracker\tjira' ]; then
4651
4647
  # Jira, resolved through the REST API — DISPATCHED ON `Tracker`, never on
4652
4648
  # `backend()`: a Bitbucket repo tracking in Jira is the normal enterprise
@@ -4671,31 +4667,57 @@ case "$op" in
4671
4667
  # AN UNDECLARED KEY LEAVES THE QUERY BYTE-IDENTICAL. `$scope` is empty,
4672
4668
  # the two halves rejoin exactly as they were written, and an upgrade
4673
4669
  # changes nothing for a repository that never set the key.
4674
- scope=""
4675
- if projects="$(tracker_projects)" && [ -n "$projects" ]; then
4670
+ scope=""; if projects="$(tracker_projects)" && [ -n "$projects" ]; then
4676
4671
  # `IN (A, B)`, never a trailing comma: paste joins N-1 separators over N
4677
4672
  # elements, so a one-element list — what adoption's seed writes — yields
4678
4673
  # `IN (A)` rather than `IN (A,)`.
4679
4674
  scope=" AND project IN ($(printf '%s' "$projects" | paste -sd, - | sed 's/,/, /g'))"
4680
4675
  fi
4676
+ # THE PERSON CLAUSE DROPS ONCE A PROJECT SCOPE EXISTS (D20): the open and
4677
+ # closed reads keep `assignee = currentUser()` only where `$scope` is
4678
+ # empty. The inbox read below keeps it unconditionally, and the scope too.
4679
+ person=""; [ -n "$scope" ] || person="assignee = currentUser() AND "
4681
4680
  # PLOT_JIRA_JQL STILL WINS OVER BOTH. Teams worked around this bug with
4682
4681
  # their own JQL; an override that stopped overriding would break exactly
4683
4682
  # the people who noticed the problem first.
4684
- jql="${PLOT_JIRA_JQL:-assignee = currentUser() AND resolution = EMPTY${scope} ORDER BY created DESC}"
4683
+ jql="${PLOT_JIRA_JQL:-${person}resolution = EMPTY${scope} ORDER BY created DESC}"
4685
4684
  # maxResults bounds ONE page. The inbox is small by construction (a
4686
- # person's open tickets), so no nextPageToken loop is needed; the caller's
4687
- # --limit caps it, else Jira's default page. v2 `search/jql` takes the same
4688
- # params as v3 but returns `summary`/`description` as plain strings.
4685
+ # person's open tickets), so its default stays 50; the caller's --limit
4686
+ # caps it. A paged read (`--paged`, and every closed read) asks at most
4687
+ # ISSUE_PAGE_ROWS per page and prints the next page's token. v2
4688
+ # `search/jql` takes the same params as v3 but returns
4689
+ # `summary`/`description` as plain strings.
4689
4690
  max="${limit:-50}"
4691
+ fields="summary,created,status,assignee,issuetype"
4692
+ if [ "$state" = closed ]; then
4693
+ # THE CLOSED READ REQUIRES `Ticket prefixes` AND READS NOT PLOT_JIRA_JQL.
4694
+ # An unscoped `resolved >=` query reads the whole instance — the hazard
4695
+ # `tracker_projects` measured for the open read — so with none declared
4696
+ # the read exits 4 before any curl. `jira_require_config` follows. The
4697
+ # closed read is always paged: a page is ISSUE_PAGE_ROWS, and the
4698
+ # TypeScript adapter walks the pages, so this arm holds no loop. JQL dates take
4699
+ # `yyyy-MM-dd` or `yyyy-MM-dd HH:mm`, so the ISO `since` is cut to the
4700
+ # shape it has: a date-only `since` sends the date alone. JQL takes no
4701
+ # offset, so Jira reads the time in the reader's profile zone. Its
4702
+ # person clause drops with the open read's (D20), same reason.
4703
+ [ -n "$scope" ] || { echo "plot-host: closed Jira issues need 'Ticket prefixes' declared; an unscoped resolved query reads the whole instance" >&2; exit 4; }
4704
+ when="${since:0:10} ${since:11:5}"; jql="resolved >= \"${when% }\"${scope} ORDER BY resolved DESC"
4705
+ fields="$fields,resolutiondate"; paged=1
4706
+ # THE D23 INBOX READ: always person-scoped, and project-scoped by `$scope`
4707
+ # like the open read, so *Waiting on you* shows the reader's own tickets of this repository's projects.
4708
+ elif [ "$state" = inbox ]; then jql="${PLOT_JIRA_JQL:-assignee = currentUser() AND resolution = EMPTY${scope} ORDER BY created DESC}"
4709
+ fi
4710
+ [ -z "$paged" ] || { max="${limit:-$ISSUE_PAGE_ROWS}"; [ "$max" -le "$ISSUE_PAGE_ROWS" ] || max="$ISSUE_PAGE_ROWS"; }
4711
+ token_args=(); [ -z "$page_token" ] || token_args=(--data-urlencode "nextPageToken=$page_token")
4690
4712
  # jq builds the query string so a JQL with spaces/quotes is encoded once,
4691
4713
  # not hand-escaped. --data-urlencode via curl -G keeps the token out of the
4692
4714
  # URL and the JQL correctly encoded.
4693
- raw="$(jira_curl "/rest/api/2/search/jql" \
4715
+ body="$(jira_ask "/rest/api/2/search/jql" \
4694
4716
  -G \
4695
4717
  --data-urlencode "jql=$jql" \
4696
- --data-urlencode "fields=summary,created,status" \
4697
- --data-urlencode "maxResults=$max")"; curl_rc=$?
4698
- body="$(jira_check "$raw" "$curl_rc")" || exit $?
4718
+ --data-urlencode "fields=$fields" \
4719
+ --data-urlencode "maxResults=$max" \
4720
+ ${token_args[@]+"${token_args[@]}"})" || exit $?
4699
4721
  # `number` is the Jira KEY (PROJ-123), a string — #447 taught the parser to
4700
4722
  # read that form. `url` is built from the base + /browse/<key>; Jira's
4701
4723
  # search payload carries no browse URL, and the base is ours to know
@@ -4707,14 +4729,20 @@ case "$op" in
4707
4729
  # substitutes for the other: the name is what a person reads, the
4708
4730
  # category is what a board groups on. A board grouping on the name
4709
4731
  # fragments across projects that spell the same stage differently.
4710
- printf '%s' "$body" | jq -c --arg base "$base" '.issues[]? | {
4732
+ # A closed row adds `closedAt`, the ticket's `resolutiondate`. A paged
4733
+ # read prints the next page's token as a LAST JSON line,
4734
+ # `{"nextPageToken":"…"}`, for the adapter to strip and loop on. An open
4735
+ # read without `--paged` prints no token line: the readers of that read
4736
+ # take every line as an issue.
4737
+ printf '%s' "$body" | jq -c --arg base "$base" --arg state "$state" --arg paged "$paged" '(.issues[]? | {
4711
4738
  number: .key,
4712
4739
  title: (.fields.summary // ""),
4713
4740
  url: ($base + "/browse/" + .key),
4714
4741
  createdAt: (.fields.created // ""),
4715
4742
  status: (.fields.status.name // ""),
4716
- statusCategory: (.fields.status.statusCategory.name // "")
4717
- }'
4743
+ statusCategory: (.fields.status.statusCategory.name // ""), assignees: ([.fields.assignee.emailAddress // .fields.assignee.accountId] | map(select(. != null)))
4744
+ } + (if .fields.issuetype.name then {type: .fields.issuetype.name} else {} end) + (if $state == "closed" then {closedAt: (.fields.resolutiondate // "")} else {} end)),
4745
+ (select($paged == "1") | (.nextPageToken // empty) | {nextPageToken: .})'
4718
4746
  elif [ "$be" = "github" ]; then
4719
4747
  # `gh issue list` — not `gh api /issues`. On GitHub every PR IS an issue,
4720
4748
  # so the REST endpoint returns both, and every open PR would arrive here
@@ -4727,21 +4755,29 @@ case "$op" in
4727
4755
  # a second literal would be a copy that a widened filter silently
4728
4756
  # outdates. `To Do` is the category because an open GitHub issue is
4729
4757
  # unstarted by the only vocabulary GitHub has.
4730
- gh_state="open"
4758
+ gh_state="$state"
4759
+ # A CLOSED READ IS THE SAME ARM with `closedAt` asked for and a search that
4760
+ # keeps what closed since `$since`. GitHub search has no close-date sort
4761
+ # (`sort:closed-desc` was measured ignored, 2026-10-13), so the adapter
4762
+ # sorts by `closedAt`.
4763
+ gh_json="number,title,url,createdAt,assignees,issueType"; search_args=()
4764
+ [ "$gh_state" = open ] || { gh_json+=",closedAt"; search_args=(--search "closed:>=$since"); }
4731
4765
  if out="$(gh issue list --state "$gh_state" ${limit_args[@]+"${limit_args[@]}"} \
4732
- --json number,title,url,createdAt 2>"$HOST_ERR")"; then
4766
+ ${search_args[@]+"${search_args[@]}"} --json "$gh_json" 2>"$HOST_ERR")"; then
4733
4767
  rm -f "$HOST_ERR"
4734
4768
  jq -c --arg status "$gh_state" \
4735
4769
  '.[] | {number:.number,title:.title,url:(.url // ""),createdAt:(.createdAt // ""),
4736
- status:$status,statusCategory:(if $status == "open" then "To Do" else "Done" end)}' <<<"$out"
4770
+ status:$status,statusCategory:(if $status == "open" then "To Do" else "Done" end),assignees:[.assignees[]?.login]} + (if .issueType.name? then {type:.issueType.name} else {} end)
4771
+ + (if $status == "closed" then {closedAt:(.closedAt // "")} else {} end)' <<<"$out"
4772
+ # `gh` pages by 100 inside ONE process and the wrapper records one call
4773
+ # per process, so each page past the first is recorded here.
4774
+ jq -r "[range(1; length / $ISSUE_PAGE_ROWS | ceil)] | .[]" <<<"$out" | while read -r _; do budget_record_call github github graphql; done
4737
4775
  else
4738
- err="$(cat "$HOST_ERR" 2>/dev/null)"; rm -f "$HOST_ERR"
4739
4776
  # NO empty-list fallback. `host_miss_or_fail` exists for a lookup whose
4740
4777
  # subject is absent — one PR that does not exist. A LIST has no absent
4741
4778
  # subject: if the call failed, the answer is unknown, and printing
4742
4779
  # nothing while exiting non-zero is what says so.
4743
- echo "plot-host: $err" >&2
4744
- exit 3
4780
+ gh_fail
4745
4781
  fi
4746
4782
  else
4747
4783
  # `bb issue list` — measured against bb 0.6.0. Three things the GitHub arm
@@ -4750,6 +4786,10 @@ case "$op" in
4750
4786
  # data; (2) it has no `--limit`, so the caller's bound is honoured HERE,
4751
4787
  # after parsing; (3) the list carries no per-issue URL, so `url` is "" —
4752
4788
  # the same answer the header documents for a host that omits it.
4789
+ #
4790
+ # A CLOSED READ IS EXIT 4: `bb issue list` prints no closing date, so there
4791
+ # is nothing honest to return. It runs before any `bb` command.
4792
+ [ "$state" = open ] || { echo "plot-host: bitbucket cannot list closed issues; bb prints no closing date" >&2; exit 4; }
4753
4793
  bb_assert_issue_version || exit $?
4754
4794
  # `--state new,open` is bb's own default for `issue list` and is what
4755
4795
  # "open tracker issues" means; stated explicitly so a bb default change
@@ -4791,25 +4831,17 @@ case "$op" in
4791
4831
  # neither is a Jira category. Empty says *this vocabulary has no word
4792
4832
  # for it*, which a board can render; inventing `Done` for WONTFIX
4793
4833
  # would file abandoned work beside finished work.
4794
- case "$state" in
4795
- NEW|OPEN) category="To Do" ;;
4796
- RESOLVED|CLOSED) category="Done" ;;
4797
- *) category="" ;;
4798
- esac
4799
4834
  # Drop the trailing reporter: bb prints three spaces then `by <name>`.
4800
4835
  title="$(sed -E 's/[[:space:]]{2,}by [^[:space:]].*$//' <<<"$rest")"
4801
4836
  # `url` is "" — bb issue list prints none; a consumer renders the number
4802
4837
  # as plain text, the rule the header states.
4803
- jq -cn --argjson number "$num" --arg title "$title" \
4804
- --arg status "$state" --arg category "$category" \
4805
- '{number:$number,title:$title,url:"",createdAt:"",
4806
- status:$status,statusCategory:$category}'
4838
+ jq -cn --argjson number "$num" --arg title "$title" --arg status "$state" \
4839
+ '{number:$number,title:$title,url:"",createdAt:"",status:$status,
4840
+ statusCategory:({NEW:"To Do",OPEN:"To Do",RESOLVED:"Done",CLOSED:"Done"}[$status] // "")}'
4807
4841
  count=$((count + 1))
4808
4842
  # Honour the caller's --limit HERE: bb has no --limit, so a bound the
4809
4843
  # caller asked for is enforced by the adapter after parsing (Done-when 7).
4810
- if [ -n "$limit" ] && [ "$count" -ge "$limit" ]; then
4811
- break
4812
- fi
4844
+ [ -z "$limit" ] || [ "$count" -lt "$limit" ] || break
4813
4845
  done <<<"$raw"
4814
4846
  fi
4815
4847
  ;;
@@ -4829,10 +4861,7 @@ case "$op" in
4829
4861
  # question with the same three answers and the same exit codes. A consumer
4830
4862
  # that maps 4 to `unsupported` needs no second table to read this op.
4831
4863
  source_said="$(issue_source)" || exit 1
4832
- if [ "${source_said%%$'\t'*}" = "nobody" ]; then
4833
- echo "plot-host: ${source_said#*$'\t'}" >&2
4834
- exit 4
4835
- fi
4864
+ [ "${source_said%%$'\t'*}" != nobody ] || { echo "plot-host: ${source_said#*$'\t'}" >&2; exit 4; }
4836
4865
  if [ "$source_said" = $'tracker\tjira' ]; then
4837
4866
  # Jira, dispatched on `Tracker` not `backend()` — the same rule issue-list
4838
4867
  # follows. `num` is a Jira KEY (PROJ-123), read off issue-list moments ago.
@@ -4846,9 +4875,8 @@ case "$op" in
4846
4875
  # adapter, so its absence (Jira answers 404) means the tracker moved under
4847
4876
  # the board. jira_check turns that 404 into exit 3 with empty stdout.
4848
4877
  jira_require_config
4849
- raw="$(jira_curl "/rest/api/2/issue/$num" \
4850
- -G --data-urlencode "fields=summary,description")"; curl_rc=$?
4851
- body_json="$(jira_check "$raw" "$curl_rc")" || exit $?
4878
+ body_json="$(jira_ask "/rest/api/2/issue/$num" \
4879
+ -G --data-urlencode "fields=summary,description")" || exit $?
4852
4880
  base="$(tracker_base_url)"
4853
4881
  printf '%s' "$body_json" | jq -c --arg base "$base" '{
4854
4882
  number: .key,
@@ -4861,7 +4889,6 @@ case "$op" in
4861
4889
  rm -f "$HOST_ERR"
4862
4890
  jq -c '{number:.number,title:(.title // ""),body:(.body // ""),url:(.url // "")}' <<<"$out"
4863
4891
  else
4864
- err="$(cat "$HOST_ERR" 2>/dev/null)"; rm -f "$HOST_ERR"
4865
4892
  # NO miss/fail split here, and that is deliberate. `host_miss_or_fail`
4866
4893
  # exists where an absent subject is a NORMAL answer — a branch with no
4867
4894
  # PR. An issue number reaching this op was read off `issue-list`
@@ -4869,8 +4896,7 @@ case "$op" in
4869
4896
  # means the tracker moved under the board. Both shapes exit non-zero
4870
4897
  # with the CLI's own words, so the caller says *could not be read*
4871
4898
  # rather than planning against an empty body.
4872
- echo "plot-host: $err" >&2
4873
- exit 3
4899
+ gh_fail
4874
4900
  fi
4875
4901
  else
4876
4902
  # `bb issue view <n>` — measured against bb 0.6.0. The output, once ANSI
@@ -4945,16 +4971,14 @@ case "$op" in
4945
4971
  # and Jira answers a transition to the state an issue already holds by
4946
4972
  # naming no such transition — which this reports as `no-target` rather than
4947
4973
  # as a failure.
4948
- key="${1:?issue-status needs an issue key}"; shift
4949
- want="${1:?issue-status needs a status}"; shift
4974
+ key="${1:?issue-status needs an issue key}"; want="${2:?issue-status needs a status}"
4950
4975
  [ "$(tracker_scheme)" = "jira" ] || exit 4
4951
4976
  jira_require_config
4952
4977
  # THE TRANSITION IS LOOKED UP, NEVER GUESSED. Jira transitions are per
4953
4978
  # workflow and per issue: the id for "In Progress" differs between projects
4954
4979
  # and the transition may not be available from the issue's current state at
4955
4980
  # all. A hardcoded id writes a status to the wrong column silently.
4956
- raw="$(jira_curl "/rest/api/2/issue/$key/transitions")"; curl_rc=$?
4957
- body_json="$(jira_check "$raw" "$curl_rc")" || exit $?
4981
+ body_json="$(jira_ask "/rest/api/2/issue/$key/transitions")" || exit $?
4958
4982
  tid="$(printf '%s' "$body_json" | jq -r --arg want "$want" \
4959
4983
  '[.transitions[]? | select((.name // "" | ascii_downcase) == ($want | ascii_downcase)
4960
4984
  or ((.to.name // "" | ascii_downcase) == ($want | ascii_downcase)))]
@@ -4967,13 +4991,29 @@ case "$op" in
4967
4991
  printf '%s\n' 'no-target'
4968
4992
  exit 0
4969
4993
  fi
4970
- raw="$(jira_curl "/rest/api/2/issue/$key/transitions" \
4971
- -X POST -H 'Content-Type: application/json' \
4972
- --data "$(jq -cn --arg id "$tid" '{transition:{id:$id}}')")"; curl_rc=$?
4973
- jira_check "$raw" "$curl_rc" >/dev/null || exit $?
4994
+ jira_ask "/rest/api/2/issue/$key/transitions" \
4995
+ -X POST -H 'Content-Type: application/json' \
4996
+ --data "$(jq -cn --arg id "$tid" '{transition:{id:$id}}')" >/dev/null || exit $?
4974
4997
  printf '%s\n' 'written'
4975
4998
  ;;
4976
4999
 
5000
+ issue-open)
5001
+ # THE SECOND WRITE TO A TRACKER: open one issue, and nothing else. NOT
5002
+ # IDEMPOTENT: the same call twice opens two issues, and this op never looks
5003
+ # for a duplicate, so the caller records what it opened. The connector
5004
+ # builds the request and reads the identifier out of the answer; this op
5005
+ # sends the one and prints the other.
5006
+ # jira <request-json> the POST /rest/api/2/issue body, sent
5007
+ # verbatim; prints Jira's JSON answer.
5008
+ # github-issues <title> <body> [--label <label>...]; prints the new
5009
+ # issue's address.
5010
+ # Exit 4, with the reason, for any other tracker.
5011
+ case "$(tracker_scheme)" in
5012
+ jira) jira_require_config; jira_ask /rest/api/2/issue -X POST -H 'Content-Type: application/json' --data-raw "${1:?issue-open needs a request}" || exit $? ;;
5013
+ github-issues) gh issue create --title "${1:?issue-open needs a title}" --body "${2-}" "${@:3}" 2>"$HOST_ERR" || gh_fail ;;
5014
+ *) echo "plot-host: issue-open answers for jira and github-issues only, not '$(tracker_scheme)'" >&2; exit 4 ;;
5015
+ esac ;;
5016
+
4977
5017
  pr-body)
4978
5018
  num="${1:?pr-body needs a PR number}"; shift
4979
5019
  body=""
@@ -5221,7 +5261,7 @@ case "$op" in
5221
5261
  # `perHour` IS null WHERE THERE IS NO SPAN TO DIVIDE BY — one line, or
5222
5262
  # several written inside one millisecond. An invented rate would be exactly
5223
5263
  # the dishonest cadence input this slice exists to remove.
5224
- _sr_connector=""; _sr_account=""; _sr_bucket=""
5264
+ _sr_connector="$be"; _sr_account=""; _sr_bucket=""
5225
5265
  while [ $# -gt 0 ]; do
5226
5266
  case "$1" in
5227
5267
  --connector) _sr_connector="${2:?}"; shift 2 ;;
@@ -5232,9 +5272,9 @@ case "$op" in
5232
5272
  done
5233
5273
  # Defaults name THIS connector and THIS account, which is what a caller
5234
5274
  # asking "what am I spending?" means. An explicit triple is for a caller
5235
- # asking about a connector it is not itself using.
5236
- [ -n "$_sr_connector" ] || _sr_connector="$be"
5237
- [ -n "$_sr_account" ] || _sr_account="$(budget_account "$be")"
5275
+ # asking about a connector it is not itself using. An omitted `--account`
5276
+ # names this machine's account on the connector asked.
5277
+ [ -n "$_sr_account" ] || _sr_account="$(budget_account "$_sr_connector")"
5238
5278
  # AN OMITTED `--bucket` MEANS EVERY BUCKET, which is what *what am I
5239
5279
  # spending?* asks. One connector meters several pools independently, and the
5240
5280
  # cadence this feeds is about how fast the ACCOUNT is going — it spends both,
@@ -5245,7 +5285,25 @@ case "$op" in
5245
5285
  '{connector:$connector,account:$account,bucket:$bucket} + .' <<<"$_sr_rate"
5246
5286
  ;;
5247
5287
 
5288
+ commit-status)
5289
+ # GITHUB AND BITBUCKET — the only two words `backend` above ever returns,
5290
+ # which already refused anything else before this case ran. Each backend's
5291
+ # logic lives in its own Node helper, never inline here —
5292
+ # `plot-commit-status.mjs` holds the GitHub App JWT/installation-token
5293
+ # exchange; `plot-bitbucket-commit-status.mjs` holds the Bitbucket state
5294
+ # mapping and Basic-auth build-status write, given a workspace/repo slug
5295
+ # parsed here from `origin` (never from `bb`, which would mean asking
5296
+ # whichever identity is signed in on this machine) — `.git` is stripped
5297
+ # before capturing the slug, not inside a trailing optional group, or a
5298
+ # greedy match absorbs it into the slug itself. A port after the host
5299
+ # (`ssh://git@altssh.bitbucket.org:443/ws/repo`) is dropped first, or the
5300
+ # `:` before it reads `443` as the workspace.
5301
+ [ "$be" = "github" ] || { node "$here/plot-bitbucket-commit-status.mjs" "$(git config --get remote.origin.url 2>/dev/null | sed -E 's#\.git$##; s#(bitbucket\.org):[0-9]+/#\1/#' | sed -nE 's#^.*bitbucket\.org[:/]([^/]+)/(.+)$#\1/\2#p')" "$@" || exit $?; exit 0; }
5302
+ node "$here/plot-commit-status.mjs" --check "$@" || exit $?
5303
+ node "$here/plot-commit-status.mjs" --repo "$(gh repo view --json nameWithOwner --jq '.nameWithOwner' 2>/dev/null)" "$@" || exit $?
5304
+ ;;
5305
+
5248
5306
  *)
5249
- die "unknown op '$op' (backend|default-branch|pr-state|pr-create|pr-merge|pr-list|issue-list|issue-view|issue-status|pr-body|rate-limit|limit|ci-limit|spend-rate)"
5307
+ die "unknown op '$op' (backend|default-branch|pr-state|pr-create|pr-merge|pr-list|issue-list|issue-view|issue-status|issue-open|pr-body|pr-review|rate-limit|limit|ci-limit|spend-rate|commit-status)"
5250
5308
  ;;
5251
5309
  esac