@plot-pm/board 0.23.1 → 0.24.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/dist/board-server.mjs +226 -218
- package/package.json +3 -3
- package/plot-fleet-scan.sh +25 -5184
- package/plot-host.sh +97 -93
- package/plot-monitor-subject.sh +3 -3
package/plot-host.sh
CHANGED
|
@@ -111,22 +111,28 @@
|
|
|
111
111
|
# (exit 0) where none merged. The same query
|
|
112
112
|
# `pr-merge-commit` runs. EXIT 3 is the question
|
|
113
113
|
# failing.
|
|
114
|
-
# pr-review <number> one JSON line `{"sha","state","bypass"}`:
|
|
115
|
-
# head sha, the newest `plot/review`
|
|
116
|
-
# (`success|failure|pending|error`,
|
|
117
|
-
#
|
|
118
|
-
#
|
|
114
|
+
# pr-review <number> one JSON line `{"sha","state","description","time","bypass"}`:
|
|
115
|
+
# the PR's head sha, the newest `plot/review`
|
|
116
|
+
# status on it (`success|failure|pending|error`,
|
|
117
|
+
# or `absent`), that status's description and
|
|
118
|
+
# time (both `""` where state is `absent`), and
|
|
119
|
+
# whether a comment starts `review-bypass:`.
|
|
120
|
+
# Bitbucket reads the same state words from the
|
|
119
121
|
# `plot/review` commit status (SUCCESSFUL,
|
|
120
|
-
# FAILED, INPROGRESS, STOPPED)
|
|
121
|
-
#
|
|
122
|
+
# FAILED, INPROGRESS, STOPPED), its
|
|
123
|
+
# `description`, and its `updated_on` as the
|
|
124
|
+
# time — `commit-status` writes that status
|
|
125
|
+
# through `plot-bitbucket-commit-status.mjs`.
|
|
126
|
+
# EXIT 3 is the question failing.
|
|
122
127
|
# pr-create --title T [--body B] [--base BR] [--head BR] [--draft]
|
|
123
128
|
# create a PR, print its URL
|
|
124
129
|
# pr-merge <number> [--squash] [--delete-branch] --match-head <sha>
|
|
130
|
+
# merge the PR. --match-head is
|
|
125
131
|
# mandatory on every backend. bitbucket
|
|
126
132
|
# re-reads the head before merging; a
|
|
127
133
|
# mismatch refuses `head-moved` (exit 1).
|
|
128
134
|
# pr-ready <number> take a PR out of draft
|
|
129
|
-
#
|
|
135
|
+
# pr-close <number> close a PR unmerged (bitbucket: decline)
|
|
130
136
|
# pr-list [--state open|merged|closed|all|settled] [--limit N] [--rich|--rich-open]
|
|
131
137
|
# settled is merged+declined on bitbucket (no
|
|
132
138
|
# open sweep) and --state all on github, which
|
|
@@ -470,6 +476,9 @@
|
|
|
470
476
|
# issue-comment <number> <marker> <body> (github)
|
|
471
477
|
# edits the comment holding <marker>, else posts
|
|
472
478
|
# one; an empty <marker> always posts, not idempotent.
|
|
479
|
+
# issue-comment-read <number> <marker> (github) prints the body of
|
|
480
|
+
# the comment holding <marker>, or nothing where
|
|
481
|
+
# none does. The plan-state write's one read-back.
|
|
473
482
|
# issue-list --label <label> keeps open issues carrying the label (github
|
|
474
483
|
# only; exit 4 on Bitbucket and on Jira).
|
|
475
484
|
# issue-list --title-has <text> keeps open issues whose title contains <text>,
|
|
@@ -668,27 +677,20 @@ host_err() { err="$(cat "$HOST_ERR" 2>/dev/null)"; rm -f "$HOST_ERR"; }
|
|
|
668
677
|
|
|
669
678
|
# THE ONE MARKER LOOKUP, shared by `pr-comment` and `issue-comment` — GitHub's
|
|
670
679
|
# REST comments endpoint is `issues/$num/comments` for both, since a PR is an
|
|
671
|
-
# issue under the hood. Prints the id of the comment holding `$2` (a
|
|
672
|
-
# substring),
|
|
673
|
-
#
|
|
674
|
-
#
|
|
675
|
-
# never mistaken for this script's own prior post. Prints empty on no match.
|
|
676
|
-
#
|
|
677
|
-
# SCOPED TO THE LOGIN `gh api user` ANSWERS for the token this call writes
|
|
678
|
-
# with (`host.ts:358`), asked once per lookup. Not `budget_account`: it reads
|
|
679
|
-
# `hosts.yml` or `PLOT_BUDGET_ACCOUNT`, and neither names the author when
|
|
680
|
-
# `GH_TOKEN` is set or the account is a grouping name, so every lookup missed
|
|
681
|
-
# and posted a new comment.
|
|
682
|
-
#
|
|
683
|
-
# NO LOGIN, NO SCOPE. When `gh api user` fails or answers no valid login (an
|
|
684
|
-
# App installation token gets 403 there), the match falls back to the marker
|
|
685
|
-
# alone, as it was before #2661. A comment with no `user` field cannot be
|
|
686
|
-
# attributed and also matches on the marker alone.
|
|
680
|
+
# issue under the hood. Prints the id of the oldest comment holding `$2` (a
|
|
681
|
+
# substring), whatever its author, or nothing. The marker alone decides: a
|
|
682
|
+
# lookup scoped to the writer's login posted a second comment whenever another
|
|
683
|
+
# account (a person's machine, fleetd's token) wrote the same marked comment.
|
|
687
684
|
#
|
|
688
685
|
# A FAILED LISTING EXITS 3 THROUGH `gh_fail`, same as a failed edit. `set -o
|
|
689
686
|
# pipefail` (above) makes the pipeline's exit code `gh api`'s own, so a lookup
|
|
690
687
|
# that cannot be read never falls through to "no marker found, post new".
|
|
691
|
-
gh_marker_comment_id() { gh api --paginate "repos/{owner}/{repo}/issues/$1/comments" 2>"$HOST_ERR" | jq -rs --arg m "$2"
|
|
688
|
+
gh_marker_comment_id() { gh api --paginate "repos/{owner}/{repo}/issues/$1/comments" 2>"$HOST_ERR" | jq -rs --arg m "$2" '[.[][] | select(.body | contains($m))][0].id // empty'; }
|
|
689
|
+
|
|
690
|
+
# EDITS THE COMMENT `$1` HOLDS, OR POSTS `$4` TO `$3` ON `$2` (`issue` or
|
|
691
|
+
# `pr`) — shared by `issue-comment` and `pr-comment`, whose tails differed
|
|
692
|
+
# only in that one word.
|
|
693
|
+
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; }
|
|
692
694
|
|
|
693
695
|
# Exit 3 — reserved for "the op itself cannot proceed", distinct from `die`'s
|
|
694
696
|
# generic 1. A Jenkins overlay with no instance to ask is such a case: a config
|
|
@@ -703,8 +705,8 @@ CHECKS_OF='def ck: (.conclusion // "") as $k | (.status // "") as $s | (if $s !=
|
|
|
703
705
|
if $k != "" and ($s|IN("","COMPLETED")) then (if ($k|IN("SUCCESS","NEUTRAL","SKIPPED")) then "ok" else "bad" end)
|
|
704
706
|
elif ($w|IN("","QUEUED","IN_PROGRESS","WAITING","REQUESTED","PENDING","EXPECTED")) then "wait"
|
|
705
707
|
elif $s == "" and $w == "SUCCESS" then "ok" else "bad" end;
|
|
706
|
-
def
|
|
707
|
-
|
|
708
|
+
def colour_of($r): if ($r|length) == 0 then "none" elif any($r[]; ck == "bad") then "failing" elif any($r[]; ck == "wait") then "pending" else "green" end;
|
|
709
|
+
def checks_of: colour_of(.statusCheckRollup // []); def ci_checks_of: colour_of([.statusCheckRollup[]? | select((.context // .name // "") != "plot/review")]);'
|
|
708
710
|
|
|
709
711
|
# THE ONE FOLD of a PR's mergeability into a word, for `pr-list --rich` and both
|
|
710
712
|
# `pr-state` transports. GraphQL says `mergeable` CONFLICTING|MERGEABLE|UNKNOWN
|
|
@@ -857,15 +859,11 @@ pr_list_failed() { # $1=stderr text
|
|
|
857
859
|
# NO REPAIR NAMED, AND THAT IS THE ANSWER. A burst refusal clears in
|
|
858
860
|
# seconds and nothing is broken, so `$cli auth login` here would send a
|
|
859
861
|
# reader to fix a login that is already fine. The decision is the wait.
|
|
860
|
-
|
|
861
|
-
echo " Nothing is wrong and nothing needs fixing: this limit bounds calls at" >&2
|
|
862
|
-
echo " once, not per hour. Retry shortly, with fewer at a time." >&2
|
|
862
|
+
printf '%s\n' "plot-host: pr-list: host refused a burst — ${err:-the host refused the request and said nothing}" " Nothing is wrong and nothing needs fixing: this limit bounds calls at" " once, not per hour. Retry shortly, with fewer at a time." >&2
|
|
863
863
|
exit 6
|
|
864
864
|
;;
|
|
865
865
|
throttled)
|
|
866
|
-
|
|
867
|
-
echo " The window's quota is spent. Wait for the reset the message names," >&2
|
|
868
|
-
echo " or run against an account with quota left. No login will help." >&2
|
|
866
|
+
printf '%s\n' "plot-host: pr-list: host throttled — ${err:-the host refused the request and said nothing}" " The window's quota is spent. Wait for the reset the message names," " or run against an account with quota left. No login will help." >&2
|
|
869
867
|
exit 5
|
|
870
868
|
;;
|
|
871
869
|
timeout)
|
|
@@ -873,9 +871,7 @@ pr_list_failed() { # $1=stderr text
|
|
|
873
871
|
# 504 means the server took too long, not that the credential is bad, so
|
|
874
872
|
# `host_repair`'s `gh auth login` would send a reader to fix a login
|
|
875
873
|
# that was never broken. The decision is to ask again, not to log in.
|
|
876
|
-
|
|
877
|
-
echo " Nothing is wrong with the login: the server took too long to answer." >&2
|
|
878
|
-
echo " The next refresh asks again." >&2
|
|
874
|
+
printf '%s\n' "plot-host: pr-list: host timed out — ${err:-the host took too long and said nothing}" " Nothing is wrong with the login: the server took too long to answer." " The next refresh asks again." >&2
|
|
879
875
|
exit 3
|
|
880
876
|
;;
|
|
881
877
|
esac
|
|
@@ -1897,10 +1893,7 @@ jenkins_instance() {
|
|
|
1897
1893
|
# only a person can fix, and deliberately NOT exit 4: a `CI: jenkins` repository
|
|
1898
1894
|
# CAN be asked about builds, it just has not said where.
|
|
1899
1895
|
jenkins_no_instance() {
|
|
1900
|
-
|
|
1901
|
-
echo " Add a 'Jenkins instance' key to the ## Plot Config section of CLAUDE.md," >&2
|
|
1902
|
-
echo " naming the instance \`jen\` knows, or set JENKINS_INSTANCE." >&2
|
|
1903
|
-
echo " Or drop the 'CI: jenkins' key to read build status from the git host." >&2
|
|
1896
|
+
printf '%s\n' "plot-host: CI is jenkins but no Jenkins instance is configured" " Add a 'Jenkins instance' key to the ## Plot Config section of CLAUDE.md," " naming the instance \`jen\` knows, or set JENKINS_INSTANCE." " Or drop the 'CI: jenkins' key to read build status from the git host." >&2
|
|
1904
1897
|
exit 3
|
|
1905
1898
|
}
|
|
1906
1899
|
|
|
@@ -2246,13 +2239,9 @@ bb_state_row() {
|
|
|
2246
2239
|
ci_unaskable() { # $1 = the op's name, $2 = the CI word (may be empty)
|
|
2247
2240
|
local ci_word="${2:-}"
|
|
2248
2241
|
if [ -z "$ci_word" ] || [ "$ci_word" = none ]; then
|
|
2249
|
-
|
|
2250
|
-
echo " Add a 'CI' key to the ## Plot Config section of CLAUDE.md naming the" >&2
|
|
2251
|
-
echo " system that builds this repository — \`github-actions\` or \`jenkins\`." >&2
|
|
2242
|
+
printf '%s\n' "plot-host: $1 — this repository declares no CI system, so there is nothing to ask" " Add a 'CI' key to the ## Plot Config section of CLAUDE.md naming the" " system that builds this repository — \`github-actions\` or \`jenkins\`." >&2
|
|
2252
2243
|
else
|
|
2253
|
-
|
|
2254
|
-
echo " Plot answers this op for \`github-actions\` and \`jenkins\`. An unknown" >&2
|
|
2255
|
-
echo " system cannot be asked, which is not the same as having no runs." >&2
|
|
2244
|
+
printf '%s\n' "plot-host: $1 — no connector for CI system '$ci_word'" " Plot answers this op for \`github-actions\` and \`jenkins\`. An unknown" " system cannot be asked, which is not the same as having no runs." >&2
|
|
2256
2245
|
fi
|
|
2257
2246
|
exit 4
|
|
2258
2247
|
}
|
|
@@ -2579,7 +2568,7 @@ rest_pr_to_state() {
|
|
|
2579
2568
|
state: $state,
|
|
2580
2569
|
draft: (.draft // false),
|
|
2581
2570
|
url: (.html_url // ""),
|
|
2582
|
-
mergeCommit: (.merge_commit_sha // ""), headSha: (.head.sha // ""), base: (.base.ref // ""), checks: "unknown", mergeable: mergeable_of,
|
|
2571
|
+
mergeCommit: (.merge_commit_sha // ""), head: (.head.ref // ""), headSha: (.head.sha // ""), base: (.base.ref // ""), checks: "unknown", mergeable: mergeable_of,
|
|
2583
2572
|
mergedAt: (.merged_at // "") }
|
|
2584
2573
|
'
|
|
2585
2574
|
}
|
|
@@ -3109,10 +3098,7 @@ jira_require_config() {
|
|
|
3109
3098
|
[ -n "$(tracker_base_url)" ] || die3 "Tracker is jira but no base URL is configured (write 'Tracker: jira https://your.atlassian.net' or set PLOT_JIRA_BASE_URL)"
|
|
3110
3099
|
jira_load_env_file
|
|
3111
3100
|
if [ -z "${JIRA_EMAIL:-}" ] || [ -z "${JIRA_API_TOKEN:-}" ]; then
|
|
3112
|
-
|
|
3113
|
-
echo " Create a token at https://id.atlassian.com/manage-profile/security/api-tokens" >&2
|
|
3114
|
-
echo " then export JIRA_EMAIL=<your account email> and JIRA_API_TOKEN=<the token>," >&2
|
|
3115
|
-
echo " or put both in this repository's .env (which .gitignore already excludes)." >&2
|
|
3101
|
+
printf '%s\n' "plot-host: Jira needs JIRA_EMAIL and JIRA_API_TOKEN in the environment — an unauthenticated Jira must not read as an empty inbox" " Create a token at https://id.atlassian.com/manage-profile/security/api-tokens" " then export JIRA_EMAIL=<your account email> and JIRA_API_TOKEN=<the token>," " or put both in this repository's .env (which .gitignore already excludes)." >&2
|
|
3116
3102
|
exit 3
|
|
3117
3103
|
fi
|
|
3118
3104
|
}
|
|
@@ -3958,6 +3944,8 @@ be="$(backend)" || exit $?
|
|
|
3958
3944
|
# emptiness is the honest value — there is no route where there is no fork.
|
|
3959
3945
|
route=""
|
|
3960
3946
|
[ "$be" = "github" ] && route="$(gh_route "$op")"
|
|
3947
|
+
# THE HOST CLI FOR OPS WHOSE TWO ARMS DIFFER ONLY IN ITS NAME.
|
|
3948
|
+
cli=gh; [ "$be" = "github" ] || cli=bb
|
|
3961
3949
|
|
|
3962
3950
|
case "$op" in
|
|
3963
3951
|
backend)
|
|
@@ -4096,9 +4084,9 @@ case "$op" in
|
|
|
4096
4084
|
# mergeCommit is what lets a caller ask "which release contains this?" —
|
|
4097
4085
|
# `git tag --contains <sha>` answers exactly, where dates cannot. It is ""
|
|
4098
4086
|
# for anything unmerged, which is the honest answer rather than a guess.
|
|
4099
|
-
elif out="$(gh ${repo_args[@]+"${repo_args[@]}"} pr view "$ref" --json number,state,isDraft,url,mergeCommit,headRefOid,baseRefName,statusCheckRollup,mergeable,mergeStateStatus,mergedAt 2>"$HOST_ERR")"; then
|
|
4087
|
+
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
|
|
4100
4088
|
rm -f "$HOST_ERR"
|
|
4101
|
-
jq -c "$CHECKS_OF$MERGEABLE_OF"'{number:.number,state:.state,draft:.isDraft,url:.url,mergeCommit:(.mergeCommit.oid // ""),headSha:(.headRefOid // ""),base:(.baseRefName // ""),checks:checks_of,checksSha:(.headRefOid // ""),mergeable:mergeable_of,mergedAt:(.mergedAt // "")}' <<<"$out"
|
|
4089
|
+
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,checksSha:(.headRefOid // ""),mergeable:mergeable_of,mergedAt:(.mergedAt // "")}' <<<"$out"
|
|
4102
4090
|
else
|
|
4103
4091
|
host_err
|
|
4104
4092
|
# REFUSED FOR RATE IS NOT ANSWERED. The budget gate above could not see
|
|
@@ -4404,7 +4392,7 @@ case "$op" in
|
|
|
4404
4392
|
|| die3 "pr-review: the read failed"
|
|
4405
4393
|
exit 0; fi
|
|
4406
4394
|
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")" \
|
|
4407
|
-
&& jq -c --argjson st "$st" '
|
|
4395
|
+
&& jq -c --argjson st "$st" '[$st[] | select(.context == "plot/review")][0] as $m | {sha: .headRefOid, state: ($m.state // "absent"), description: ($m.description // ""), time: ($m.updated_at // ""), bypass: any(.comments[]?; .body | startswith("review-bypass:"))}' <<<"$out" \
|
|
4408
4396
|
|| die3 "pr-review: the read failed" ;;
|
|
4409
4397
|
|
|
4410
4398
|
pr-create)
|
|
@@ -4461,21 +4449,24 @@ case "$op" in
|
|
|
4461
4449
|
fi
|
|
4462
4450
|
;;
|
|
4463
4451
|
|
|
4464
|
-
pr-ready)
|
|
4465
|
-
# TAKE A PR OUT OF DRAFT
|
|
4466
|
-
#
|
|
4467
|
-
#
|
|
4452
|
+
pr-ready|pr-close)
|
|
4453
|
+
# TAKE A PR OUT OF DRAFT (`pr-ready`) OR CLOSE IT WITHOUT MERGING (`pr-close`;
|
|
4454
|
+
# `bb pr close` declines). One call each, and the ONE place that talks to the
|
|
4455
|
+
# host CLI keeps that property — `plot-approve.sh` needs the first before it
|
|
4456
|
+
# merges, and the repair arm closes the fix and revert PRs of an episode with
|
|
4457
|
+
# the second; reaching for `gh` there would put a second host caller in the
|
|
4458
|
+
# estate.
|
|
4468
4459
|
#
|
|
4469
4460
|
# Bitbucket's support depends on the bb CLI version (see the caveat list at
|
|
4470
4461
|
# the top of this file, which already names `--draft`/`--ready`), so a
|
|
4471
4462
|
# failure here surfaces as the CLI's own message rather than being
|
|
4472
4463
|
# swallowed: the caller must be able to tell *the host refused* from *the
|
|
4473
|
-
# PR is now ready*.
|
|
4474
|
-
num="${1
|
|
4475
|
-
if [ "$
|
|
4476
|
-
gh pr ready "$num"
|
|
4477
|
-
else
|
|
4464
|
+
# PR is now ready or closed*.
|
|
4465
|
+
num="${1:?$op needs a PR number}"
|
|
4466
|
+
if [ "$op" = "pr-ready" ] && [ "$cli" = "bb" ]; then
|
|
4478
4467
|
bb pr update "$num" --ready
|
|
4468
|
+
else
|
|
4469
|
+
"$cli" pr "${op#pr-}" "$num"
|
|
4479
4470
|
fi
|
|
4480
4471
|
;;
|
|
4481
4472
|
|
|
@@ -4802,15 +4793,14 @@ case "$op" in
|
|
|
4802
4793
|
| jq -c "$CHECKS_OF$MERGEABLE_OF"'.[] | {
|
|
4803
4794
|
number:.number, title:.title, state:.state, head:.headRefName,
|
|
4804
4795
|
draft:.isDraft,
|
|
4805
|
-
checks:checks_of,
|
|
4806
|
-
mergeable:mergeable_of,
|
|
4796
|
+
checks:checks_of, mergeable:mergeable_of,
|
|
4807
4797
|
review:(.reviewDecision // ""),
|
|
4808
4798
|
url:.url,
|
|
4809
4799
|
updatedAt:(.updatedAt // ""),headSha:(.headRefOid // ""),checksSha:(.headRefOid // ""),mergedAt:(.mergedAt // ""),
|
|
4810
4800
|
author:(.author.login // ""),
|
|
4811
4801
|
failing_checks:[
|
|
4812
|
-
.statusCheckRollup[]? | select(ck == "bad") | (.name // .context // "")] | map(select(. != ""))
|
|
4813
|
-
}'
|
|
4802
|
+
.statusCheckRollup[]? | select(ck == "bad") | (.name // .context // "")] | map(select(. != "")), ciChecks:ci_checks_of
|
|
4803
|
+
} + (([.statusCheckRollup[]? | select((.context // "") == "plot/review")] | .[0]) as $pr | if $pr == null then {plotReview:"absent"} else {plotReview:($pr.state // "" | ascii_downcase), plotReviewSha:(.headRefOid // ""), plotReviewAt:($pr.startedAt // "")} end)'
|
|
4814
4804
|
fi
|
|
4815
4805
|
else
|
|
4816
4806
|
# `isDraft`, `url` AND `updatedAt` TRAVEL ON THE PLAIN ARM TOO, and they
|
|
@@ -5034,9 +5024,7 @@ case "$op" in
|
|
|
5034
5024
|
# `CI: github-actions` on a Bitbucket remote has declared something
|
|
5035
5025
|
# `gh` cannot reach — an unaskable configuration, not an empty history.
|
|
5036
5026
|
if [ "$be" != "github" ]; then
|
|
5037
|
-
|
|
5038
|
-
echo " \`gh run list\` reads the runs of the repository its remote names," >&2
|
|
5039
|
-
echo " so there is no GitHub repository here to ask about." >&2
|
|
5027
|
+
printf '%s\n' "plot-host: runs — CI is github-actions but the git host is '$be'" " \`gh run list\` reads the runs of the repository its remote names," " so there is no GitHub repository here to ask about." >&2
|
|
5040
5028
|
exit 4
|
|
5041
5029
|
fi
|
|
5042
5030
|
gh run list --branch "$branch" --limit "$limit" \
|
|
@@ -5151,9 +5139,7 @@ case "$op" in
|
|
|
5151
5139
|
# SAME SECOND CONDITION AS `runs`: `gh run list` reads the repository its
|
|
5152
5140
|
# remote names, so `CI: github-actions` on a non-GitHub remote names runs
|
|
5153
5141
|
# that cannot be reached from here.
|
|
5154
|
-
|
|
5155
|
-
echo " \`gh run list\` reads the runs of the repository its remote names," >&2
|
|
5156
|
-
echo " so there is no GitHub repository here to ask about." >&2
|
|
5142
|
+
printf '%s\n' "plot-host: $op — CI is github-actions but the git host is '$be'" " \`gh run list\` reads the runs of the repository its remote names," " so there is no GitHub repository here to ask about." >&2
|
|
5157
5143
|
exit 4
|
|
5158
5144
|
fi
|
|
5159
5145
|
# From here the CI system is `github-actions` and the git host is GitHub;
|
|
@@ -5207,6 +5193,23 @@ case "$op" in
|
|
|
5207
5193
|
'$match[0] + {jobs: [$run[0].jobs[] | {conclusion, startedAt, completedAt, steps: [(.steps // [])[].conclusion]}]}' || exit 4
|
|
5208
5194
|
;;
|
|
5209
5195
|
|
|
5196
|
+
rerun-failed|rerun-all)
|
|
5197
|
+
# `rerun-failed` re-runs the failed jobs of every concluded-red run for ONE
|
|
5198
|
+
# sha; `rerun-all` re-runs every job of every run for it, whatever each
|
|
5199
|
+
# concluded. GitHub resets a re-run run's `startedAt` to the new attempt.
|
|
5200
|
+
# Exit 4 is *cannot be asked*: any CI but GitHub Actions on GitHub, and a
|
|
5201
|
+
# failing `gh`. Exit 1 is `rerun-all` matching no run for the sha: nothing
|
|
5202
|
+
# was re-run, so a caller waiting for a new attempt would wait forever.
|
|
5203
|
+
branch="${1:?$op needs a branch}"; sha="${2:?$op needs a sha}"
|
|
5204
|
+
[ "$(ci_scheme)" = github-actions ] && [ "$be" = github ] || exit 4
|
|
5205
|
+
# Empty for `rerun-all`; non-empty, and so `--failed` below, for `rerun-failed`.
|
|
5206
|
+
_failed_only=${op#rerun-all}
|
|
5207
|
+
_ids=$(gh run list --branch "$branch" --limit 50 --json headSha,conclusion,databaseId \
|
|
5208
|
+
--jq ".[] | select(.headSha == \"$sha\" and (\"$_failed_only\" == \"\" or .conclusion == \"failure\")) | .databaseId" 2>/dev/null) || exit 4
|
|
5209
|
+
[ -n "$_ids$_failed_only" ] || exit 1
|
|
5210
|
+
for _id in $_ids; do gh run rerun "$_id" ${_failed_only:+--failed} >/dev/null 2>&1 || exit 4; done
|
|
5211
|
+
;;
|
|
5212
|
+
|
|
5210
5213
|
issue-list)
|
|
5211
5214
|
# Open tracker issues — the board's inbox, and READ-ONLY in both
|
|
5212
5215
|
# directions. Nothing here writes a label, an assignee or a close: the
|
|
@@ -5466,7 +5469,7 @@ case "$op" in
|
|
|
5466
5469
|
gh_json="number,title,url,createdAt,assignees,issueType"; search_args=(); ask_state="$gh_state"
|
|
5467
5470
|
[ -z "$label" ] || search_args=(--label "$label")
|
|
5468
5471
|
if [ "$gh_state" = changed ]; then gh_json+=",updatedAt,state,closedAt"; ask_state=all; search_args+=(--search "updated:>=$since")
|
|
5469
|
-
elif [ "$gh_state" != open ]; then gh_json+=",closedAt"; search_args+=(--search "closed:>=$since")
|
|
5472
|
+
elif [ "$gh_state" != open ]; then gh_json+=",closedAt,labels"; search_args+=(--search "closed:>=$since")
|
|
5470
5473
|
# TITLE SEARCH NARROWS, IT DOES NOT REPLACE THE LABEL FILTER: both are
|
|
5471
5474
|
# qualifiers `gh` combines in one `--search` string, so a backlog's
|
|
5472
5475
|
# label stays the safety net while the title cuts the read to the one PR
|
|
@@ -5486,7 +5489,7 @@ case "$op" in
|
|
|
5486
5489
|
{number:.number,title:.title,url:(.url // ""),createdAt:(.createdAt // ""),
|
|
5487
5490
|
status:$actual,statusCategory:(if $actual == "open" then "To Do" else "Done" end),assignees:[.assignees[]?.login]}
|
|
5488
5491
|
+ (if .updatedAt then {updatedAt:.updatedAt} else {} end) + (if .issueType.name? then {type:.issueType.name} else {} end)
|
|
5489
|
-
+ (if $actual == "closed" then {closedAt:(.closedAt // "")} else {} end)' <<<"$out"
|
|
5492
|
+
+ (if $actual == "closed" then {closedAt:(.closedAt // "")} else {} end) + (if .labels then {labels:[.labels[].name]} else {} end)' <<<"$out"
|
|
5490
5493
|
else
|
|
5491
5494
|
# NO empty-list fallback. `host_miss_or_fail` exists for a lookup whose
|
|
5492
5495
|
# subject is absent — one PR that does not exist. A LIST has no absent
|
|
@@ -5567,7 +5570,7 @@ case "$op" in
|
|
|
5567
5570
|
# exit codes are deliberately THE SAME ONES — a consumer that already maps
|
|
5568
5571
|
# 4 to `unsupported` and anything else to `failed` must not need a second
|
|
5569
5572
|
# table to read this op.
|
|
5570
|
-
num="${1:?issue-view needs an issue number}"
|
|
5573
|
+
num="${1:?issue-view needs an issue number}"
|
|
5571
5574
|
# Asked once, before the arms, exactly as issue-list does — the same
|
|
5572
5575
|
# question with the same three answers and the same exit codes. A consumer
|
|
5573
5576
|
# that maps 4 to `unsupported` needs no second table to read this op.
|
|
@@ -5738,12 +5741,15 @@ case "$op" in
|
|
|
5738
5741
|
*) echo "plot-host: issue-open: ${source_said#*$'\t'}" >&2; exit 4 ;;
|
|
5739
5742
|
esac ;;
|
|
5740
5743
|
|
|
5741
|
-
issue-label|issue-comment|issue-close)
|
|
5744
|
+
issue-label|issue-comment|issue-comment-read|issue-close)
|
|
5742
5745
|
# THE PLAN-STATE WRITES, and one-way: Plot sets a `plan:*` label, keeps one
|
|
5743
|
-
# comment per issue and closes the issue at release; nothing reads any back
|
|
5744
|
-
#
|
|
5745
|
-
#
|
|
5746
|
-
# issue-
|
|
5746
|
+
# comment per issue and closes the issue at release; nothing reads any back,
|
|
5747
|
+
# except `issue-comment-read`, the plan-state comment's one sanctioned
|
|
5748
|
+
# read-back (D6: recovering ticket lines a write has no record to redo).
|
|
5749
|
+
# 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`
|
|
5750
|
+
# issue-comment <n> <marker> <body> edits the comment holding <marker>, else posts; an empty <marker> always posts
|
|
5751
|
+
# issue-comment-read <n> <marker> prints the marked comment's body, or nothing where none carries it
|
|
5752
|
+
# issue-close <n>
|
|
5747
5753
|
# GitHub issues only, dispatched on `issue_source` like issue-open. Exit 4,
|
|
5748
5754
|
# with the reason, for a source that cannot be asked.
|
|
5749
5755
|
num="${1:?$op needs an issue number}"; source_said="$(issue_source)" || exit 1
|
|
@@ -5752,9 +5758,11 @@ case "$op" in
|
|
|
5752
5758
|
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 ;;
|
|
5753
5759
|
issue-close) gh issue close "$num" >/dev/null 2>"$HOST_ERR" || gh_fail ;;
|
|
5754
5760
|
issue-comment)
|
|
5755
|
-
cid="
|
|
5756
|
-
|
|
5757
|
-
|
|
5761
|
+
cid="${2:+$(gh_marker_comment_id "$num" "$2")}" || gh_fail
|
|
5762
|
+
gh_edit_or_post_comment "$cid" issue "$num" "${3-}" || gh_fail ;;
|
|
5763
|
+
issue-comment-read)
|
|
5764
|
+
cid="$(gh_marker_comment_id "$num" "${2:?issue-comment-read needs a marker}")" || gh_fail
|
|
5765
|
+
[ -z "$cid" ] || gh api "repos/{owner}/{repo}/issues/comments/$cid" -q .body 2>"$HOST_ERR" || gh_fail ;;
|
|
5758
5766
|
esac
|
|
5759
5767
|
rm -f "$HOST_ERR" ;;
|
|
5760
5768
|
|
|
@@ -5777,11 +5785,7 @@ case "$op" in
|
|
|
5777
5785
|
esac
|
|
5778
5786
|
done
|
|
5779
5787
|
[ -n "$body" ] || die "pr-body needs --body"
|
|
5780
|
-
|
|
5781
|
-
gh pr edit "$num" --body "$body"
|
|
5782
|
-
else
|
|
5783
|
-
bb pr edit "$num" --body "$body"
|
|
5784
|
-
fi
|
|
5788
|
+
"$cli" pr edit "$num" --body "$body"
|
|
5785
5789
|
;;
|
|
5786
5790
|
|
|
5787
5791
|
rate-limit)
|
|
@@ -6058,11 +6062,11 @@ case "$op" in
|
|
|
6058
6062
|
# KEYED BY PR NUMBER, NOT A SHA — unlike commit-status, this writes through
|
|
6059
6063
|
# the signed-in CLI identity, so it needs no App credentials and no Node
|
|
6060
6064
|
# helper.
|
|
6061
|
-
[ "$be" = "github" ] || { echo "plot-host: pr-comment: bitbucket has no verified pr-comment write" >&2; exit 4; }; num="${1:?pr-comment needs a PR number}"
|
|
6062
|
-
|
|
6063
|
-
|
|
6065
|
+
[ "$be" = "github" ] || { echo "plot-host: pr-comment: bitbucket has no verified pr-comment write" >&2; exit 4; }; num="${1:?pr-comment needs a PR number}"
|
|
6066
|
+
cid="${3:+$(gh_marker_comment_id "$num" "$3")}" || gh_fail
|
|
6067
|
+
gh_edit_or_post_comment "$cid" pr "$num" "${2:?pr-comment needs a body}" || gh_fail; rm -f "$HOST_ERR" ;;
|
|
6064
6068
|
|
|
6065
6069
|
*)
|
|
6066
|
-
die "unknown op '$op' (backend|default-branch|pr-state|pr-create|pr-merge|pr-list|issue-list|issue-view|issue-status|issue-open|issue-label|issue-comment|issue-close|version-list|pr-body|pr-review|rate-limit|limit|ci-limit|spend-rate|commit-status|pr-comment)"
|
|
6070
|
+
die "unknown op '$op' (backend|default-branch|pr-state|pr-create|pr-merge|pr-list|issue-list|issue-view|issue-status|issue-open|issue-label|issue-comment|issue-comment-read|issue-close|version-list|pr-body|pr-review|rate-limit|limit|ci-limit|spend-rate|commit-status|pr-comment)"
|
|
6067
6071
|
;;
|
|
6068
6072
|
esac
|
package/plot-monitor-subject.sh
CHANGED
|
@@ -124,11 +124,11 @@ plot_monitor_subject() {
|
|
|
124
124
|
# PRODUCTION IS UNCHANGED: a real worktree outlives its agent, so the
|
|
125
125
|
# directory is present and this reads `starting` exactly as before.
|
|
126
126
|
if [ ! -f "$pid_file" ]; then
|
|
127
|
-
[ -d "$
|
|
127
|
+
[ -d "${pid_file%/*}" ] && { printf 'starting'; return 0; }
|
|
128
128
|
printf 'gone'; return 0
|
|
129
129
|
fi
|
|
130
130
|
|
|
131
|
-
pid
|
|
131
|
+
read -r pid < "$pid_file" 2>/dev/null
|
|
132
132
|
|
|
133
133
|
# A file that exists but holds no digits is a half-written pid, which is the
|
|
134
134
|
# startup window caught mid-`printf`. Not gone — UNLESS the wrapper has
|
|
@@ -140,7 +140,7 @@ plot_monitor_subject() {
|
|
|
140
140
|
# would read `starting` forever.
|
|
141
141
|
case "$pid" in
|
|
142
142
|
'' | *[!0-9]*)
|
|
143
|
-
if [ -f "$
|
|
143
|
+
if [ -f "${pid_file%/*}/.plot-worker.exit" ]; then
|
|
144
144
|
printf 'gone'; return 0
|
|
145
145
|
fi
|
|
146
146
|
printf 'starting'; return 0 ;;
|