rungate 0.8.19 → 0.8.20
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/gates/.gate-salt +1 -1
- package/lib/board-intake-move.ts +280 -0
- package/lib/board-mirror.ts +11 -4
- package/lib/cli-commands.ts +17 -0
- package/lib/criterion-issue-census.ts +62 -0
- package/lib/issue-closure-audit.ts +96 -0
- package/lib/project-state-shape.ts +18 -0
- package/lib/scaffold/board-intake-workflow.ts +469 -0
- package/lib/scaffold/human-steps.ts +98 -22
- package/lib/scaffold/owned-files.ts +10 -0
- package/lib/scaffold/steps.ts +14 -1
- package/lib/unaccounted-work.ts +314 -0
- package/package.json +3 -1
- package/scripts/board-intake-move.ts +80 -0
- package/scripts/unaccounted-work.ts +122 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.github/workflows/board-intake.yml`, generated — #2166, ADR-014 row 4,
|
|
3
|
+
* the second half of SC-2745 (`board-ready.yml` is #2047's).
|
|
4
|
+
*
|
|
5
|
+
* Every new issue and pull request goes on the board, and a pull request
|
|
6
|
+
* offered for review moves to In review. Hand-written and caller-owned until
|
|
7
|
+
* now, with this repository's project URL and node id pasted in. A consumer
|
|
8
|
+
* has neither, so the scaffold writes it and this repository's copy is the
|
|
9
|
+
* generated one.
|
|
10
|
+
*
|
|
11
|
+
* ## It names no board
|
|
12
|
+
*
|
|
13
|
+
* The add step asks `bunx rungate@<version> board-id` (#2173), which reads
|
|
14
|
+
* `board.id` from the checked-out config through the one loader. The add is
|
|
15
|
+
* then `addProjectV2ItemById` on that node id, so a user board and an
|
|
16
|
+
* organisation board need no branch, and no project URL exists anywhere in
|
|
17
|
+
* the file. `actions/add-to-project` is gone: it accepts only a URL.
|
|
18
|
+
*
|
|
19
|
+
* ## The checkout is the default branch, never the pull request
|
|
20
|
+
*
|
|
21
|
+
* The trigger is `pull_request_target`, which runs with secrets in the BASE
|
|
22
|
+
* repository's context. Checking out the head would run a contributor's code
|
|
23
|
+
* holding a token that can write the board. The config is read from
|
|
24
|
+
* `github.event.repository.default_branch`, with `persist-credentials: false`,
|
|
25
|
+
* and `bunx` runs the published package, not anything in the tree.
|
|
26
|
+
*
|
|
27
|
+
* ## An unconfigured tree is UNMEASURED, an annotation and not a red run
|
|
28
|
+
*
|
|
29
|
+
* No `RUNGATE_PROJECT_TOKEN`, or no `board.id` (`board-id` exits 2), ends the
|
|
30
|
+
* add step with a warning and no item id, and the move step's `if:` skips on
|
|
31
|
+
* the empty id (`.claude/rules/config-access.md`). Any other failure stands.
|
|
32
|
+
*
|
|
33
|
+
* ## What the move step keeps, each piece asserted in test/board-intake.test.ts
|
|
34
|
+
*
|
|
35
|
+
* - It owns only the opened -> In review edge. `merged -> Done` and
|
|
36
|
+
* `closed -> Done` stay with GitHub's built-in workflows, so each
|
|
37
|
+
* transition has exactly one decider. Do not add a merge or close handler.
|
|
38
|
+
* - Drafts are not moved (BI-2): Jason's call, 2026-11-04.
|
|
39
|
+
* - It keys off the item the add step created (BI-1), never a re-query, which
|
|
40
|
+
* would race the built-in "Item added to project" workflow.
|
|
41
|
+
* - Every call goes through one retrying helper (BI-7), whose value is stdout
|
|
42
|
+
* only (BI-8). Every write is read back from the item AND from the project's
|
|
43
|
+
* search index, which is what the board draws from (BI-6, BI-9). Every paged
|
|
44
|
+
* read reports truncation instead of reading a full page as absence (BI-10),
|
|
45
|
+
* and every `node(id:)` refuses a null node by naming the id (BI-11).
|
|
46
|
+
* - No `${{ }}` inside a `run:` block (BI-4), and the one scratch file is
|
|
47
|
+
* removed on exit (BI-12).
|
|
48
|
+
* - The field and option are resolved by NAME at run time, so a renamed
|
|
49
|
+
* column fails loudly rather than writing a stale id.
|
|
50
|
+
*
|
|
51
|
+
* The incidents behind each of these are in the hand-written file's history
|
|
52
|
+
* (git log -- .github/workflows/board-intake.yml, before #2166).
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/** The file this module generates, under `.github/workflows/`. */
|
|
56
|
+
export const BOARD_INTAKE_WORKFLOW_FILE = "board-intake.yml";
|
|
57
|
+
|
|
58
|
+
/** The one job in it. */
|
|
59
|
+
export const BOARD_INTAKE_JOB = "add-to-board";
|
|
60
|
+
|
|
61
|
+
/** The CLI command the add step runs to learn the board (#2173). */
|
|
62
|
+
export const BOARD_ID_COMMAND = "board-id";
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* How `rungate board-id` begins its no-board refusal. Exit 2 alone also
|
|
66
|
+
* covers a usage error, so the add step softens only this wording;
|
|
67
|
+
* `test/board-intake.test.ts` holds it to `scripts/board-id.ts`.
|
|
68
|
+
*/
|
|
69
|
+
export { NO_BOARD_REFUSAL } from "./board-ready-workflow";
|
|
70
|
+
import { NO_BOARD_REFUSAL } from "./board-ready-workflow";
|
|
71
|
+
|
|
72
|
+
/** The add step's `run:` body. Exported so a test executes THIS text. */
|
|
73
|
+
export function buildBoardIntakeAddScript(version: string): string {
|
|
74
|
+
return `set -euo pipefail
|
|
75
|
+
if [ -z "\${GH_TOKEN}" ]; then
|
|
76
|
+
echo "::warning title=Board intake::UNMEASURED — RUNGATE_PROJECT_TOKEN is not set, so nothing was added to the board."
|
|
77
|
+
exit 0
|
|
78
|
+
fi
|
|
79
|
+
# The board is board.id in the default branch's config. Only the no-board
|
|
80
|
+
# refusal (exit 2 AND its own wording) is an annotation; a usage error is red.
|
|
81
|
+
code=0
|
|
82
|
+
project=$(bunx rungate@${version} ${BOARD_ID_COMMAND} 2>"\${RUNNER_TEMP}/board-id.stderr") || code=$?
|
|
83
|
+
cat "\${RUNNER_TEMP}/board-id.stderr" >&2
|
|
84
|
+
if [ "\${code}" -eq 2 ] && grep -q '^${NO_BOARD_REFUSAL}' "\${RUNNER_TEMP}/board-id.stderr"; then
|
|
85
|
+
echo "::warning title=Board intake::UNMEASURED — no board.id in the rungate config, so nothing was added. Set board.id and this runs."
|
|
86
|
+
exit 0
|
|
87
|
+
fi
|
|
88
|
+
if [ "\${code}" -ne 0 ]; then
|
|
89
|
+
exit "\${code}"
|
|
90
|
+
fi
|
|
91
|
+
# Done only on a real id: an exit-0 reply carrying null is retried too (#2185).
|
|
92
|
+
item=""
|
|
93
|
+
tried=0
|
|
94
|
+
: > "\${RUNNER_TEMP}/add.stderr"
|
|
95
|
+
for attempt in 1 2 3; do
|
|
96
|
+
tried=\${attempt}
|
|
97
|
+
item=$(gh api graphql -f project="\${project}" -f content="\${CONTENT_ID}" -f query='
|
|
98
|
+
mutation($project: ID!, $content: ID!) {
|
|
99
|
+
addProjectV2ItemById(input: { projectId: $project, contentId: $content }) { item { id } }
|
|
100
|
+
}' --jq '.data.addProjectV2ItemById.item.id' 2>"\${RUNNER_TEMP}/add.stderr") || item=""
|
|
101
|
+
if [ -n "\${item}" ] && [ "\${item}" != "null" ]; then
|
|
102
|
+
break
|
|
103
|
+
fi
|
|
104
|
+
item=""
|
|
105
|
+
sleep $(( attempt * 2 ))
|
|
106
|
+
done
|
|
107
|
+
if [ -z "\${item}" ]; then
|
|
108
|
+
echo "::error title=Board intake::addProjectV2ItemById gave no item after \${tried} attempt(s), so the item is NOT on the board. Last error: $(cat "\${RUNNER_TEMP}/add.stderr")" >&2
|
|
109
|
+
exit 1
|
|
110
|
+
fi
|
|
111
|
+
echo "itemId=\${item}" >> "\${GITHUB_OUTPUT}"
|
|
112
|
+
echo "projectId=\${project}" >> "\${GITHUB_OUTPUT}"
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The move step's `run:` body, carried verbatim from the hand-written file
|
|
118
|
+
* (#2166). PROJECT_ID now comes from the add step's output rather than a
|
|
119
|
+
* pasted id; nothing in this text changed.
|
|
120
|
+
*/
|
|
121
|
+
export const BOARD_INTAKE_MOVE_SCRIPT = `set -euo pipefail
|
|
122
|
+
|
|
123
|
+
# EVERY API CALL GOES THROUGH HERE, and the reason is \`set -e\`.
|
|
124
|
+
# A bare \`gh api graphql\` that fails on a network blip, a secondary
|
|
125
|
+
# rate limit or a momentary 5xx aborts this step instantly with gh's
|
|
126
|
+
# raw error: the retry loop below is never reached and none of the
|
|
127
|
+
# diagnostics in this script ever print. The loop would then be
|
|
128
|
+
# guarding the race it was written for and nothing else.
|
|
129
|
+
#
|
|
130
|
+
# Three calls had that exposure, not the one that was reported —
|
|
131
|
+
# resolving the field, mutating, and reading back — so it is fixed
|
|
132
|
+
# as a population and \`test/board-intake.test.ts\` BI-7 asserts no
|
|
133
|
+
# bare \`gh api graphql\` survives anywhere in this step.
|
|
134
|
+
#
|
|
135
|
+
# STDERR GOES TO A FILE, NOT INTO THE RETURN VALUE. An earlier
|
|
136
|
+
# revision captured \`2>&1\`, which is right for the failure path —
|
|
137
|
+
# \${out} is quoted into the ::error — and wrong for the success
|
|
138
|
+
# path, because the same \${out} is what callers parse. \`gh\` writes
|
|
139
|
+
# to stderr on calls that SUCCEED: the update notifier, rate-limit
|
|
140
|
+
# warnings. Two of the three call sites treat the result as data,
|
|
141
|
+
# and the read-back is the dangerous one. A comparison against
|
|
142
|
+
# "\${COLUMN}" that is polluted by a one-line warning simply stops
|
|
143
|
+
# matching, so the loop logs "a concurrent write won" for a race
|
|
144
|
+
# that never happened and then blames a competing writer for a
|
|
145
|
+
# dirty capture — the right exit code reporting the wrong
|
|
146
|
+
# mechanism (\`.claude/rules/checks-must-be-able-to-fail.md\`, the
|
|
147
|
+
# sixth shape).
|
|
148
|
+
#
|
|
149
|
+
# Setting GH_NO_UPDATE_NOTIFIER would silence the one warning that
|
|
150
|
+
# was named and leave the class open, so it is not the fix.
|
|
151
|
+
err=$(mktemp)
|
|
152
|
+
# A trap, not a trailing \`rm\`. Every refusal below exits the step
|
|
153
|
+
# early, so a cleanup line at the bottom runs on exactly the path
|
|
154
|
+
# that did not need it. Asserted by BI-12.
|
|
155
|
+
trap 'rm -f "\${err}"' EXIT
|
|
156
|
+
gql() {
|
|
157
|
+
local out attempt
|
|
158
|
+
for attempt in 1 2 3; do
|
|
159
|
+
if out=$(gh api graphql "$@" 2>"\${err}"); then
|
|
160
|
+
printf '%s' "\${out}"
|
|
161
|
+
return 0
|
|
162
|
+
fi
|
|
163
|
+
sleep $(( attempt * 2 ))
|
|
164
|
+
done
|
|
165
|
+
echo "::error title=Board intake::GitHub's GraphQL API failed three times. The item may or may not be on the board and its Status is UNKNOWN — this run measured nothing. Last error: $(< "\${err}")" >&2
|
|
166
|
+
return 1
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# \`node(id: ID!)\` IS NULLABLE, and a null node is an id that did not
|
|
170
|
+
# resolve rather than an empty reading. A stale id, a wrong
|
|
171
|
+
# PROJECT_ID, or a project this token lost access to returns
|
|
172
|
+
# \`{"data":{"node":null}}\` with NO GraphQL error, so \`gql\` exits 0
|
|
173
|
+
# and \`--jq '.data.node.X'\` prints the four bytes \`null\`.
|
|
174
|
+
#
|
|
175
|
+
# What that does downstream, measured:
|
|
176
|
+
#
|
|
177
|
+
# jq '.data.node.fields' on a null node -> null, exit 0
|
|
178
|
+
# jq -r '[.nodes[] | …]' on \`null\` -> exit 5
|
|
179
|
+
# jq -r '.pageInfo.hasNextPage' on \`null\` -> null, exit 0
|
|
180
|
+
#
|
|
181
|
+
# So \`set -euo pipefail\` does kill the job rather than write the
|
|
182
|
+
# wrong column — but it dies on jq's "Cannot iterate over null",
|
|
183
|
+
# naming jq and not the id, and the truncation guard above compares
|
|
184
|
+
# the string \`null\` against \`true\` and stays silent. Right exit
|
|
185
|
+
# code, unreadable cause, which is this workflow's own subject one
|
|
186
|
+
# layer down. BI-11 asserts it over all three reads.
|
|
187
|
+
require_node() {
|
|
188
|
+
if [ -z "$2" ] || [ "$2" = "null" ]; then
|
|
189
|
+
echo "::error title=Board intake::\${1} is UNMEASURED and nothing was written: node(id: \${3}) came back null, so that id did not resolve — it is stale, it names an object this token cannot see, or PROJECT_ID is wrong. This is NOT a missing field, NOT an unset column and NOT an empty board." >&2
|
|
190
|
+
exit 1
|
|
191
|
+
fi
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
# An empty item id means the add step did not produce one. Writing a
|
|
195
|
+
# field against "" returns a confusing NOT_FOUND about the project,
|
|
196
|
+
# so say which half actually failed.
|
|
197
|
+
if [ -z "\${ITEM_ID}" ]; then
|
|
198
|
+
echo "::error title=Board intake::The add step produced no itemId, so there is nothing to move. The item was NOT added and its Status is UNSET — this is not a board that merely missed a transition." >&2
|
|
199
|
+
exit 1
|
|
200
|
+
fi
|
|
201
|
+
|
|
202
|
+
# A TRUNCATED PAGE IS NOT AN ABSENT VALUE, and this step asked three
|
|
203
|
+
# connections for a FIRST page and then read "not in it" as "not
|
|
204
|
+
# there" at all three. Every one of them had the same consequence:
|
|
205
|
+
# a confident error message naming a cause that did not happen.
|
|
206
|
+
#
|
|
207
|
+
# Found in review round 8, reported at one site. It is a population
|
|
208
|
+
# — \`fields\`, \`fieldValues\` and the index \`items\` query — and the
|
|
209
|
+
# round that introduced it fixed the identical shape in the board
|
|
210
|
+
# sweep without carrying it across.
|
|
211
|
+
#
|
|
212
|
+
# THAT SWEEP IS NOT IN THIS TREE. It is \`scripts/board-status-sweep.ts\`
|
|
213
|
+
# on branch \`rg/board-sweep\`, open as PR #1754 and unmerged, so a
|
|
214
|
+
# reader of this file cannot resolve the path and review was right
|
|
215
|
+
# to say so. Naming the pull request instead: a cross-branch
|
|
216
|
+
# reference a reader can follow beats a path that 404s, and the
|
|
217
|
+
# citation is kept rather than deleted because the precedent is the
|
|
218
|
+
# reason this fix has the shape it does.
|
|
219
|
+
#
|
|
220
|
+
# The repair is NOT a bigger page. A bigger page has the same defect
|
|
221
|
+
# further out. Each connection now asks \`pageInfo { hasNextPage }\`,
|
|
222
|
+
# and "wanted value not found AND the page was full" is reported as
|
|
223
|
+
# UNMEASURED with its own message — the same treatment #1754 gives
|
|
224
|
+
# the same fact under the name \`statusUnread\`, so the two halves
|
|
225
|
+
# answer it the same way once both land.
|
|
226
|
+
# \`test/board-intake.test.ts\` BI-10 asserts the population rather
|
|
227
|
+
# than any one site.
|
|
228
|
+
fields=$(gql -f project="\${PROJECT_ID}" -f query='
|
|
229
|
+
query($project: ID!) {
|
|
230
|
+
node(id: $project) {
|
|
231
|
+
... on ProjectV2 {
|
|
232
|
+
fields(first: 50) {
|
|
233
|
+
pageInfo { hasNextPage }
|
|
234
|
+
nodes { ... on ProjectV2SingleSelectField { id name options { id name } } }
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}' --jq '.data.node.fields')
|
|
239
|
+
require_node "the project's field list" "\${fields}" "\${PROJECT_ID}"
|
|
240
|
+
|
|
241
|
+
status=$(printf '%s' "\${fields}" | jq -r '[.nodes[] | select(.name == "Status")] | first // empty')
|
|
242
|
+
field_id=$(printf '%s' "\${status}" | jq -r '.id // empty')
|
|
243
|
+
option_id=$(printf '%s' "\${status}" | jq -r --arg c "\${COLUMN}" '.options[]? | select(.name == $c) | .id')
|
|
244
|
+
|
|
245
|
+
if [ -z "\${field_id}" ] && [ "$(printf '%s' "\${fields}" | jq -r '.pageInfo.hasNextPage')" = "true" ]; then
|
|
246
|
+
echo "::error title=Board intake::The first 50 fields on this project do not include one named 'Status', AND there are more fields beyond that page — so this read is UNMEASURED, not a missing field. Nothing was written. Do not rename anything on the strength of this message; page the fields query instead." >&2
|
|
247
|
+
exit 1
|
|
248
|
+
fi
|
|
249
|
+
|
|
250
|
+
# Resolved by name on purpose, so a renamed field or column is a red
|
|
251
|
+
# job rather than a stale node id writing the wrong column quietly.
|
|
252
|
+
# Reachable only when the page was NOT truncated, so it can now say
|
|
253
|
+
# "renamed" and mean it.
|
|
254
|
+
if [ -z "\${field_id}" ] || [ -z "\${option_id}" ]; then
|
|
255
|
+
echo "::error title=Board intake::Could not resolve the Status field or its '\${COLUMN}' option on this project. The whole field list was read, so this is not a truncated page. The item WAS added; only the transition failed. Someone renamed the field or the column — update COLUMN in this workflow to match the board." >&2
|
|
256
|
+
exit 1
|
|
257
|
+
fi
|
|
258
|
+
|
|
259
|
+
# WRITE, THEN READ BACK. Keying off the add step's itemId settles
|
|
260
|
+
# WHICH item is written and says nothing about WHEN. This job and
|
|
261
|
+
# GitHub's built-in "Item added to project" automation fire off the
|
|
262
|
+
# same event and run concurrently, and this one is the slower of
|
|
263
|
+
# the two by construction: it resolves the field and the option
|
|
264
|
+
# first, which is two round trips the built-in does not make. If
|
|
265
|
+
# the built-in's "set to Backlog" lands after this step's write,
|
|
266
|
+
# the board reverts and the defect this workflow exists to fix
|
|
267
|
+
# returns non-deterministically.
|
|
268
|
+
#
|
|
269
|
+
# So the mutation's exit code is NOT a reading of the board. A
|
|
270
|
+
# write whose effect is never read is indistinguishable from one
|
|
271
|
+
# overwritten a millisecond later
|
|
272
|
+
# (\`.claude/rules/checks-must-be-able-to-fail.md\`, the sixth
|
|
273
|
+
# shape). Three attempts, each verified, and a loud refusal if the
|
|
274
|
+
# last one did not stick.
|
|
275
|
+
for attempt in 1 2 3; do
|
|
276
|
+
gql \\
|
|
277
|
+
-f project="\${PROJECT_ID}" -f item="\${ITEM_ID}" \\
|
|
278
|
+
-f field="\${field_id}" -f option="\${option_id}" -f query='
|
|
279
|
+
mutation($project: ID!, $item: ID!, $field: ID!, $option: String!) {
|
|
280
|
+
updateProjectV2ItemFieldValue(input: {
|
|
281
|
+
projectId: $project, itemId: $item, fieldId: $field,
|
|
282
|
+
value: { singleSelectOptionId: $option }
|
|
283
|
+
}) { projectV2Item { id } }
|
|
284
|
+
}' --jq '.data.updateProjectV2ItemFieldValue.projectV2Item.id' > /dev/null
|
|
285
|
+
|
|
286
|
+
# Give a concurrent built-in write time to land, so the read-back
|
|
287
|
+
# observes the SETTLED value rather than this step's own write
|
|
288
|
+
# racing ahead of it. Reading immediately would report success
|
|
289
|
+
# and then be overwritten, which is the exact failure being
|
|
290
|
+
# guarded against.
|
|
291
|
+
sleep 3
|
|
292
|
+
|
|
293
|
+
values=$(gql -f item="\${ITEM_ID}" -f query='
|
|
294
|
+
query($item: ID!) {
|
|
295
|
+
node(id: $item) {
|
|
296
|
+
... on ProjectV2Item {
|
|
297
|
+
fieldValues(first: 50) {
|
|
298
|
+
pageInfo { hasNextPage }
|
|
299
|
+
nodes {
|
|
300
|
+
... on ProjectV2ItemFieldSingleSelectValue {
|
|
301
|
+
name field { ... on ProjectV2FieldCommon { name } }
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}' --jq '.data.node.fieldValues')
|
|
308
|
+
require_node "the item's field values, read back after the write" "\${values}" "\${ITEM_ID}"
|
|
309
|
+
|
|
310
|
+
current=$(printf '%s' "\${values}" | jq -r '[.nodes[] | select(.field.name == "Status") | .name] | first // ""')
|
|
311
|
+
|
|
312
|
+
# The worst of the three, because its wrong diagnosis is the one
|
|
313
|
+
# a reader would act on: an item carrying more field values than
|
|
314
|
+
# the page holds reads back as "" and the loop below blames a
|
|
315
|
+
# competing writer for a race that never happened, three times,
|
|
316
|
+
# then fails a job whose write in fact succeeded.
|
|
317
|
+
if [ -z "\${current}" ] && [ "$(printf '%s' "\${values}" | jq -r '.pageInfo.hasNextPage')" = "true" ]; then
|
|
318
|
+
echo "::error title=Board intake::Status was not among this item's first 50 field values and there are more beyond that page, so the read-back is UNMEASURED — the write may well have worked. This is NOT a competing writer and NOT an unset column. Page the fieldValues query." >&2
|
|
319
|
+
exit 1
|
|
320
|
+
fi
|
|
321
|
+
|
|
322
|
+
# THE FIELD VALUE IS NOT WHAT THE BOARD DRAWS, AND THIS STEP USED
|
|
323
|
+
# TO STOP HERE. Projects serves a board view from a SEARCH INDEX
|
|
324
|
+
# that is separate from the item data, and the two can disagree.
|
|
325
|
+
#
|
|
326
|
+
# Measured on this project, 2026-11-04. Four pull requests held
|
|
327
|
+
# Status "In review" in the data; \`items(query: "status:...")\`
|
|
328
|
+
# returned two, and the board drew exactly those two. #1740 and
|
|
329
|
+
# #1747 were invisible on the board for over an hour while every
|
|
330
|
+
# field-value read said they were fine — which is precisely the
|
|
331
|
+
# read this loop was doing.
|
|
332
|
+
#
|
|
333
|
+
# So a read-back that only asks the data path CANNOT observe the
|
|
334
|
+
# failure it exists to catch: it returns "In review", the job
|
|
335
|
+
# reports success, and nobody sees the card. Right exit code,
|
|
336
|
+
# wrong mechanism (\`.claude/rules/checks-must-be-able-to-fail.md\`,
|
|
337
|
+
# the sixth shape).
|
|
338
|
+
#
|
|
339
|
+
# Both readings must agree before this job claims the move worked.
|
|
340
|
+
index_page=$(gql -f project="\${PROJECT_ID}" -f q="status:\\"\${COLUMN}\\"" -f query='
|
|
341
|
+
query($project: ID!, $q: String!) {
|
|
342
|
+
node(id: $project) {
|
|
343
|
+
... on ProjectV2 {
|
|
344
|
+
items(first: 100, query: $q) {
|
|
345
|
+
pageInfo { hasNextPage }
|
|
346
|
+
nodes { id }
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}' --jq '.data.node.items')
|
|
351
|
+
require_node "the search index for the '\${COLUMN}' column" "\${index_page}" "\${PROJECT_ID}"
|
|
352
|
+
|
|
353
|
+
# \`--arg\` rather than interpolating ITEM_ID into the jq program.
|
|
354
|
+
# The id is minted by GitHub so this is not a sanitisation fix; a
|
|
355
|
+
# value pasted into a program text is simply a different thing
|
|
356
|
+
# from a value passed to one, and only one of them stays a value.
|
|
357
|
+
indexed=$(printf '%s' "\${index_page}" | jq -r --arg id "\${ITEM_ID}" '[.nodes[].id] | index($id) // empty')
|
|
358
|
+
|
|
359
|
+
# The third site. A column holding more than 100 cards is not
|
|
360
|
+
# hypothetical on a 121-item board, and without this the job
|
|
361
|
+
# reports the card as absent from the index and tells a human to
|
|
362
|
+
# go and look at an index that is in fact correct.
|
|
363
|
+
if [ -z "\${indexed}" ] && [ "$(printf '%s' "\${index_page}" | jq -r '.pageInfo.hasNextPage')" = "true" ]; then
|
|
364
|
+
echo "::error title=Board intake::More than 100 items match '\${COLUMN}' in the project's search index and this item was not in the first page, so its membership is UNMEASURED — it may well be indexed and rendering. Do not read this as a missing card. Page the index query." >&2
|
|
365
|
+
exit 1
|
|
366
|
+
fi
|
|
367
|
+
|
|
368
|
+
if [ "\${current}" = "\${COLUMN}" ] && [ -n "\${indexed}" ]; then
|
|
369
|
+
echo "::notice title=Board intake::Moved to '\${COLUMN}' on attempt \${attempt}, confirmed in BOTH the item's field value and the project's search index — so the card will actually render. This workflow owns only the opened->In review edge; merged->Done and closed->Done remain GitHub's built-in project workflows, so exactly one decider writes each transition."
|
|
370
|
+
exit 0
|
|
371
|
+
fi
|
|
372
|
+
|
|
373
|
+
if [ "\${current}" = "\${COLUMN}" ]; then
|
|
374
|
+
echo "Attempt \${attempt}: the field value reads '\${COLUMN}' but the search index does not carry this item yet, so the board would not draw it. Re-writing to prompt a re-index."
|
|
375
|
+
else
|
|
376
|
+
echo "Attempt \${attempt}: wrote '\${COLUMN}', read back '\${current:-(nothing)}' — a concurrent write won. Retrying."
|
|
377
|
+
fi
|
|
378
|
+
done
|
|
379
|
+
|
|
380
|
+
if [ "\${current}" = "\${COLUMN}" ]; then
|
|
381
|
+
echo "::error title=Board intake::The Status field reads '\${COLUMN}' but after three attempts the project's SEARCH INDEX still does not list this item under it, and the board draws from the index. The data is right and the card is invisible — do not 'fix' the Status, it is already correct. Re-writing the same value is what repairs the index entry; if three did not take, the index is lagging and this needs a human to re-check later." >&2
|
|
382
|
+
exit 1
|
|
383
|
+
fi
|
|
384
|
+
|
|
385
|
+
echo "::error title=Board intake::Wrote '\${COLUMN}' three times and the board still reads '\${current:-(nothing)}'. Something else is writing this item's Status and winning: check the project's built-in workflows for a rule that also fires on a pull request being added. The item IS on the board; only its column is wrong. Not exiting 0 on this — a job that writes and does not check is how the column silently reverted before." >&2
|
|
386
|
+
exit 1
|
|
387
|
+
`;
|
|
388
|
+
|
|
389
|
+
export interface BoardIntakeWorkflowOptions {
|
|
390
|
+
/** The `runs-on:` value, already JSON-quoted by the caller. */
|
|
391
|
+
runsOn: string;
|
|
392
|
+
/** The pinned `actions/checkout` reference. */
|
|
393
|
+
checkout: string;
|
|
394
|
+
/** The pinned `oven-sh/setup-bun` reference. */
|
|
395
|
+
setupBun: string;
|
|
396
|
+
/** The `with:` body of that step, at ten spaces — the project's single bun declaration (#622). */
|
|
397
|
+
setupBunWith: string;
|
|
398
|
+
/** The step's `env:` block, from `setupBunEnv` (#2039). */
|
|
399
|
+
setupBunEnv: string;
|
|
400
|
+
/** The published harness version the add step runs through `bunx`. */
|
|
401
|
+
version: string;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** The whole `board-intake.yml` body. */
|
|
405
|
+
export function buildBoardIntakeWorkflow(opts: BoardIntakeWorkflowOptions): string {
|
|
406
|
+
const indent = (text: string, pad: string) =>
|
|
407
|
+
text
|
|
408
|
+
.trimEnd()
|
|
409
|
+
.split("\n")
|
|
410
|
+
.map(line => (line === "" ? "" : `${pad}${line}`))
|
|
411
|
+
.join("\n");
|
|
412
|
+
|
|
413
|
+
return `# Managed by rungate — do not edit. The board is board.id in .claude/rungate/config.json.
|
|
414
|
+
#
|
|
415
|
+
# Every new issue and pull request goes on the board, and a pull request
|
|
416
|
+
# offered for review moves to In review. Generated since #2166, and it names
|
|
417
|
+
# no project id or URL: \`rungate ${BOARD_ID_COMMAND}\` reads board.id from the
|
|
418
|
+
# default branch's config, and the add uses that node id.
|
|
419
|
+
#
|
|
420
|
+
# Needs the RUNGATE_PROJECT_TOKEN secret: a token that can write the project
|
|
421
|
+
# board, which GITHUB_TOKEN cannot. Without it, or without board.id, the run
|
|
422
|
+
# is an UNMEASURED annotation, not a red run.
|
|
423
|
+
name: Board intake
|
|
424
|
+
|
|
425
|
+
on:
|
|
426
|
+
issues:
|
|
427
|
+
types: [opened, reopened]
|
|
428
|
+
pull_request_target:
|
|
429
|
+
types: [opened, reopened, ready_for_review]
|
|
430
|
+
|
|
431
|
+
permissions:
|
|
432
|
+
contents: read
|
|
433
|
+
|
|
434
|
+
jobs:
|
|
435
|
+
${BOARD_INTAKE_JOB}:
|
|
436
|
+
runs-on: ${opts.runsOn}
|
|
437
|
+
steps:
|
|
438
|
+
# The default branch, never the pull request: pull_request_target holds a
|
|
439
|
+
# board-writing token, and the config is the only input read from the tree.
|
|
440
|
+
- uses: ${opts.checkout}
|
|
441
|
+
with:
|
|
442
|
+
ref: \${{ github.event.repository.default_branch }}
|
|
443
|
+
persist-credentials: false
|
|
444
|
+
- uses: ${opts.setupBun}
|
|
445
|
+
with:
|
|
446
|
+
${opts.setupBunWith}
|
|
447
|
+
${opts.setupBunEnv}
|
|
448
|
+
- id: add
|
|
449
|
+
name: Add the issue or pull request to the board
|
|
450
|
+
env:
|
|
451
|
+
GH_TOKEN: \${{ secrets.RUNGATE_PROJECT_TOKEN }}
|
|
452
|
+
CONTENT_ID: \${{ github.event.issue.node_id || github.event.pull_request.node_id }}
|
|
453
|
+
run: |
|
|
454
|
+
${indent(buildBoardIntakeAddScript(opts.version), " ")}
|
|
455
|
+
# Only the opened -> In review edge; merged and closed stay with GitHub's
|
|
456
|
+
# built-in workflows, so each transition has one decider. Not a draft:
|
|
457
|
+
# a draft in \`In review\` says somebody is waiting on a reader when nobody is.
|
|
458
|
+
# Drafts stay in Backlog until \`ready_for_review\`, which this subscribes to.
|
|
459
|
+
- name: Move the pull request to In review
|
|
460
|
+
if: github.event_name == 'pull_request_target' && github.event.pull_request.draft == false && steps.add.outputs.itemId != ''
|
|
461
|
+
env:
|
|
462
|
+
GH_TOKEN: \${{ secrets.RUNGATE_PROJECT_TOKEN }}
|
|
463
|
+
PROJECT_ID: \${{ steps.add.outputs.projectId }}
|
|
464
|
+
ITEM_ID: \${{ steps.add.outputs.itemId }}
|
|
465
|
+
COLUMN: In review
|
|
466
|
+
run: |
|
|
467
|
+
${indent(BOARD_INTAKE_MOVE_SCRIPT, " ")}
|
|
468
|
+
`;
|
|
469
|
+
}
|