rungate 0.8.19 → 0.8.21
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/ai-review-threads.ts +46 -2
- package/lib/board-intake-move.ts +292 -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/ai-review-findings.ts +33 -7
- package/lib/scaffold/board-intake-workflow.ts +214 -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/ai-review-threads.ts +15 -3
- package/scripts/board-intake-move.ts +80 -0
- package/scripts/unaccounted-work.ts +122 -0
|
@@ -1156,7 +1156,15 @@ export function reviewThreadRequests(
|
|
|
1156
1156
|
// posting less.
|
|
1157
1157
|
const scope = reading.scope;
|
|
1158
1158
|
let touched: ReadonlySet<string> | null = null;
|
|
1159
|
+
// The diff's own spelling of each changed file, keyed by the comparison
|
|
1160
|
+
// form. When a finding matches one, THAT spelling is sent: it is byte for
|
|
1161
|
+
// byte what the API resolves against (#1992).
|
|
1162
|
+
const diffSpelling = new Map<string, string>();
|
|
1159
1163
|
if (scope?.status === "MEASURED") {
|
|
1164
|
+
for (const entry of scope.files) {
|
|
1165
|
+
const spelt = repoPathSpelling(entry);
|
|
1166
|
+
if (spelt !== null) diffSpelling.set(spelt.toLowerCase(), spelt);
|
|
1167
|
+
}
|
|
1160
1168
|
// The same conversion `readPayload` makes, through the same function, so
|
|
1161
1169
|
// the skip here and the demotion there cannot disagree about one finding.
|
|
1162
1170
|
const { readable } = partitionChangedFiles(scope.files);
|
|
@@ -1176,13 +1184,17 @@ export function reviewThreadRequests(
|
|
|
1176
1184
|
if (findingPathScope(finding, touched) === "PRE_EXISTING") continue;
|
|
1177
1185
|
|
|
1178
1186
|
const raw = finding[f.file];
|
|
1179
|
-
//
|
|
1180
|
-
//
|
|
1181
|
-
//
|
|
1182
|
-
//
|
|
1183
|
-
|
|
1187
|
+
// The scope check above matched the NORMALISED spelling; the raw one —
|
|
1188
|
+
// `./lib/a.ts`, `lib//a.ts` — asks the API for a path it cannot resolve,
|
|
1189
|
+
// the file-level retry is refused the same way, and the round ends
|
|
1190
|
+
// FAILED over a finding that was correctly in the diff (#1992). So the
|
|
1191
|
+
// diff's own spelling is sent when the finding matched one, and the
|
|
1192
|
+
// finding's case-kept spelling otherwise. Both drop a `:line` suffix;
|
|
1193
|
+
// the number in it is still read below, as the only line given.
|
|
1194
|
+
const spelt = repoPathSpelling(raw);
|
|
1195
|
+
if (spelt === null) continue;
|
|
1196
|
+
const path = diffSpelling.get(spelt.toLowerCase()) ?? spelt;
|
|
1184
1197
|
const suffixed = String(raw).trim().replace(/\\/g, "/").match(/^(.*?):(\d+)(?::\d+)?$/);
|
|
1185
|
-
const path = suffixed ? suffixed[1]! : String(raw).trim().replace(/\\/g, "/");
|
|
1186
1198
|
|
|
1187
1199
|
const declared = finding[f.line];
|
|
1188
1200
|
const line =
|
|
@@ -2016,8 +2028,22 @@ function readPayload(
|
|
|
2016
2028
|
* deliberately `null` rather than unescaped here: decoding octal escapes to
|
|
2017
2029
|
* compare a path is a second parser, and the right repair is to produce the
|
|
2018
2030
|
* list with `-z` or `core.quotePath=false` in the first place.
|
|
2031
|
+
*
|
|
2032
|
+
* It is `repoPathSpelling` lowercased: the two share every rule but case,
|
|
2033
|
+
* because this one COMPARES and that one is SENT (#1992).
|
|
2019
2034
|
*/
|
|
2020
2035
|
export function normaliseRepoPath(value: unknown): string | null {
|
|
2036
|
+
return repoPathSpelling(value)?.toLowerCase() ?? null;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
/**
|
|
2040
|
+
* A path in the spelling the REST API can match: dot segments collapsed,
|
|
2041
|
+
* leading slashes, backslashes and a `:line` suffix removed, CASE KEPT. The
|
|
2042
|
+
* API matches the diff byte for byte, so the lowercased comparison form is
|
|
2043
|
+
* the predicate and never the value (#1992). `null` exactly where
|
|
2044
|
+
* `normaliseRepoPath` is `null`, because that one is this one lowercased.
|
|
2045
|
+
*/
|
|
2046
|
+
export function repoPathSpelling(value: unknown): string | null {
|
|
2021
2047
|
if (typeof value !== "string") return null;
|
|
2022
2048
|
let p = value.trim().replace(/\\/g, "/");
|
|
2023
2049
|
// git's C-quoted spelling. Not comparable without a second unescaper.
|
|
@@ -2053,7 +2079,7 @@ export function normaliseRepoPath(value: unknown): string | null {
|
|
|
2053
2079
|
p = out.join("/");
|
|
2054
2080
|
if (p === "") return null;
|
|
2055
2081
|
|
|
2056
|
-
return /^(?:[\w.@+-]+\/)*[\w.@+-]+$/.test(p) ? p
|
|
2082
|
+
return /^(?:[\w.@+-]+\/)*[\w.@+-]+$/.test(p) ? p : null;
|
|
2057
2083
|
}
|
|
2058
2084
|
|
|
2059
2085
|
/** What a changed-file list reduced to, split by whether it could be read. */
|
|
@@ -0,0 +1,214 @@
|
|
|
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
|
|
34
|
+
*
|
|
35
|
+
* Since #2183 the step is one call to `rungate board-intake-move`
|
|
36
|
+
* (`lib/board-intake-move.ts`, #2193); the retry, the read-backs, the
|
|
37
|
+
* truncation and null-node refusals below are that code's, each tested in
|
|
38
|
+
* test/board-intake-move.test.ts. This file keeps the step's shape:
|
|
39
|
+
*
|
|
40
|
+
* - It owns only the opened -> In review edge. `merged -> Done` and
|
|
41
|
+
* `closed -> Done` stay with GitHub's built-in workflows, so each
|
|
42
|
+
* transition has exactly one decider. Do not add a merge or close handler.
|
|
43
|
+
* - Drafts are not moved (BI-2): Jason's call, 2026-11-04.
|
|
44
|
+
* - It keys off the item the add step created (BI-1), never a re-query, which
|
|
45
|
+
* would race the built-in "Item added to project" workflow.
|
|
46
|
+
* - Every call is retried, every write is read back from the item AND from the
|
|
47
|
+
* project's search index, a full page is never read as absence, and a null
|
|
48
|
+
* or wrong-type node is refused by naming the id: in the command.
|
|
49
|
+
* - No `${{ }}` inside a `run:` block (BI-4), and no scratch file (BI-12).
|
|
50
|
+
* - The field and option are resolved by NAME at run time, so a renamed
|
|
51
|
+
* column fails loudly rather than writing a stale id.
|
|
52
|
+
*
|
|
53
|
+
* The incidents behind each of these are in the hand-written file's history
|
|
54
|
+
* (git log -- .github/workflows/board-intake.yml, before #2166).
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/** The file this module generates, under `.github/workflows/`. */
|
|
58
|
+
export const BOARD_INTAKE_WORKFLOW_FILE = "board-intake.yml";
|
|
59
|
+
|
|
60
|
+
/** The one job in it. */
|
|
61
|
+
export const BOARD_INTAKE_JOB = "add-to-board";
|
|
62
|
+
|
|
63
|
+
/** The CLI command the add step runs to learn the board (#2173). */
|
|
64
|
+
export const BOARD_ID_COMMAND = "board-id";
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* How `rungate board-id` begins its no-board refusal. Exit 2 alone also
|
|
68
|
+
* covers a usage error, so the add step softens only this wording;
|
|
69
|
+
* `test/board-intake.test.ts` holds it to `scripts/board-id.ts`.
|
|
70
|
+
*/
|
|
71
|
+
export { NO_BOARD_REFUSAL } from "./board-ready-workflow";
|
|
72
|
+
import { NO_BOARD_REFUSAL } from "./board-ready-workflow";
|
|
73
|
+
|
|
74
|
+
/** The add step's `run:` body. Exported so a test executes THIS text. */
|
|
75
|
+
export function buildBoardIntakeAddScript(version: string): string {
|
|
76
|
+
return `set -euo pipefail
|
|
77
|
+
if [ -z "\${GH_TOKEN}" ]; then
|
|
78
|
+
echo "::warning title=Board intake::UNMEASURED — RUNGATE_PROJECT_TOKEN is not set, so nothing was added to the board."
|
|
79
|
+
exit 0
|
|
80
|
+
fi
|
|
81
|
+
# The board is board.id in the default branch's config. Only the no-board
|
|
82
|
+
# refusal (exit 2 AND its own wording) is an annotation; a usage error is red.
|
|
83
|
+
code=0
|
|
84
|
+
project=$(bunx rungate@${version} ${BOARD_ID_COMMAND} 2>"\${RUNNER_TEMP}/board-id.stderr") || code=$?
|
|
85
|
+
cat "\${RUNNER_TEMP}/board-id.stderr" >&2
|
|
86
|
+
if [ "\${code}" -eq 2 ] && grep -q '^${NO_BOARD_REFUSAL}' "\${RUNNER_TEMP}/board-id.stderr"; then
|
|
87
|
+
echo "::warning title=Board intake::UNMEASURED — no board.id in the rungate config, so nothing was added. Set board.id and this runs."
|
|
88
|
+
exit 0
|
|
89
|
+
fi
|
|
90
|
+
if [ "\${code}" -ne 0 ]; then
|
|
91
|
+
exit "\${code}"
|
|
92
|
+
fi
|
|
93
|
+
# Done only on a real id: an exit-0 reply carrying null is retried too (#2185).
|
|
94
|
+
item=""
|
|
95
|
+
tried=0
|
|
96
|
+
: > "\${RUNNER_TEMP}/add.stderr"
|
|
97
|
+
for attempt in 1 2 3; do
|
|
98
|
+
tried=\${attempt}
|
|
99
|
+
item=$(gh api graphql -f project="\${project}" -f content="\${CONTENT_ID}" -f query='
|
|
100
|
+
mutation($project: ID!, $content: ID!) {
|
|
101
|
+
addProjectV2ItemById(input: { projectId: $project, contentId: $content }) { item { id } }
|
|
102
|
+
}' --jq '.data.addProjectV2ItemById.item.id' 2>"\${RUNNER_TEMP}/add.stderr") || item=""
|
|
103
|
+
if [ -n "\${item}" ] && [ "\${item}" != "null" ]; then
|
|
104
|
+
break
|
|
105
|
+
fi
|
|
106
|
+
item=""
|
|
107
|
+
sleep $(( attempt * 2 ))
|
|
108
|
+
done
|
|
109
|
+
if [ -z "\${item}" ]; then
|
|
110
|
+
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
|
|
111
|
+
exit 1
|
|
112
|
+
fi
|
|
113
|
+
echo "itemId=\${item}" >> "\${GITHUB_OUTPUT}"
|
|
114
|
+
echo "projectId=\${project}" >> "\${GITHUB_OUTPUT}"
|
|
115
|
+
`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The CLI command the move step runs (#2193, #2183). */
|
|
119
|
+
export const BOARD_INTAKE_MOVE_COMMAND = "board-intake-move";
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The move step's `run:` body: one call to the tested command. Its 260 lines
|
|
123
|
+
* of shell are now `lib/board-intake-move.ts`, and each refusal is observed
|
|
124
|
+
* failing against a stub client in `test/board-intake-move.test.ts`. Values
|
|
125
|
+
* arrive through `env:`, never interpolated into this block (BI-4).
|
|
126
|
+
* Exported so a test reads THIS text.
|
|
127
|
+
*/
|
|
128
|
+
export function buildBoardIntakeMoveScript(version: string): string {
|
|
129
|
+
return `set -euo pipefail
|
|
130
|
+
bunx rungate@${version} ${BOARD_INTAKE_MOVE_COMMAND} --project "\${PROJECT_ID}" --item "\${ITEM_ID}" --column "\${COLUMN}"
|
|
131
|
+
`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface BoardIntakeWorkflowOptions {
|
|
135
|
+
/** The `runs-on:` value, already JSON-quoted by the caller. */
|
|
136
|
+
runsOn: string;
|
|
137
|
+
/** The pinned `actions/checkout` reference. */
|
|
138
|
+
checkout: string;
|
|
139
|
+
/** The pinned `oven-sh/setup-bun` reference. */
|
|
140
|
+
setupBun: string;
|
|
141
|
+
/** The `with:` body of that step, at ten spaces — the project's single bun declaration (#622). */
|
|
142
|
+
setupBunWith: string;
|
|
143
|
+
/** The step's `env:` block, from `setupBunEnv` (#2039). */
|
|
144
|
+
setupBunEnv: string;
|
|
145
|
+
/** The published harness version the add step runs through `bunx`. */
|
|
146
|
+
version: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The whole `board-intake.yml` body. */
|
|
150
|
+
export function buildBoardIntakeWorkflow(opts: BoardIntakeWorkflowOptions): string {
|
|
151
|
+
const indent = (text: string, pad: string) =>
|
|
152
|
+
text
|
|
153
|
+
.trimEnd()
|
|
154
|
+
.split("\n")
|
|
155
|
+
.map(line => (line === "" ? "" : `${pad}${line}`))
|
|
156
|
+
.join("\n");
|
|
157
|
+
|
|
158
|
+
return `# Managed by rungate — do not edit. The board is board.id in .claude/rungate/config.json.
|
|
159
|
+
#
|
|
160
|
+
# Every new issue and pull request goes on the board, and a pull request
|
|
161
|
+
# offered for review moves to In review. Generated since #2166, and it names
|
|
162
|
+
# no project id or URL: \`rungate ${BOARD_ID_COMMAND}\` reads board.id from the
|
|
163
|
+
# default branch's config, and the add uses that node id.
|
|
164
|
+
#
|
|
165
|
+
# Needs the RUNGATE_PROJECT_TOKEN secret: a token that can write the project
|
|
166
|
+
# board, which GITHUB_TOKEN cannot. Without it, or without board.id, the run
|
|
167
|
+
# is an UNMEASURED annotation, not a red run.
|
|
168
|
+
name: Board intake
|
|
169
|
+
|
|
170
|
+
on:
|
|
171
|
+
issues:
|
|
172
|
+
types: [opened, reopened]
|
|
173
|
+
pull_request_target:
|
|
174
|
+
types: [opened, reopened, ready_for_review]
|
|
175
|
+
|
|
176
|
+
permissions:
|
|
177
|
+
contents: read
|
|
178
|
+
|
|
179
|
+
jobs:
|
|
180
|
+
${BOARD_INTAKE_JOB}:
|
|
181
|
+
runs-on: ${opts.runsOn}
|
|
182
|
+
steps:
|
|
183
|
+
# The default branch, never the pull request: pull_request_target holds a
|
|
184
|
+
# board-writing token, and the config is the only input read from the tree.
|
|
185
|
+
- uses: ${opts.checkout}
|
|
186
|
+
with:
|
|
187
|
+
ref: \${{ github.event.repository.default_branch }}
|
|
188
|
+
persist-credentials: false
|
|
189
|
+
- uses: ${opts.setupBun}
|
|
190
|
+
with:
|
|
191
|
+
${opts.setupBunWith}
|
|
192
|
+
${opts.setupBunEnv}
|
|
193
|
+
- id: add
|
|
194
|
+
name: Add the issue or pull request to the board
|
|
195
|
+
env:
|
|
196
|
+
GH_TOKEN: \${{ secrets.RUNGATE_PROJECT_TOKEN }}
|
|
197
|
+
CONTENT_ID: \${{ github.event.issue.node_id || github.event.pull_request.node_id }}
|
|
198
|
+
run: |
|
|
199
|
+
${indent(buildBoardIntakeAddScript(opts.version), " ")}
|
|
200
|
+
# Only the opened -> In review edge; merged and closed stay with GitHub's
|
|
201
|
+
# built-in workflows, so each transition has one decider. Not a draft:
|
|
202
|
+
# a draft in \`In review\` says somebody is waiting on a reader when nobody is.
|
|
203
|
+
# Drafts stay in Backlog until \`ready_for_review\`, which this subscribes to.
|
|
204
|
+
- name: Move the pull request to In review
|
|
205
|
+
if: github.event_name == 'pull_request_target' && github.event.pull_request.draft == false && steps.add.outputs.itemId != ''
|
|
206
|
+
env:
|
|
207
|
+
GH_TOKEN: \${{ secrets.RUNGATE_PROJECT_TOKEN }}
|
|
208
|
+
PROJECT_ID: \${{ steps.add.outputs.projectId }}
|
|
209
|
+
ITEM_ID: \${{ steps.add.outputs.itemId }}
|
|
210
|
+
COLUMN: In review
|
|
211
|
+
run: |
|
|
212
|
+
${indent(buildBoardIntakeMoveScript(opts.version), " ")}
|
|
213
|
+
`;
|
|
214
|
+
}
|
|
@@ -33,8 +33,8 @@ export const REQUIRE_CLOSING_REF_VARIABLE = "RUNGATE_REQUIRE_CLOSING_REF";
|
|
|
33
33
|
export const PROCESS_CHECK_WORKFLOWS = ["closing-references.yml"] as const;
|
|
34
34
|
|
|
35
35
|
export interface HumanStepReadings {
|
|
36
|
-
/** `owner/name
|
|
37
|
-
slug: string | null
|
|
36
|
+
/** `owner/name`; null when the origin remote names no GitHub repository; UNMEASURED when it could not be read (#2169). */
|
|
37
|
+
slug: Reading<string | null>;
|
|
38
38
|
secretPresent: Reading<boolean>;
|
|
39
39
|
/** The variable's value, or null when it is not set. */
|
|
40
40
|
requireClosingRef: Reading<string | null>;
|
|
@@ -49,20 +49,25 @@ export interface HumanStepReadings {
|
|
|
49
49
|
/** One line per step owed or unread, then a line saying what was measured. Pure. */
|
|
50
50
|
export function humanSteps(r: HumanStepReadings): string[] {
|
|
51
51
|
const unreadWorkflows = r.unreadableWorkflows.map(why => `UNMEASURED: process checks — ${why}`);
|
|
52
|
-
if (r.slug === null) {
|
|
52
|
+
if (r.slug.kind === "UNMEASURED" || r.slug.value === null) {
|
|
53
|
+
const why =
|
|
54
|
+
r.slug.kind === "UNMEASURED"
|
|
55
|
+
? `the origin remote could not be read (${r.slug.why})`
|
|
56
|
+
: "the origin remote names no GitHub repository";
|
|
53
57
|
return [
|
|
54
|
-
|
|
58
|
+
`UNMEASURED: human steps — ${why}, so the project token, ` +
|
|
55
59
|
`${REQUIRE_CLOSING_REF_VARIABLE} and the required checks were not read.`,
|
|
56
60
|
// Read from the tree, not from GitHub, so it is owed whatever the remote is.
|
|
57
61
|
...unreadWorkflows,
|
|
58
62
|
];
|
|
59
63
|
}
|
|
64
|
+
const slug = r.slug.value;
|
|
60
65
|
const out: string[] = [];
|
|
61
66
|
const measured: string[] = [];
|
|
62
67
|
if (r.secretPresent.kind === "UNMEASURED") out.push(`UNMEASURED: ${PROJECT_TOKEN_SECRET} — ${r.secretPresent.why}`);
|
|
63
68
|
else if (!r.secretPresent.value) {
|
|
64
69
|
out.push(
|
|
65
|
-
`OWED: gh secret set ${PROJECT_TOKEN_SECRET} -R ${
|
|
70
|
+
`OWED: gh secret set ${PROJECT_TOKEN_SECRET} -R ${slug} # a token that can write the project board; every board step refuses without it`,
|
|
66
71
|
);
|
|
67
72
|
} else measured.push(`${PROJECT_TOKEN_SECRET} is set`);
|
|
68
73
|
|
|
@@ -70,7 +75,7 @@ export function humanSteps(r: HumanStepReadings): string[] {
|
|
|
70
75
|
out.push(`UNMEASURED: ${REQUIRE_CLOSING_REF_VARIABLE} — ${r.requireClosingRef.why}`);
|
|
71
76
|
} else if (r.requireClosingRef.value !== "true") {
|
|
72
77
|
out.push(
|
|
73
|
-
`OWED: gh variable set ${REQUIRE_CLOSING_REF_VARIABLE} -R ${
|
|
78
|
+
`OWED: gh variable set ${REQUIRE_CLOSING_REF_VARIABLE} -R ${slug} --body true # closing-references refuses instead of warning`,
|
|
74
79
|
);
|
|
75
80
|
} else measured.push(`${REQUIRE_CLOSING_REF_VARIABLE} is true`);
|
|
76
81
|
|
|
@@ -85,7 +90,7 @@ export function humanSteps(r: HumanStepReadings): string[] {
|
|
|
85
90
|
if (missing.length > 0 && statusChecks === "required-checks") {
|
|
86
91
|
for (const check of missing) {
|
|
87
92
|
out.push(
|
|
88
|
-
`OWED: gh api -X POST repos/${
|
|
93
|
+
`OWED: gh api -X POST repos/${slug}/branches/${branch}/protection/required_status_checks/contexts ` +
|
|
89
94
|
`-f 'contexts[]=${check}' # ${check} runs on every pull request and blocks nothing until it is required`,
|
|
90
95
|
);
|
|
91
96
|
}
|
|
@@ -99,7 +104,7 @@ export function humanSteps(r: HumanStepReadings): string[] {
|
|
|
99
104
|
restrictions: null,
|
|
100
105
|
};
|
|
101
106
|
out.push(
|
|
102
|
-
`OWED: gh api -X PUT repos/${
|
|
107
|
+
`OWED: gh api -X PUT repos/${slug}/branches/${branch}/protection --input - <<<'${JSON.stringify(body)}'` +
|
|
103
108
|
` # ${branch} is unprotected; this protects it and requires ${missing.join(", ")}, nothing else`,
|
|
104
109
|
);
|
|
105
110
|
} else if (missing.length > 0) {
|
|
@@ -160,30 +165,97 @@ export function processChecksIn(root: string): { checks: string[]; unreadable: s
|
|
|
160
165
|
* module can read. `parseRemoteSlug` deliberately ignores the host, because
|
|
161
166
|
* repo identity is its question; which forge to ask is this one's.
|
|
162
167
|
*/
|
|
163
|
-
export function githubSlugOf(
|
|
168
|
+
export function githubSlugOf(
|
|
169
|
+
url: string,
|
|
170
|
+
resolveSshHost: (host: string) => Reading<string | null> = sshHostName,
|
|
171
|
+
): Reading<string | null> {
|
|
172
|
+
const none = { kind: "READ", value: null } as const;
|
|
164
173
|
const trimmed = url.trim();
|
|
165
|
-
if (!trimmed) return
|
|
174
|
+
if (!trimmed) return none;
|
|
166
175
|
let host: string | null = null;
|
|
176
|
+
let viaSsh = false;
|
|
177
|
+
// A URL's slug comes from its path, so a port (`ssh.github.com:443`) cannot
|
|
178
|
+
// be read as the owner; an scp-style remote has no port to confuse.
|
|
179
|
+
let slug: () => string | null = () => parseRemoteSlug(trimmed);
|
|
167
180
|
if (/^[a-z+]+:\/\//i.test(trimmed)) {
|
|
181
|
+
let parsed: URL;
|
|
168
182
|
try {
|
|
169
|
-
|
|
183
|
+
parsed = new URL(trimmed);
|
|
170
184
|
} catch {
|
|
171
|
-
return
|
|
185
|
+
return none; // not a URL at all, so it names no GitHub repository
|
|
172
186
|
}
|
|
187
|
+
host = parsed.hostname;
|
|
188
|
+
viaSsh = /^(?:ssh|git\+ssh|ssh\+git):$/i.test(parsed.protocol);
|
|
189
|
+
const parts = parsed.pathname.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "").split("/").filter(Boolean);
|
|
190
|
+
slug = () => (parts.length === 2 ? `${parts[0]}/${parts[1]}`.toLowerCase() : null);
|
|
173
191
|
} else {
|
|
174
192
|
host = trimmed.match(/^(?:[^@/]+@)?([^:/]+):/)?.[1] ?? null;
|
|
193
|
+
viaSsh = host !== null;
|
|
175
194
|
}
|
|
176
|
-
|
|
195
|
+
if (host === null) return none;
|
|
196
|
+
const literal = host.toLowerCase();
|
|
197
|
+
// A GitHub host spelled literally is accepted before asking ssh, so a
|
|
198
|
+
// `Host` block rewriting its HostName cannot refuse it, and a machine with
|
|
199
|
+
// no ssh can still read it. Over ssh that is both of GitHub's SSH hosts
|
|
200
|
+
// (review round 2 of PR #2187); over https it is github.com alone.
|
|
201
|
+
if (viaSsh ? GITHUB_SSH_HOSTS.has(literal) : literal === "github.com") return { kind: "READ", value: slug() };
|
|
202
|
+
// An scp-style or ssh:// host may be an alias in ~/.ssh/config
|
|
203
|
+
// (`Host github.com-work` / `HostName github.com`), so ssh decides what it
|
|
204
|
+
// names (#2169). An https host is a DNS name, so it stays a literal compare
|
|
205
|
+
// and a lookalike is still refused.
|
|
206
|
+
if (!viaSsh) return none;
|
|
207
|
+
// The host as written: OpenSSH matches `Host` patterns case-sensitively, so a
|
|
208
|
+
// lowercased `GitHub-Perso` misses its own stanza (review round 3 of PR #2187).
|
|
209
|
+
const resolved = resolveSshHost(host);
|
|
210
|
+
// ssh missing or timed out says nothing about whether the host is GitHub
|
|
211
|
+
// (review of PR #2187), so it is UNMEASURED, never "no GitHub repository".
|
|
212
|
+
if (resolved.kind === "UNMEASURED") return { kind: "UNMEASURED", why: `its host ${host} could not be resolved: ${resolved.why}` };
|
|
213
|
+
const named = resolved.value?.toLowerCase();
|
|
214
|
+
return { kind: "READ", value: named !== undefined && GITHUB_SSH_HOSTS.has(named) ? slug() : null };
|
|
177
215
|
}
|
|
178
216
|
|
|
179
|
-
/** The
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
217
|
+
/** The hosts GitHub serves git over SSH on: the usual one, and the port-443 one its docs give for blocked networks. */
|
|
218
|
+
const GITHUB_SSH_HOSTS = new Set(["github.com", "ssh.github.com"]);
|
|
219
|
+
|
|
220
|
+
/** What `spawnSync` reports, narrowed to what the reads below look at, so a failed read can be tested. */
|
|
221
|
+
export type RunResult = { status: number | null; stdout: string; error?: Error; signal?: NodeJS.Signals | null };
|
|
222
|
+
export type Run = (cmd: string, args: string[], cwd?: string) => RunResult;
|
|
223
|
+
const runLive: Run = (cmd, args, cwd) => spawnSync(cmd, args, { cwd, encoding: "utf-8", timeout: 5000 });
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The host `ssh -G` resolves `host` to (its `hostname` line). A host that could
|
|
227
|
+
* be read as an option never reaches ssh and names nothing. ssh missing, the
|
|
228
|
+
* timeout, a non-zero exit or no hostname line is a reading not taken.
|
|
229
|
+
*/
|
|
230
|
+
export function sshHostName(host: string, run: Run = runLive): Reading<string | null> {
|
|
231
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(host)) return { kind: "READ", value: null };
|
|
232
|
+
const r = run("ssh", ["-G", host]);
|
|
233
|
+
if (r.error) return { kind: "UNMEASURED", why: `ssh -G ${host} could not run (${r.error.message})` };
|
|
234
|
+
if (r.status !== 0) {
|
|
235
|
+
const how = r.status === null ? `was stopped${r.signal ? ` by ${r.signal}` : ""}` : `exited ${r.status}`;
|
|
236
|
+
return { kind: "UNMEASURED", why: `ssh -G ${host} ${how}` };
|
|
237
|
+
}
|
|
238
|
+
const name = r.stdout.match(/^hostname (\S+)$/m)?.[1];
|
|
239
|
+
return name ? { kind: "READ", value: name } : { kind: "UNMEASURED", why: `ssh -G ${host} printed no hostname line` };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The configured `origin` url of `root` (#2169). `""` only when git ran and
|
|
244
|
+
* said none is configured: `git config --get` exits 1 for an absent key. Git
|
|
245
|
+
* missing, a root that does not exist, the timeout, or any other exit is a
|
|
246
|
+
* reading not taken, never "no repository".
|
|
247
|
+
*/
|
|
248
|
+
export function readOrigin(root: string, run: Run = runLive): Reading<string> {
|
|
249
|
+
const r = run("git", ["config", "--get", "remote.origin.url"], root);
|
|
250
|
+
if (r.error) return { kind: "UNMEASURED", why: `git could not read it (${r.error.message})` };
|
|
251
|
+
if (r.status === 0) return { kind: "READ", value: r.stdout };
|
|
252
|
+
if (r.status === 1) return { kind: "READ", value: "" };
|
|
253
|
+
const why = r.status === null ? `git was stopped${r.signal ? ` by ${r.signal}` : ""} before it answered` : `git exited ${r.status}`;
|
|
254
|
+
return { kind: "UNMEASURED", why };
|
|
183
255
|
}
|
|
184
256
|
|
|
185
257
|
export interface HumanStepProbes {
|
|
186
|
-
slug: (root: string) => string | null
|
|
258
|
+
slug: (root: string) => Reading<string | null>;
|
|
187
259
|
secret: (slug: string) => Promise<Reading<boolean>>;
|
|
188
260
|
variable: (slug: string) => Promise<Reading<string | null>>;
|
|
189
261
|
protection: ProtectionProbe;
|
|
@@ -207,7 +279,10 @@ const why = (e: unknown) => `${typeof status(e) === "number" ? `HTTP ${status(e)
|
|
|
207
279
|
|
|
208
280
|
/** The live reads: two GETs here, three in the protection probe. No writes. */
|
|
209
281
|
export const LIVE_PROBES: HumanStepProbes = {
|
|
210
|
-
slug: root =>
|
|
282
|
+
slug: root => {
|
|
283
|
+
const origin = readOrigin(root);
|
|
284
|
+
return origin.kind === "READ" ? githubSlugOf(origin.value) : origin;
|
|
285
|
+
},
|
|
211
286
|
secret: async slug => {
|
|
212
287
|
try {
|
|
213
288
|
const { owner, repo } = parseOwnerRepo(slug);
|
|
@@ -239,11 +314,12 @@ export const LIVE_PROBES: HumanStepProbes = {
|
|
|
239
314
|
|
|
240
315
|
/** Read everything {@link humanSteps} needs for `root`. */
|
|
241
316
|
export async function readHumanSteps(root: string, probes: HumanStepProbes = LIVE_PROBES): Promise<HumanStepReadings> {
|
|
242
|
-
const
|
|
317
|
+
const origin = probes.slug(root);
|
|
243
318
|
const { checks: processChecks, unreadable: unreadableWorkflows } = processChecksIn(root);
|
|
319
|
+
const slug = origin.kind === "READ" ? origin.value : null;
|
|
244
320
|
if (slug === null) {
|
|
245
321
|
const none = { kind: "UNMEASURED", why: "no repository" } as const;
|
|
246
|
-
return { slug, secretPresent: none, requireClosingRef: none, protection: none, processChecks, unreadableWorkflows };
|
|
322
|
+
return { slug: origin, secretPresent: none, requireClosingRef: none, protection: none, processChecks, unreadableWorkflows };
|
|
247
323
|
}
|
|
248
324
|
const [secretPresent, requireClosingRef, facts] = await Promise.all([
|
|
249
325
|
probes.secret(slug),
|
|
@@ -256,5 +332,5 @@ export async function readHumanSteps(root: string, probes: HumanStepProbes = LIV
|
|
|
256
332
|
: facts.statusChecks === undefined
|
|
257
333
|
? { kind: "UNMEASURED", why: "the protection probe did not say whether the branch is protected" }
|
|
258
334
|
: { kind: "READ", value: { branch: facts.branch, contexts: facts.contexts, statusChecks: facts.statusChecks } };
|
|
259
|
-
return { slug, secretPresent, requireClosingRef, protection, processChecks, unreadableWorkflows };
|
|
335
|
+
return { slug: origin, secretPresent, requireClosingRef, protection, processChecks, unreadableWorkflows };
|
|
260
336
|
}
|
|
@@ -200,6 +200,16 @@ export const OWNED_FILES: OwnedFile[] = [
|
|
|
200
200
|
customize: "Set `board.id` in config and secret `RUNGATE_PROJECT_TOKEN`; add your own jobs alongside the generated `move-freed-issues-to-ready` job",
|
|
201
201
|
avoid: "Don't edit the generated `move-freed-issues-to-ready` job",
|
|
202
202
|
},
|
|
203
|
+
{
|
|
204
|
+
// #2166, ADR-014 row 4. Hand-written with this repository's project URL
|
|
205
|
+
// and id pasted in; the generator writes it with neither, for #631's
|
|
206
|
+
// reason above. The board is board.id, read by `rungate board-id`.
|
|
207
|
+
path: ".github/workflows/board-intake.yml",
|
|
208
|
+
strategy: "job-preserving",
|
|
209
|
+
servedBy: "writeManagedFile (lib/scaffold/steps.ts) via mergeManagedWorkflow — the harness owns named jobs, not the file",
|
|
210
|
+
customize: "Set `board.id` in config and secret `RUNGATE_PROJECT_TOKEN`; add your own jobs alongside the generated `add-to-board` job",
|
|
211
|
+
avoid: "Don't edit the generated `add-to-board` job",
|
|
212
|
+
},
|
|
203
213
|
{
|
|
204
214
|
// `regenerate` until #655, and the declaration was never consulted:
|
|
205
215
|
// `generateAgentBriefsStep` called `writeFileSync` directly, so the row
|
package/lib/scaffold/steps.ts
CHANGED
|
@@ -51,6 +51,7 @@ import {
|
|
|
51
51
|
import { buildAdrAcceptedWorkflow } from "./adr-accepted-workflow";
|
|
52
52
|
import { buildClosingReferencesWorkflow } from "./closing-references-workflow";
|
|
53
53
|
import { buildBoardReadyWorkflow } from "./board-ready-workflow";
|
|
54
|
+
import { buildBoardIntakeWorkflow } from "./board-intake-workflow";
|
|
54
55
|
import { CI_SUITE_FETCH_DEPTH, baseRefFetchDepth } from "../ci-history-depth";
|
|
55
56
|
import { CLAUDE_CODE_ACTION } from "../claude-code-action";
|
|
56
57
|
import { GOOGLE_AUTH_ACTION } from "../google-auth-action";
|
|
@@ -4514,6 +4515,18 @@ ${buildAuthDetectStep(vertex)}${buildReviewRunStep(
|
|
|
4514
4515
|
version: harnessVersion(),
|
|
4515
4516
|
});
|
|
4516
4517
|
|
|
4518
|
+
// #2166, ADR-014 row 4: new issues and pull requests onto the board. It
|
|
4519
|
+
// names no board: the published CLI prints board.id from the default
|
|
4520
|
+
// branch's config (#2173), and the add uses that node id.
|
|
4521
|
+
const boardIntakeYml = buildBoardIntakeWorkflow({
|
|
4522
|
+
runsOn,
|
|
4523
|
+
checkout: actionRef("actions/checkout"),
|
|
4524
|
+
setupBun: actionRef("oven-sh/setup-bun"),
|
|
4525
|
+
setupBunWith: bunStep,
|
|
4526
|
+
setupBunEnv: setupBunEnv(" "),
|
|
4527
|
+
version: harnessVersion(),
|
|
4528
|
+
});
|
|
4529
|
+
|
|
4517
4530
|
// Not `writeFileSync`. The harness owns the `test` and `gates` jobs; it does
|
|
4518
4531
|
// not own the file, and a consumer's own jobs have to survive the update
|
|
4519
4532
|
// that re-scaffolding IS. A refusal is recorded rather than thrown so that
|
|
@@ -4529,7 +4542,7 @@ ${buildAuthDetectStep(vertex)}${buildReviewRunStep(
|
|
|
4529
4542
|
// lib/conformity.ts reads back, and the two are held together by
|
|
4530
4543
|
// test/ai-review-workflow.test.ts AC-1, which looks for the constant's
|
|
4531
4544
|
// filename in what this loop actually wrote.
|
|
4532
|
-
for (const [name, content] of [["ci.yml", ciYml], ["gates.yml", gatesYml], ["ai-review.yml", aiReviewYml], ["ai-review-unmeasured.yml", aiReviewUnmeasuredYml], ["adr-accepted.yml", adrAcceptedYml], ["closing-references.yml", closingReferencesYml], ["board-ready.yml", boardReadyYml]] as const) {
|
|
4545
|
+
for (const [name, content] of [["ci.yml", ciYml], ["gates.yml", gatesYml], ["ai-review.yml", aiReviewYml], ["ai-review-unmeasured.yml", aiReviewUnmeasuredYml], ["adr-accepted.yml", adrAcceptedYml], ["closing-references.yml", closingReferencesYml], ["board-ready.yml", boardReadyYml], ["board-intake.yml", boardIntakeYml]] as const) {
|
|
4533
4546
|
const label = `.github/workflows/${name}`;
|
|
4534
4547
|
try {
|
|
4535
4548
|
// Keyed by FILE, and the lookup is here because this loop is the only
|