From 8c5916ac4141fc376dfe32be0c98970666fd89d4 Mon Sep 17 00:00:00 2001 From: jparker2006 <85816763+jparker2006@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:14:21 +0000 Subject: [PATCH 1/4] #5 WL3: hourly-status check test, red first against the live loop's always-print check --- catalog/hourly-status/test.sh | 88 +++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 catalog/hourly-status/test.sh diff --git a/catalog/hourly-status/test.sh b/catalog/hourly-status/test.sh new file mode 100644 index 0000000..4c7b144 --- /dev/null +++ b/catalog/hourly-status/test.sh @@ -0,0 +1,88 @@ +#!/bin/sh +# Runs hourly-status's check against a stand-in `gh` that serves synthetic +# spec data, and checks the one promise the loop makes: it prints the spec's +# state when it changed since the last posted status line, and nothing +# otherwise, so a quiet hour starts no agent. +# +# Usage, from anywhere: sh catalog/hourly-status/test.sh +set -eu +here=$(cd "$(dirname "$0")" && pwd) +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +mkdir -p "$work/bin" "$work/home" "$work/data" + +# The check with its params replaced by the file's synthetic defaults, as an +# adapter replaces them before it applies the loop. +sed -e 's#[{][{]repo[}][}]#example-org/example-repo#g' \ + -e 's#[{][{]spec[}][}]#1#g' \ + "$here/check.sh" > "$work/check.sh" + +# A stand-in for `gh`: it prints the synthetic answer for the command the +# check runs (after gh's own --jq), or fails like gh does when GitHub can't +# be read. +cat > "$work/bin/gh" <<'EOF' +#!/bin/sh +[ -f "$FAKE/fail" ] && { echo "gh: could not connect" >&2; exit 1; } +case "$1 $2" in + "issue view") cat "$FAKE/tickets" ;; + "pr list") cat "$FAKE/prs" ;; + *) echo "gh: unexpected: $*" >&2; exit 1 ;; +esac +EOF +chmod +x "$work/bin/gh" + +fails=0 +wake() { + set +e + out=$(FAKE="$work/data" HOME="$work/home" PATH="$work/bin:$PATH" sh "$work/check.sh" 2>"$work/err") + code=$? + set -e +} +quiet() { # : the wake printed nothing and ended 0 or 1 + wake + if [ -n "$out" ] || [ "$code" -gt 1 ]; then + echo "FAIL $1: expected a quiet wake, got exit $code and: $out"; fails=$((fails + 1)) + else echo "ok $1"; fi +} +due() { # : the wake printed the state + wake + case "$out" in + *"$2"*) if [ "$code" -le 1 ]; then echo "ok $1"; return; fi ;; + esac + echo "FAIL $1: expected output with '$2', got exit $code and: $out"; fails=$((fails + 1)) +} +posted() { # the agent posted the line and recorded it, as the prompt says + for f in "$work/home/.wizloops/hourly-status/"*.pending; do [ -e "$f" ] || continue; mv "$f" "${f%.pending}.posted"; done +} + +printf '#2 CLOSED\n#3 OPEN\n#4 OPEN\n' > "$work/data/tickets" +printf '12 abc1234 3\n20 fff0000 99\n' > "$work/data/prs" + +# catches: the first wake stays quiet, so a spec never gets its first line +due "first wake shows the state" "#12 at abc1234" +# catches: the check prints on every wake (as an always-echo check does), so +# every hour starts an agent even when nothing changed +posted; quiet "nothing changed since the posted line" +# catches: a change is missed, so the status line goes stale +printf '#2 CLOSED\n#3 CLOSED\n#4 OPEN\n' > "$work/data/tickets" +due "a ticket closed" "#3 CLOSED" +# catches: the check marks a change as posted itself, so a run that fails +# before posting loses the change for good +due "not posted yet, still due" "#3 CLOSED" +posted; quiet "posted, quiet again" +# catches: a push to the spec's pull request is not seen as progress +printf '12 abc9999 3\n20 fff0000 99\n' > "$work/data/prs" +due "a pull request moved" "#12 at abc9999" +posted +# catches: another spec's pull request wakes this spec's agent +printf '12 abc9999 3\n20 fff1111 99\n21 eee0000 98\n' > "$work/data/prs" +quiet "another spec's pull request changed" +# catches: GitHub can't be read and the check exits 0 or 1 with no output, +# which reads as a quiet hour and hides the failure +touch "$work/data/fail" +wake +if [ -z "$out" ] && [ "$code" -gt 1 ]; then echo "ok a failed read fails the run" +else echo "FAIL a failed read fails the run: got exit $code and: $out"; fails=$((fails + 1)); fi + +[ "$fails" -eq 0 ] || { echo "$fails failed"; exit 1; } +echo "all passed" From bd215d4648500dcf3894ac1e0209c23af303afc3 Mon Sep 17 00:00:00 2001 From: jparker2006 <85816763+jparker2006@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:15:50 +0000 Subject: [PATCH 2/4] #5 WL3: catalog: the hourly-status loop, quiet unless the spec changed (green) --- catalog/hourly-status.md | 30 ++++++++++++++++++++++++++ catalog/hourly-status/check.sh | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 catalog/hourly-status.md create mode 100644 catalog/hourly-status/check.sh diff --git a/catalog/hourly-status.md b/catalog/hourly-status.md new file mode 100644 index 0000000..00934ec --- /dev/null +++ b/catalog/hourly-status.md @@ -0,0 +1,30 @@ +--- +id: "hourly-status" +name: "Hourly status line, only when something changed" +trigger: {"cron": "15 * * * *", "timezone": "UTC"} +check: {"run": "hourly-status/check.sh", "timeout": 60} +thread: "same" +secrets: [] +priority: 2 +params: {"repo": "example-org/example-repo", "spec": 1, "status_repo": "example-org/example-tracker", "status_issue": 1} +--- +You manage spec {{spec}} in {{repo}}. This hour's check found that its +tickets or their pull requests changed since your last status line; its +output is below. + +1. Write one status line for spec {{spec}}, from the check's output and what + you know of the spec: tickets merged out of the total, which are in + review, which are being built, and what blocks any that wait. Start it + with `Status for spec {{spec}}:`. Say nothing the output and the spec's + own records do not show. +2. Post it as one comment on issue {{status_issue}} in {{status_repo}}. +3. Only once the comment is posted, run the `mv` line the check printed, so + the next quiet hour stays quiet. If the post failed, leave the file: the + next hour shows the same change again. + +Post nothing else and change nothing else. Public comments carry no thread +ids, private names or exact words of a private decision. + +This loop grants no secrets (`secrets: []`). It runs in the thread that +applied it, so its check and this run use that thread's own `gh` login to +read {{repo}} and to post on {{status_repo}}. diff --git a/catalog/hourly-status/check.sh b/catalog/hourly-status/check.sh new file mode 100644 index 0000000..3559163 --- /dev/null +++ b/catalog/hourly-status/check.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# hourly-status check for spec {{spec}} in {{repo}}. +# +# Reads the spec's tickets and the open pull requests that close them, and +# prints that state only when it differs from the last status line the agent +# posted. Nothing changed: it prints nothing, so no agent starts. GitHub +# can't be read: it fails the run (exit 2), never a silent quiet hour. +# +# The state it printed waits in .pending until the agent has posted the +# line and renamed it to .posted, so a run that fails before posting +# shows the same change again next hour. +set -eu +dir="$HOME/.wizloops/hourly-status" +key=$(printf '%s-%s' '{{repo}}' '{{spec}}' | tr -c 'A-Za-z0-9.\n-' '_') +mkdir -p "$dir" + +tickets=$(gh issue view '{{spec}}' -R '{{repo}}' --json subIssues \ + --jq '.subIssues.nodes[] | "#\(.number) \(.state)"') || + { echo "hourly-status: cannot read spec {{spec}} in {{repo}}" >&2; exit 2; } +prs=$(gh pr list -R '{{repo}}' --state open --limit 200 \ + --json number,headRefOid,closingIssuesReferences \ + --jq '.[] | "\(.number) \(.headRefOid[0:7]) \([.closingIssuesReferences[].number | tostring] | join(","))"') || + { echo "hourly-status: cannot read pull requests in {{repo}}" >&2; exit 2; } + +# Keep only the pull requests that close one of this spec's tickets. +spec_prs=$(printf '%s\n' "$prs" | awk -v t="$tickets" ' + BEGIN { n = split(t, l, "\n"); for (i = 1; i <= n; i++) { sub(/^#/, "", l[i]); sub(/ .*/, "", l[i]); mine[l[i]] = 1 } } + NF >= 3 { m = split($3, c, ","); for (i = 1; i <= m; i++) if (c[i] in mine) { print "#" $1 " at " $2 " (closes #" c[i] ")"; break } }') + +state=$(printf 'tickets:\n%s\npull requests:\n%s\n' "$tickets" "${spec_prs:-none}") + +if [ -f "$dir/$key.posted" ] && [ "$state" = "$(cat "$dir/$key.posted")" ]; then + rm -f "$dir/$key.pending" + exit 0 +fi +printf '%s\n' "$state" > "$dir/$key.pending" +echo "Spec {{spec}} in {{repo}} changed since the last status line." +echo "Once the line is posted: mv $dir/$key.pending $dir/$key.posted" +printf '%s\n' "$state" From a3fa2029c96102cebf288d97df68862d4f129180 Mon Sep 17 00:00:00 2001 From: jparker2006 <85816763+jparker2006@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:42:17 +0000 Subject: [PATCH 3/4] #5 WL3: R1-R3 red: same-head progress, PRs past a window, another repository's issue number --- catalog/hourly-status/test.sh | 127 +++++++++++++++++++++++++++------- 1 file changed, 101 insertions(+), 26 deletions(-) diff --git a/catalog/hourly-status/test.sh b/catalog/hourly-status/test.sh index 4c7b144..b488070 100644 --- a/catalog/hourly-status/test.sh +++ b/catalog/hourly-status/test.sh @@ -1,12 +1,14 @@ #!/bin/sh -# Runs hourly-status's check against a stand-in `gh` that serves synthetic -# spec data, and checks the one promise the loop makes: it prints the spec's -# state when it changed since the last posted status line, and nothing -# otherwise, so a quiet hour starts no agent. +# Runs hourly-status's check against a stand-in `gh` that serves raw, +# synthetic GitHub JSON and applies the check's own --jq filter with jq, and +# checks the one promise the loop makes: it prints the spec's state when it +# changed since the last posted status line, and nothing otherwise, so a +# quiet hour starts no agent. # -# Usage, from anywhere: sh catalog/hourly-status/test.sh +# Needs jq. Usage, from anywhere: sh catalog/hourly-status/test.sh set -eu here=$(cd "$(dirname "$0")" && pwd) +command -v jq >/dev/null || { echo "test: needs jq" >&2; exit 2; } work=$(mktemp -d) trap 'rm -rf "$work"' EXIT mkdir -p "$work/bin" "$work/home" "$work/data" @@ -17,22 +19,72 @@ sed -e 's#[{][{]repo[}][}]#example-org/example-repo#g' \ -e 's#[{][{]spec[}][}]#1#g' \ "$here/check.sh" > "$work/check.sh" -# A stand-in for `gh`: it prints the synthetic answer for the command the -# check runs (after gh's own --jq), or fails like gh does when GitHub can't -# be read. +# A stand-in for `gh`. `api graphql` serves page1.json, and page2.json only +# with --paginate and an $endCursor query, as gh does; `issue view` and +# `pr list` serve the same world in their shapes (pr list honours --limit). +# Each answer goes through the caller's --jq, applied by jq. With +# data/fail it fails as gh does when GitHub can't be read. cat > "$work/bin/gh" <<'EOF' #!/bin/sh [ -f "$FAKE/fail" ] && { echo "gh: could not connect" >&2; exit 1; } -case "$1 $2" in - "issue view") cat "$FAKE/tickets" ;; - "pr list") cat "$FAKE/prs" ;; - *) echo "gh: unexpected: $*" >&2; exit 1 ;; +cmd="$1 $2"; shift 2 +filter=. paginate=no limit=30 query= +while [ $# -gt 0 ]; do + case "$1" in + --jq) filter=$2; shift ;; + --limit) limit=$2; shift ;; + --paginate) paginate=yes ;; + -f|-F) case "$2" in query=*) query=${2#query=} ;; esac; shift ;; + esac + shift +done +pages="$FAKE/page1.json" +case "$query" in *'$endCursor'*) [ $paginate = yes ] && pages="$pages $FAKE/page2.json" ;; esac +case "$cmd" in + "api graphql") for p in $pages; do jq -r "$filter" "$p" || exit 1; done ;; + "issue view") jq -s '{subIssues: {nodes: [.[].data.repository.issue.subIssues.nodes[]]}}' \ + "$FAKE/page1.json" "$FAKE/page2.json" | jq -r "$filter" ;; + "pr list") jq ".[0:$limit]" "$FAKE/prs.json" | jq -r "$filter" ;; + *) echo "gh: unexpected: $cmd" >&2; exit 1 ;; esac EOF chmod +x "$work/bin/gh" +# The synthetic world. Spec 1 has tickets #2 and #3 on the first page of its +# sub-issues and #4 on the second. #12 closes #3; #30 closes #4 and is the +# 201st open pull request; #40 closes other-org/other-repo#2, not ticket #2. +t2=CLOSED t3=OPEN t3_labels='"ready-for-agent"' +h12=abc1234 draft12=false reviews12= checks12=PENDING comments12=1 +h30=ccc3000 h40=ddd4000 more_labels=false +pr() { # number repo head draft reviews checks comments + printf '{"number":%s,"state":"OPEN","isDraft":%s,"headRefOid":"%s000000000000000000000000000000000","reviewDecision":null,"repository":{"nameWithOwner":"%s"},"comments":{"totalCount":%s},"latestReviews":{"pageInfo":{"hasNextPage":false},"nodes":[%s]},"commits":{"nodes":[{"commit":{"statusCheckRollup":{"state":"%s"}}}]},"closingIssuesReferences":[]}' \ + "$1" "$4" "$3" "$2" "$7" "$5" "$6" +} +ticket() { # number state labels prs + printf '{"number":%s,"state":"%s","repository":{"nameWithOwner":"example-org/example-repo"},"labels":{"pageInfo":{"hasNextPage":%s},"nodes":[%s]},"closedByPullRequestsReferences":{"pageInfo":{"hasNextPage":false},"nodes":[%s]}}' \ + "$1" "$2" "$more_labels" "$(printf '%s' "$3" | sed 's/"\([^",]*\)"/{"name":"\1"}/g')" "$4" +} +closes() { # + printf '%s' "$1" | sed "s#\"closingIssuesReferences\":\[\]#\"closingIssuesReferences\":[{\"number\":$2,\"repository\":{\"nameWithOwner\":\"$3\"}}]#" +} +world() { + p12=$(pr 12 example-org/example-repo "$h12" "$draft12" "$reviews12" "$checks12" "$comments12") + p30=$(pr 30 example-org/example-repo "$h30" false "" SUCCESS 0) + p40=$(pr 40 example-org/example-repo "$h40" false "" SUCCESS 0) + printf '{"data":{"repository":{"issue":{"subIssues":{"pageInfo":{"hasNextPage":true,"endCursor":"Mg"},"nodes":[%s,%s]}}}}}\n' \ + "$(ticket 2 "$t2" "" "")" "$(ticket 3 "$t3" "$t3_labels" "$p12")" > "$work/data/page1.json" + printf '{"data":{"repository":{"issue":{"subIssues":{"pageInfo":{"hasNextPage":false,"endCursor":"Mw"},"nodes":[%s]}}}}}\n' \ + "$(ticket 4 OPEN "" "$p30")" > "$work/data/page2.json" + # pr list: #12 and #40 first, 198 unrelated, then #30 as the 201st. + { printf '[%s,%s' "$(closes "$p12" 3 example-org/example-repo)" "$(closes "$p40" 2 other-org/other-repo)" + i=100; while [ $i -lt 298 ]; do printf ',%s' "$(pr $i example-org/example-repo eee0000 false "" SUCCESS 0)"; i=$((i + 1)); done + printf ',%s]\n' "$(closes "$p30" 4 example-org/example-repo)" + } > "$work/data/prs.json" +} + fails=0 wake() { + world set +e out=$(FAKE="$work/data" HOME="$work/home" PATH="$work/bin:$PATH" sh "$work/check.sh" 2>"$work/err") code=$? @@ -51,38 +103,61 @@ due() { # : the wake printed the state esac echo "FAIL $1: expected output with '$2', got exit $code and: $out"; fails=$((fails + 1)) } +shows() { # : the last wake's output shows it + case "$out" in *"$2"*) echo "ok $1" ;; *) echo "FAIL $1: no '$2' in: $out"; fails=$((fails + 1)) ;; esac +} +lacks() { # : the last wake's output does not show it + case "$out" in *"$2"*) echo "FAIL $1: '$2' shown in: $out"; fails=$((fails + 1)) ;; *) echo "ok $1" ;; esac +} +failed() { # : the wake failed the run (exit over 1) and printed nothing + wake + if [ -z "$out" ] && [ "$code" -gt 1 ]; then echo "ok $1" + else echo "FAIL $1: expected a failed run, got exit $code and: $out"; fails=$((fails + 1)); fi +} posted() { # the agent posted the line and recorded it, as the prompt says for f in "$work/home/.wizloops/hourly-status/"*.pending; do [ -e "$f" ] || continue; mv "$f" "${f%.pending}.posted"; done } -printf '#2 CLOSED\n#3 OPEN\n#4 OPEN\n' > "$work/data/tickets" -printf '12 abc1234 3\n20 fff0000 99\n' > "$work/data/prs" - # catches: the first wake stays quiet, so a spec never gets its first line due "first wake shows the state" "#12 at abc1234" +# catches: a pull request that closes another repository's #2 is counted as +# work on this spec's ticket #2 +lacks "another repository's #2 is not this spec's" "#40" +# catches: a fixed window over the repository's open pull requests, or only +# the first page of sub-issues, hides the spec's pull request #30 +shows "a ticket's pull request past any window is seen" "#30 at ccc3000" # catches: the check prints on every wake (as an always-echo check does), so # every hour starts an agent even when nothing changed posted; quiet "nothing changed since the posted line" # catches: a change is missed, so the status line goes stale -printf '#2 CLOSED\n#3 CLOSED\n#4 OPEN\n' > "$work/data/tickets" -due "a ticket closed" "#3 CLOSED" +t3=CLOSED +due "a ticket closed" "#3 example-org/example-repo CLOSED" # catches: the check marks a change as posted itself, so a run that fails # before posting loses the change for good -due "not posted yet, still due" "#3 CLOSED" +due "not posted yet, still due" "#3 example-org/example-repo CLOSED" posted; quiet "posted, quiet again" # catches: a push to the spec's pull request is not seen as progress -printf '12 abc9999 3\n20 fff0000 99\n' > "$work/data/prs" +t3=OPEN h12=abc9999 due "a pull request moved" "#12 at abc9999" posted -# catches: another spec's pull request wakes this spec's agent -printf '12 abc9999 3\n20 fff1111 99\n21 eee0000 98\n' > "$work/data/prs" -quiet "another spec's pull request changed" +# catches: progress at the same head is missed: a draft marked ready, a +# review, a CI result, a verdict comment, a blocking label +draft12=true; due "same head: marked draft" "draft"; posted +draft12=false; due "same head: marked ready" "ready"; posted +reviews12='{"state":"CHANGES_REQUESTED","author":{"login":"example-reviewer"}}' +due "same head: a review asks for changes" "example-reviewer=CHANGES_REQUESTED"; posted +checks12=FAILURE; due "same head: CI failed" "checks:FAILURE"; posted +comments12=2; due "same head: a new comment (a verdict)" "comments:2"; posted +t3_labels='"ready-for-agent","needs-info"' +due "a ticket asks a question" "needs-info"; posted +quiet "all of that posted, quiet again" +# catches: another spec's or nobody's pull request wakes this spec's agent +h40=ddd9999; quiet "an unrelated pull request moved" +# catches: a list GitHub cut short is read as complete, hiding changes +more_labels=true; failed "a cut-short list fails the run"; more_labels=false # catches: GitHub can't be read and the check exits 0 or 1 with no output, # which reads as a quiet hour and hides the failure -touch "$work/data/fail" -wake -if [ -z "$out" ] && [ "$code" -gt 1 ]; then echo "ok a failed read fails the run" -else echo "FAIL a failed read fails the run: got exit $code and: $out"; fails=$((fails + 1)); fi +touch "$work/data/fail"; failed "a failed read fails the run" [ "$fails" -eq 0 ] || { echo "$fails failed"; exit 1; } echo "all passed" From 6c2ad9680c8896a7dcd1652634ab553b121e4e75 Mon Sep 17 00:00:00 2001 From: jparker2006 <85816763+jparker2006@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:43:06 +0000 Subject: [PATCH 4/4] #5 WL3: R1-R3: per-ticket closing pull requests, all pages, with review, CI, draft and label state (green) --- catalog/hourly-status.md | 5 ++- catalog/hourly-status/check.sh | 69 +++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/catalog/hourly-status.md b/catalog/hourly-status.md index 00934ec..3b28b71 100644 --- a/catalog/hourly-status.md +++ b/catalog/hourly-status.md @@ -9,8 +9,9 @@ priority: 2 params: {"repo": "example-org/example-repo", "spec": 1, "status_repo": "example-org/example-tracker", "status_issue": 1} --- You manage spec {{spec}} in {{repo}}. This hour's check found that its -tickets or their pull requests changed since your last status line; its -output is below. +tickets (their state or labels) or the open pull requests that close them +(their head, draft state, reviews, CI or comments) changed since your last +status line; its output is below. 1. Write one status line for spec {{spec}}, from the check's output and what you know of the spec: tickets merged out of the total, which are in diff --git a/catalog/hourly-status/check.sh b/catalog/hourly-status/check.sh index 3559163..d64c00b 100644 --- a/catalog/hourly-status/check.sh +++ b/catalog/hourly-status/check.sh @@ -1,10 +1,13 @@ #!/bin/sh # hourly-status check for spec {{spec}} in {{repo}}. # -# Reads the spec's tickets and the open pull requests that close them, and -# prints that state only when it differs from the last status line the agent -# posted. Nothing changed: it prints nothing, so no agent starts. GitHub -# can't be read: it fails the run (exit 2), never a silent quiet hour. +# Reads every one of the spec's tickets (all pages) with its labels, and for +# each ticket the open pull requests GitHub links as closing that exact +# issue, with their head, draft state, review decision, latest reviews, CI +# state and comment count. It prints that state only when it differs from +# the last status line the agent posted. Nothing changed: it prints nothing, +# so no agent starts. GitHub can't be read, or cut a list short: it fails the +# run (exit 2), never a silent quiet hour. # # The state it printed waits in .pending until the agent has posted the # line and renamed it to .posted, so a run that fails before posting @@ -13,21 +16,52 @@ set -eu dir="$HOME/.wizloops/hourly-status" key=$(printf '%s-%s' '{{repo}}' '{{spec}}' | tr -c 'A-Za-z0-9.\n-' '_') mkdir -p "$dir" +repo='{{repo}}' -tickets=$(gh issue view '{{spec}}' -R '{{repo}}' --json subIssues \ - --jq '.subIssues.nodes[] | "#\(.number) \(.state)"') || - { echo "hourly-status: cannot read spec {{spec}} in {{repo}}" >&2; exit 2; } -prs=$(gh pr list -R '{{repo}}' --state open --limit 200 \ - --json number,headRefOid,closingIssuesReferences \ - --jq '.[] | "\(.number) \(.headRefOid[0:7]) \([.closingIssuesReferences[].number | tostring] | join(","))"') || - { echo "hourly-status: cannot read pull requests in {{repo}}" >&2; exit 2; } - -# Keep only the pull requests that close one of this spec's tickets. -spec_prs=$(printf '%s\n' "$prs" | awk -v t="$tickets" ' - BEGIN { n = split(t, l, "\n"); for (i = 1; i <= n; i++) { sub(/^#/, "", l[i]); sub(/ .*/, "", l[i]); mine[l[i]] = 1 } } - NF >= 3 { m = split($3, c, ","); for (i = 1; i <= m; i++) if (c[i] in mine) { print "#" $1 " at " $2 " (closes #" c[i] ")"; break } }') +query='query($owner: String!, $name: String!, $spec: Int!, $endCursor: String) { + repository(owner: $owner, name: $name) { issue(number: $spec) { + subIssues(first: 50, after: $endCursor) { + pageInfo { hasNextPage endCursor } + nodes { + number state repository { nameWithOwner } + labels(first: 50) { pageInfo { hasNextPage } nodes { name } } + closedByPullRequestsReferences(first: 20, includeClosedPrs: false) { + pageInfo { hasNextPage } + nodes { + number state isDraft headRefOid reviewDecision + repository { nameWithOwner } + comments { totalCount } + latestReviews(first: 50) { pageInfo { hasNextPage } nodes { state author { login } } } + commits(last: 1) { nodes { commit { statusCheckRollup { state } } } } + } + } + } + } + } } +}' +# One line per ticket and per open pull request that closes it; a line +# "cut-short" when GitHub has more labels, pull requests or reviews than +# were read. +filter='.data.repository.issue.subIssues.nodes[] | + (if .labels.pageInfo.hasNextPage or .closedByPullRequestsReferences.pageInfo.hasNextPage + or any(.closedByPullRequestsReferences.nodes[]; .latestReviews.pageInfo.hasNextPage) + then "cut-short #\(.number)" else empty end), + "#\(.number) \(.repository.nameWithOwner) \(.state) labels:\([.labels.nodes[].name] | sort | join(","))", + (.closedByPullRequestsReferences.nodes[] | select(.state == "OPEN") | + " #\(.number) at \(.headRefOid[0:7]) in \(.repository.nameWithOwner)" + + " \(if .isDraft then "draft" else "ready" end)" + + " decision:\(.reviewDecision // "none")" + + " reviews:\([.latestReviews.nodes[] | "\(.author.login // "ghost")=\(.state)"] | sort | join(","))" + + " checks:\(.commits.nodes[0].commit.statusCheckRollup.state // "none")" + + " comments:\(.comments.totalCount)")' -state=$(printf 'tickets:\n%s\npull requests:\n%s\n' "$tickets" "${spec_prs:-none}") +state=$(gh api graphql --paginate -F owner="${repo%%/*}" -F name="${repo#*/}" \ + -F spec='{{spec}}' -f query="$query" --jq "$filter") || + { echo "hourly-status: cannot read spec {{spec}} in {{repo}}" >&2; exit 2; } +case "$state" in + cut-short*|*" +cut-short"*) echo "hourly-status: GitHub cut a list short for spec {{spec}} in {{repo}}" >&2; exit 2 ;; +esac if [ -f "$dir/$key.posted" ] && [ "$state" = "$(cat "$dir/$key.posted")" ]; then rm -f "$dir/$key.pending" @@ -36,4 +70,5 @@ fi printf '%s\n' "$state" > "$dir/$key.pending" echo "Spec {{spec}} in {{repo}} changed since the last status line." echo "Once the line is posted: mv $dir/$key.pending $dir/$key.posted" +echo "Each ticket, then the open pull requests that close it:" printf '%s\n' "$state"