@skitterbyte/skitterspec-github 2.3.0 → 2.5.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/assets/claude-md-section.md +20 -1
- package/assets/core/SETUP.md +5 -0
- package/assets/core/env.config.json.example +1 -0
- package/assets/core/env.config.md +143 -8
- package/assets/core/github.config.json.example +2 -1
- package/assets/core/github.config.md +5 -1
- package/assets/hooks/main-guard.cjs +40 -6
- package/assets/hooks/review-gate.cjs +42 -7
- package/assets/rules/commit-trailers.md +24 -1
- package/assets/rules/spec-planning.md +81 -18
- package/assets/rules/spec-reports.md +1 -1
- package/assets/skills/spec/SKILL.md +55 -2
- package/assets/skills/spec-bug/SKILL.md +36 -3
- package/assets/skills/spec-cancel/SKILL.md +37 -0
- package/assets/skills/spec-claim/SKILL.md +41 -2
- package/assets/skills/spec-complete/SKILL.md +115 -0
- package/assets/skills/spec-github-setup/SKILL.md +31 -4
- package/assets/skills/spec-hotfix/SKILL.md +51 -4
- package/assets/skills/spec-incident/SKILL.md +22 -0
- package/assets/skills/spec-next/SKILL.md +12 -5
- package/assets/skills/spec-push/SKILL.md +22 -0
- package/assets/skills/spec-review/SKILL.md +34 -0
- package/assets/skills/spec-start/SKILL.md +50 -3
- package/assets/skills/spec-status/SKILL.md +18 -3
- package/assets/skills/spec-sync/SKILL.md +1 -0
- package/assets/skills/spec-to-main/SKILL.md +47 -1
- package/package.json +1 -1
- package/src/cli.js +1188 -79
- package/src/env/base.js +104 -0
- package/src/env/bootstrap.js +22 -3
- package/src/env/classify.js +12 -4
- package/src/env/config.js +77 -5
- package/src/env/disposition.js +62 -0
- package/src/env/handoff.js +81 -0
- package/src/env/host.js +262 -0
- package/src/env/hotfix.js +237 -9
- package/src/env/hotfixland.js +105 -10
- package/src/env/inflight.js +98 -0
- package/src/env/integrate.js +136 -9
- package/src/env/live.js +8 -7
- package/src/env/mainguard.js +20 -5
- package/src/env/phases.js +28 -0
- package/src/env/project.js +223 -0
- package/src/env/provision.js +30 -8
- package/src/env/resolve.js +147 -25
- package/src/env/review.js +21 -7
- package/src/env/reviewers.js +7 -10
- package/src/env/serve.js +27 -11
- package/src/env/specstate.js +101 -0
- package/src/env/supervise.js +15 -2
- package/src/env/teardown.js +46 -3
- package/src/init.js +49 -9
- package/src/vendor/github/api.js +33 -2
- package/src/vendor/github/cli-sync.js +65 -4
- package/src/vendor/github/config.js +19 -5
- package/src/vendor/provider-kit/index.js +4 -0
- package/src/vendor/provider-kit/src/apply.js +58 -6
- package/src/vendor/provider-kit/src/assignment.js +78 -1
- package/src/vendor/provider-kit/src/config.js +34 -1
- package/src/vendor/provider-kit/src/credentials.js +7 -2
- package/src/vendor/provider-kit/src/list-rows.js +35 -11
- package/src/vendor/provider-kit/src/released.js +48 -4
- package/src/vendor/provider-kit/src/specs.js +18 -7
- package/src/vendor/provider-kit/src/splice.js +64 -0
- package/src/vendor/provider-kit/src/status.js +137 -0
- package/src/vendor/sync-core/index.js +14 -1
- package/src/vendor/sync-core/src/compare.js +81 -6
- package/src/vendor/sync-core/src/normalize.js +50 -7
- package/src/vendor/sync-core/src/push.js +65 -5
- package/src/vendor/sync-core/src/summary.js +257 -0
|
@@ -35,6 +35,9 @@ const {
|
|
|
35
35
|
stampSubIssueId,
|
|
36
36
|
listPhaseFiles,
|
|
37
37
|
normalizeLocal,
|
|
38
|
+
descriptionMode,
|
|
39
|
+
progressOf,
|
|
40
|
+
readSnapshot,
|
|
38
41
|
} = require('../sync-core')
|
|
39
42
|
const kit = require('../provider-kit')
|
|
40
43
|
const { GITHUB_REF_RE, IDENTIFIER_RE } = require('../provider-kit/src/released.js')
|
|
@@ -221,7 +224,19 @@ function applyOps({ adapter, config, kind = 'feature', snapshotDir = null }) {
|
|
|
221
224
|
if (severityLabel && !spec.labels.some((l) => l.toLowerCase() === severityLabel.toLowerCase())) {
|
|
222
225
|
spec.labels = [...spec.labels, severityLabel]
|
|
223
226
|
}
|
|
227
|
+
// `summary.progressField`: mirror % done into a board Number field. Opt-in;
|
|
228
|
+
// a spec with no checkboxes has no progress to send (cannot-tell, not 0).
|
|
229
|
+
const progressField = config.summary && config.summary.progressField
|
|
224
230
|
return {
|
|
231
|
+
afterIssue: async (issue) => {
|
|
232
|
+
if (!progressField || !snapshotDir || typeof adapter.setNumberField !== 'function') return null
|
|
233
|
+
const progress = progressOf(readSnapshot(snapshotDir, config).phases)
|
|
234
|
+
if (!progress) return null
|
|
235
|
+
const r = await adapter.setNumberField(issue, progressField, progress.percent)
|
|
236
|
+
return r && r.skipped
|
|
237
|
+
? ` progress: not mirrored — ${r.skipped}`
|
|
238
|
+
: ` progress: ${progress.percent}% → board field "${progressField}"`
|
|
239
|
+
},
|
|
225
240
|
prevalidateStates: (buckets) => {
|
|
226
241
|
for (const bucket of buckets) statusFor(bucket)
|
|
227
242
|
},
|
|
@@ -296,6 +311,16 @@ function apiAdapterFor(config, flags) {
|
|
|
296
311
|
return { ok: true, adapter: makeApiAdapter({ ...adapterOptions(config), token: cred.token, fetch: flags.fetch }) }
|
|
297
312
|
}
|
|
298
313
|
|
|
314
|
+
// `board <spec>` — has GitHub finished what this repo has not? The kit's
|
|
315
|
+
// (`provider-kit/src/status.js`): one line on a disagreement, silent otherwise.
|
|
316
|
+
async function specSyncBoard(dir, config, specArg, flags, out) {
|
|
317
|
+
const snapshotDir = resolveOrExit(specArg, dir, out)
|
|
318
|
+
if (!snapshotDir) return 1
|
|
319
|
+
const cred = apiAdapterFor(config, flags)
|
|
320
|
+
const credential = kit.resolveTransport(flags, config, cred.ok) === 'mcp' ? { ok: false, error: 'transport = mcp — no API read' } : cred
|
|
321
|
+
return kit.specSyncBoard({ snapshotDir, config, credential, flags, out, tracker: 'GitHub', program: PROGRAM })
|
|
322
|
+
}
|
|
323
|
+
|
|
299
324
|
// ---------------------------------------------------------------------------
|
|
300
325
|
// Assignment: `assign`, `whoami` and `users` are the kit's
|
|
301
326
|
// (`provider-kit/src/assignment.js`); this is GitHub's binding. The id is a
|
|
@@ -555,7 +580,7 @@ function specSyncRecord(dir, config, specArg, out) {
|
|
|
555
580
|
const snapshotDir = resolveOrExit(specArg, dir, out)
|
|
556
581
|
if (!snapshotDir) return 1
|
|
557
582
|
const file = recordPush({ dir, snapshotDir, identifier: specIdentifier(snapshotDir, config), config })
|
|
558
|
-
out.write(`${PROGRAM} record: snapshot written — ${path.relative(dir, file)}\n`)
|
|
583
|
+
out.write(`${PROGRAM} record: snapshot written — ${path.relative(dir, file).split(path.sep).join('/')}\n`)
|
|
559
584
|
return 0
|
|
560
585
|
}
|
|
561
586
|
|
|
@@ -931,12 +956,16 @@ function specSyncRef(dir, config, specArg, flags, out, err) {
|
|
|
931
956
|
// `Refs:` trailers (kit `src/released.js` owns the parsing rules). Refs are
|
|
932
957
|
// `#N`; an older tracker's `KEY-N` trailer — a repo that moved here from
|
|
933
958
|
// Linear or Jira — counts as historical, never as a missed trailer.
|
|
959
|
+
// Merge commits are READ, never skipped: a hand merge is where a ticket's only
|
|
960
|
+
// trailer sometimes lives (--no-merges was tried and dropped for exactly that
|
|
961
|
+
// loss). What changes is the counting — a trailer-less merge is transport, not
|
|
962
|
+
// a gap — and %P is what lets ticketsInRange tell the two apart.
|
|
934
963
|
function readCommitRange(dir, range) {
|
|
935
964
|
const { execFileSync } = require('node:child_process')
|
|
936
965
|
const SEP = '\0SKITTERSPEC\0'
|
|
937
966
|
let raw
|
|
938
967
|
try {
|
|
939
|
-
raw = execFileSync('git', ['-C', dir, 'log', `--format=%x00SKITTERSPEC%x00%H%n%B%x00END%x00`, '--name-only', range], {
|
|
968
|
+
raw = execFileSync('git', ['-C', dir, 'log', `--format=%x00SKITTERSPEC%x00%H %P%n%B%x00END%x00`, '--name-only', range], {
|
|
940
969
|
encoding: 'utf-8',
|
|
941
970
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
942
971
|
maxBuffer: 64 * 1024 * 1024,
|
|
@@ -957,9 +986,10 @@ function readCommitRange(dir, range) {
|
|
|
957
986
|
.map((l) => l.trim())
|
|
958
987
|
.filter(Boolean)
|
|
959
988
|
const nl = head.indexOf('\n')
|
|
960
|
-
const
|
|
989
|
+
const idLine = head.slice(0, nl < 0 ? head.length : nl).trim()
|
|
990
|
+
const [sha, ...parents] = idLine.split(/\s+/).filter(Boolean)
|
|
961
991
|
const body = nl < 0 ? '' : head.slice(nl + 1)
|
|
962
|
-
commits.push({ sha, subject: body.split('\n')[0] || '', body, paths })
|
|
992
|
+
commits.push({ sha, isMerge: parents.length > 1, subject: body.split('\n')[0] || '', body, paths })
|
|
963
993
|
}
|
|
964
994
|
return { ok: true, commits }
|
|
965
995
|
}
|
|
@@ -973,6 +1003,8 @@ function specSyncReleased(dir, config, rangeArg, flags, out) {
|
|
|
973
1003
|
}
|
|
974
1004
|
const report = kit.ticketsInRange(read.commits, {
|
|
975
1005
|
ignorePaths: (config.release && config.release.ignorePaths) || [],
|
|
1006
|
+
// A nested project's commits carry its folder in every path (feat-subfolder-project).
|
|
1007
|
+
prefix: kit.projectPrefixOf(dir),
|
|
976
1008
|
refPattern: GITHUB_REF_RE,
|
|
977
1009
|
foreignPatterns: [IDENTIFIER_RE],
|
|
978
1010
|
})
|
|
@@ -985,6 +1017,7 @@ function specSyncReleased(dir, config, rangeArg, flags, out) {
|
|
|
985
1017
|
for (const t of report.tickets) lines.push(` ${t.ref} (${t.commits} commit(s))${t.spec ? ` ${t.spec}` : ''}`)
|
|
986
1018
|
if (!report.tickets.length) lines.push(' no referenced issues')
|
|
987
1019
|
if (report.unreferenced) lines.push(` ${report.unreferenced} commit(s) carry no Refs: trailer`)
|
|
1020
|
+
if (report.merges) lines.push(` ${report.merges} merge commit(s) — transport, not counted as gaps`)
|
|
988
1021
|
if (report.historical) lines.push(` ${report.historical} commit(s) reference an earlier tracker (KEY-N)`)
|
|
989
1022
|
if (report.ignored) lines.push(` ${report.ignored} bookkeeping commit(s) ignored`)
|
|
990
1023
|
out.write(lines.join('\n') + '\n')
|
|
@@ -1009,6 +1042,11 @@ async function specSyncPreserve(dir, config, specArg, flags, out) {
|
|
|
1009
1042
|
return 0
|
|
1010
1043
|
}
|
|
1011
1044
|
if (!identifier) return done(`${path.basename(snapshotDir)} is not linked — nothing to preserve`)
|
|
1045
|
+
// Summary mode splices a block in beside the reporter's text rather than
|
|
1046
|
+
// replacing it, so the original is still in the description itself.
|
|
1047
|
+
if (descriptionMode(config) === 'summary') {
|
|
1048
|
+
return done(`${identifier} — summary mode keeps the original description in place; nothing to preserve`)
|
|
1049
|
+
}
|
|
1012
1050
|
|
|
1013
1051
|
let original = null
|
|
1014
1052
|
if (flags.text) {
|
|
@@ -1225,6 +1263,10 @@ async function specSyncInitConfig(dir, flags, out) {
|
|
|
1225
1263
|
// fails HERE rather than on the first push.
|
|
1226
1264
|
const parsed = { github: { owner: flags.owner, repo: flags.repo, project: flags.project } }
|
|
1227
1265
|
if (flags.statusField) parsed.github.statusField = flags.statusField
|
|
1266
|
+
// A NEW config carries a summary, not the spec: written explicitly, so the
|
|
1267
|
+
// file says what the ticket gets. A config that predates the key keeps
|
|
1268
|
+
// pushing the spec (the loader's default), so an upgrade rewrites nothing.
|
|
1269
|
+
parsed.mapping = { description: flags.description || 'summary' }
|
|
1228
1270
|
if (flags.stateNames && Object.keys(flags.stateNames).length) {
|
|
1229
1271
|
for (const bucket of Object.keys(flags.stateNames)) {
|
|
1230
1272
|
if (!LIFECYCLE_BUCKETS.includes(bucket)) {
|
|
@@ -1320,6 +1362,7 @@ async function specSyncDoctor(dir, flags, out) {
|
|
|
1320
1362
|
checks.push(row('tracker', 'GitHub config', 'broken', configGap(loaded.config), `fix ${CONFIG_FILE}`))
|
|
1321
1363
|
} else {
|
|
1322
1364
|
checks.push(row('tracker', 'GitHub config', 'ok', `${repoLabel(loaded.config)} · board ${loaded.config.github.project}`))
|
|
1365
|
+
checks.push(kit.ownershipDoctorRow(loaded.config))
|
|
1323
1366
|
const retired = kit.retiredKeysRow(path.join(dir, CONFIG_FILE), CONFIG_FILE, row)
|
|
1324
1367
|
if (retired) checks.push(retired)
|
|
1325
1368
|
// A worktree forks from a COMMIT, so a config that exists only in the
|
|
@@ -1435,19 +1478,24 @@ const USAGE = `Usage: ${BIN} spec-sync <subcommand>
|
|
|
1435
1478
|
record <spec> write the last-pushed snapshot
|
|
1436
1479
|
status <spec> [--remote <f>] read-only drift report
|
|
1437
1480
|
verify <spec> --stored <f> compare a read-back against the repo
|
|
1481
|
+
splice <spec> --live <f> [--phase <ref>] the body to write over MCP (summary mode)
|
|
1438
1482
|
states [--json] the board's Status options + bucket map
|
|
1439
1483
|
list [--all | --state NAME|BUCKET | --next N] [--mine | --by USER] the board's issues
|
|
1440
1484
|
intake [query] [--json] issues waiting to become specs
|
|
1441
1485
|
linked [--json] specs and their linked issues (offline)
|
|
1486
|
+
ownership [--json] who owns status and assignee (offline)
|
|
1487
|
+
board <spec> [--json] is the issue finished where the spec is not?
|
|
1442
1488
|
ref [<spec>] the Refs: trailer value for this branch
|
|
1443
1489
|
released [<range>] issues a commit range contains
|
|
1444
1490
|
preserve <spec> [--text <f>] keep an adopted issue's original report
|
|
1445
1491
|
comment <spec> --file <f> post a file onto the issue as a comment
|
|
1446
1492
|
assign <spec> --to <login> | --release stamp who is building it
|
|
1493
|
+
[--if-unassigned] only when nobody holds the issue
|
|
1447
1494
|
whoami [--set <login>] [--unset] who you are on GitHub (cached)
|
|
1448
1495
|
users [<query>] the repo's assignable people
|
|
1449
1496
|
credentials <status|set|unset> the GitHub token (user-level)
|
|
1450
1497
|
init-config --owner … --repo … --project N write the config
|
|
1498
|
+
[--description summary|spec] what a ticket body carries (default summary)
|
|
1451
1499
|
doctor [--check-remote] [--json] readiness report
|
|
1452
1500
|
|
|
1453
1501
|
Not yet shipped for GitHub: retarget, reattach, sanitise.
|
|
@@ -1508,10 +1556,19 @@ async function specSync(rest, io = {}) {
|
|
|
1508
1556
|
return specSyncRecord(dir, config, positional[0], out)
|
|
1509
1557
|
case 'status':
|
|
1510
1558
|
return specSyncStatus(dir, config, positional[0], flags, out, err)
|
|
1559
|
+
case 'splice': {
|
|
1560
|
+
const snapshotDir = resolveOrExit(positional[0], dir, err)
|
|
1561
|
+
if (!snapshotDir) return 1
|
|
1562
|
+
return kit.specSyncSplice({ snapshotDir, config, flags, out, err, program: PROGRAM })
|
|
1563
|
+
}
|
|
1511
1564
|
case 'verify':
|
|
1512
1565
|
return specSyncVerify(dir, config, positional[0], flags, out)
|
|
1513
1566
|
case 'linked':
|
|
1514
1567
|
return specSyncLinked(dir, config, flags, out)
|
|
1568
|
+
case 'ownership':
|
|
1569
|
+
return kit.specSyncOwnership(config, flags, out, PROGRAM)
|
|
1570
|
+
case 'board':
|
|
1571
|
+
return specSyncBoard(dir, config, positional[0], flags, out)
|
|
1515
1572
|
case 'states':
|
|
1516
1573
|
return specSyncStates(dir, config, flags, out)
|
|
1517
1574
|
case 'list':
|
|
@@ -1558,6 +1615,8 @@ function parseArgs(args, sub) {
|
|
|
1558
1615
|
'--dir': { kind: 'path', name: 'dirOverride' },
|
|
1559
1616
|
'--plan': { kind: 'path' },
|
|
1560
1617
|
'--stored': { kind: 'path' },
|
|
1618
|
+
'--live': { kind: 'path' },
|
|
1619
|
+
'--phase': { kind: 'string' },
|
|
1561
1620
|
'--remote': { kind: 'path' },
|
|
1562
1621
|
'--text': { kind: 'path' },
|
|
1563
1622
|
'--file': { kind: 'path' },
|
|
@@ -1576,9 +1635,11 @@ function parseArgs(args, sub) {
|
|
|
1576
1635
|
'--repo': { kind: 'string' },
|
|
1577
1636
|
'--project': { kind: 'string' },
|
|
1578
1637
|
'--status-field': { kind: 'string', name: 'statusField' },
|
|
1638
|
+
'--description': { kind: 'string' },
|
|
1579
1639
|
'--to': { kind: 'string' },
|
|
1580
1640
|
'--name': { kind: 'value' },
|
|
1581
1641
|
'--release': { kind: 'boolean' },
|
|
1642
|
+
'--if-unassigned': { kind: 'boolean', name: 'ifUnassigned' },
|
|
1582
1643
|
'--mine': { kind: 'boolean' },
|
|
1583
1644
|
'--next': { kind: 'number' },
|
|
1584
1645
|
'--by': { kind: 'string' },
|
|
@@ -28,7 +28,7 @@ const CONFIG_FILE = 'specs/.core/github.config.json'
|
|
|
28
28
|
|
|
29
29
|
const OWNERSHIP = Object.freeze(['both', 'pull', 'push', 'none'])
|
|
30
30
|
const TASK_MAPPINGS = Object.freeze(['checklist', 'none'])
|
|
31
|
-
const PHASE_MAPPINGS = Object.freeze(['subissue', 'deferred', 'inline'])
|
|
31
|
+
const PHASE_MAPPINGS = Object.freeze(['subissue', 'deferred', 'inline', 'none'])
|
|
32
32
|
const TRANSPORTS = Object.freeze(['api', 'mcp'])
|
|
33
33
|
const DEFAULT_TOKEN_ENV = 'GITHUB_TOKEN'
|
|
34
34
|
// Read after `auth.tokenEnv`, because it is the name the GitHub CLI itself
|
|
@@ -64,7 +64,13 @@ const DEFAULT_CONFIG = Object.freeze({
|
|
|
64
64
|
// A spec is a GitHub ISSUE; each phase a SUB-ISSUE of it, carrying the
|
|
65
65
|
// phase's checkboxes in its body as a task list (rendered live by GitHub —
|
|
66
66
|
// still a read-only mirror).
|
|
67
|
-
|
|
67
|
+
// `description`: what the ticket body carries — `spec` (the whole overview)
|
|
68
|
+
// or `summary` (a delimited block beside the team's own text). `spec` is the
|
|
69
|
+
// default so a config written before the key pushes what it always pushed.
|
|
70
|
+
mapping: Object.freeze({ specFolder: 'issue', phases: DEFAULT_PHASE_MODE, tasks: 'checklist', description: 'spec' }),
|
|
71
|
+
// The summary block's delimiters (measured 2026-11-08: GitHub keeps HTML comments verbatim and hides them).
|
|
72
|
+
// `progressField`: a board Number field to mirror % done into; empty = off.
|
|
73
|
+
summary: Object.freeze({ delimiter: 'comment', progressField: '' }),
|
|
68
74
|
// Board STATUS OPTION names — the spec issue's (from the folder bucket) and
|
|
69
75
|
// each sub-issue's (from the phase emoji) both map through this table. They
|
|
70
76
|
// must match the Status field's options exactly; the adapter resolves them
|
|
@@ -96,11 +102,16 @@ const DEFAULT_CONFIG = Object.freeze({
|
|
|
96
102
|
sync: Object.freeze({
|
|
97
103
|
baseDir: 'specs/.core/github-base',
|
|
98
104
|
backupDir: 'specs/.core/github-backups',
|
|
105
|
+
// The repo owns the spec's CONTENT (`push`); the tracker owns its STATUS and
|
|
106
|
+
// ASSIGNEE (`pull`) — the board is where a team assigns and moves work, so a
|
|
107
|
+
// repo copy is one somebody has to keep in step by hand. Under `pull` the
|
|
108
|
+
// state is sent only as a transition the repo made (a bucket move), and the
|
|
109
|
+
// assignee not at all. Set either back to `"push"` for the repo-owned behaviour.
|
|
99
110
|
fieldOwnership: Object.freeze({
|
|
100
111
|
description: 'push',
|
|
101
112
|
subIssues: 'push',
|
|
102
|
-
workflowState: '
|
|
103
|
-
assignee: '
|
|
113
|
+
workflowState: 'pull',
|
|
114
|
+
assignee: 'pull',
|
|
104
115
|
}),
|
|
105
116
|
localOnlySections: Object.freeze(['State log', 'Changelog', 'Open questions']),
|
|
106
117
|
keyedFields: Object.freeze({}),
|
|
@@ -126,6 +137,7 @@ function defaults() {
|
|
|
126
137
|
return {
|
|
127
138
|
github: { ...g, labels: { ...g.labels }, issueTypes: { ...g.issueTypes }, labelsByKind: { ...g.labelsByKind }, severityLabels: { ...g.severityLabels } },
|
|
128
139
|
mapping: { ...DEFAULT_CONFIG.mapping },
|
|
140
|
+
summary: { ...DEFAULT_CONFIG.summary },
|
|
129
141
|
states: { ...DEFAULT_CONFIG.states },
|
|
130
142
|
statesByKind: {},
|
|
131
143
|
stateAliases: {},
|
|
@@ -153,7 +165,7 @@ function defaults() {
|
|
|
153
165
|
}
|
|
154
166
|
|
|
155
167
|
const { isObject, stringList, assign } = kitConfig
|
|
156
|
-
const { mergeStates, mergeStateOverrides, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
|
|
168
|
+
const { mergeStates, mergeStateOverrides, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields, mergeDescription } =
|
|
157
169
|
kitConfig.makeMergeHelpers({
|
|
158
170
|
configFile: CONFIG_FILE,
|
|
159
171
|
ownership: OWNERSHIP,
|
|
@@ -222,6 +234,8 @@ function mergeConfig(base, parsed) {
|
|
|
222
234
|
}
|
|
223
235
|
mergePhaseMapping(base.mapping, parsed.mapping)
|
|
224
236
|
}
|
|
237
|
+
mergeDescription(base, parsed)
|
|
238
|
+
if (isObject(parsed.summary)) assign(base.summary, parsed.summary, 'progressField', 'string?')
|
|
225
239
|
|
|
226
240
|
mergeStates(base, parsed)
|
|
227
241
|
mergeStateOverrides(base, parsed, 'statesByKind')
|
|
@@ -24,6 +24,8 @@ const prompt = require('./src/prompt.js')
|
|
|
24
24
|
const args = require('./src/args.js')
|
|
25
25
|
const adapter = require('./src/adapter.js')
|
|
26
26
|
const apply = require('./src/apply.js')
|
|
27
|
+
const status = require('./src/status.js')
|
|
28
|
+
const splice = require('./src/splice.js')
|
|
27
29
|
|
|
28
30
|
module.exports = {
|
|
29
31
|
...config,
|
|
@@ -38,4 +40,6 @@ module.exports = {
|
|
|
38
40
|
...args,
|
|
39
41
|
...adapter,
|
|
40
42
|
...apply,
|
|
43
|
+
...status,
|
|
44
|
+
...splice,
|
|
41
45
|
}
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
* - `updateSubIssue(sub)` apply a sub-issue update
|
|
37
37
|
* - `remoteEditedLine(identifier)` the someone-else-edited warning
|
|
38
38
|
* - `twinAdvice(twin, title, specName)` the refusal message for a twin
|
|
39
|
+
* - `afterIssue(issue)` optional; → a report line or null
|
|
39
40
|
*/
|
|
40
41
|
|
|
41
42
|
const path = require('node:path')
|
|
@@ -51,6 +52,8 @@ const {
|
|
|
51
52
|
remoteDescriptionEdited,
|
|
52
53
|
remoteSubIssueEdited,
|
|
53
54
|
listPhaseFiles,
|
|
55
|
+
descriptionMode,
|
|
56
|
+
spliceBlock,
|
|
54
57
|
} = require('../../sync-core')
|
|
55
58
|
const { makeSpecHelpers } = require('./specs.js')
|
|
56
59
|
|
|
@@ -80,6 +83,9 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
|
|
|
80
83
|
const identifier = helpers.linkedIdentifier(path.join(snapshotDir, overviewFile), config)
|
|
81
84
|
const lines = []
|
|
82
85
|
const result = { issue: null, subIssues: {} }
|
|
86
|
+
// Which items this apply carried a state for — the snapshot records today's
|
|
87
|
+
// state name for these and only these (`recordPush`).
|
|
88
|
+
const sent = { issue: !!(plan.issue && plan.issue.state != null), subIssues: new Set() }
|
|
83
89
|
// Handed out immediately, so a throw from anywhere below still reports what
|
|
84
90
|
// had been stamped by the time it happened.
|
|
85
91
|
if (progress) progress.result = result
|
|
@@ -140,11 +146,23 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
|
|
|
140
146
|
lines.push(ops.remoteEditedLine(identifier))
|
|
141
147
|
}
|
|
142
148
|
if (plan.issue) {
|
|
143
|
-
|
|
149
|
+
const issue = spliced(plan.issue, 'description', existing, config, identifier, lines)
|
|
150
|
+
await ops.updateIssue(existing, issue)
|
|
144
151
|
lines.push(` issue updated: ${identifier}`)
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
|
|
155
|
+
// A provider's per-push extra on the spec issue (e.g. progress mirrored into
|
|
156
|
+
// a native field). Never fatal: the repo and the block already carry it.
|
|
157
|
+
if (ops.afterIssue && result.issue) {
|
|
158
|
+
try {
|
|
159
|
+
const line = await ops.afterIssue(result.issue)
|
|
160
|
+
if (line) lines.push(line)
|
|
161
|
+
} catch (error) {
|
|
162
|
+
lines.push(` ?? ${result.issue.identifier}: ${String((error && error.message) || error).split('\n')[0]}`)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
148
166
|
// 4. Sub-issue creates — each stamped as it lands, for the same reason.
|
|
149
167
|
for (const sub of (plan.subIssues && plan.subIssues.create) || []) {
|
|
150
168
|
const created = await ops.mintSubIssue(parentId, sub)
|
|
@@ -152,6 +170,7 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
|
|
|
152
170
|
const file = resolvePhaseFileIn(snapshotDir, sub.ref)
|
|
153
171
|
if (!file) throw new Error(`no phase file for ref ${sub.ref}`)
|
|
154
172
|
stampSubIssueId(snapshotDir, file, created.identifier, config)
|
|
173
|
+
if (sub.state != null) sent.subIssues.add(String(created.identifier))
|
|
155
174
|
result.subIssues[sub.ref] = created.identifier
|
|
156
175
|
lines.push(` sub-issue created: ${sub.ref} → ${created.identifier}`)
|
|
157
176
|
}
|
|
@@ -167,13 +186,18 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
|
|
|
167
186
|
// issue. The read is spent only where the snapshot recorded something to
|
|
168
187
|
// compare against, so an old snapshot costs no extra calls.
|
|
169
188
|
const base = readBase(dir, identifier, config)
|
|
170
|
-
|
|
189
|
+
const summary = descriptionMode(config) === 'summary'
|
|
190
|
+
for (let sub of (plan.subIssues && plan.subIssues.update) || []) {
|
|
171
191
|
const streams = base && base.subIssueStreams
|
|
172
|
-
|
|
192
|
+
const compare = sub.goal != null && streams && streams[String(sub.id)]
|
|
193
|
+
// Summary mode always reads the live body: the block is spliced into it.
|
|
194
|
+
if (compare || (summary && sub.goal != null)) {
|
|
173
195
|
const before = await adapter.readIssue(sub.id)
|
|
174
|
-
if (remoteSubIssueEdited(base, sub.id, before, config) === true) lines.push(ops.remoteEditedLine(sub.id))
|
|
196
|
+
if (compare && remoteSubIssueEdited(base, sub.id, before, config) === true) lines.push(ops.remoteEditedLine(sub.id))
|
|
197
|
+
sub = spliced(sub, 'goal', before, config, sub.id, lines)
|
|
175
198
|
}
|
|
176
199
|
await ops.updateSubIssue(sub)
|
|
200
|
+
if (sub.state != null) sent.subIssues.add(String(sub.id))
|
|
177
201
|
result.subIssues[sub.ref || refById.get(String(sub.id)) || sub.id] = sub.id
|
|
178
202
|
lines.push(` sub-issue updated: ${sub.id}`)
|
|
179
203
|
}
|
|
@@ -193,11 +217,39 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
|
|
|
193
217
|
const lost = verify.some((l) => l.includes('!!') || l.includes('??'))
|
|
194
218
|
|
|
195
219
|
// 7. Record the snapshot from the now-stamped files, so the next push is empty.
|
|
196
|
-
const file = recordPush({ dir, snapshotDir, identifier: helpers.specIdentifier(snapshotDir, config), config })
|
|
197
|
-
|
|
220
|
+
const file = recordPush({ dir, snapshotDir, identifier: helpers.specIdentifier(snapshotDir, config), config, sent })
|
|
221
|
+
// A repo path, `/`-separated on every platform — the form every other
|
|
222
|
+
// spec path in this output takes.
|
|
223
|
+
lines.push(` snapshot: ${path.relative(dir, file).split(path.sep).join('/')}`)
|
|
198
224
|
return { result, lines, lost }
|
|
199
225
|
}
|
|
200
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Under `mapping.description: "summary"` the planned body is the block alone,
|
|
229
|
+
* and the write must be the block SPLICED into what the tracker holds, so the
|
|
230
|
+
* team's text around it survives. `spec` mode returns the payload untouched.
|
|
231
|
+
*
|
|
232
|
+
* A damaged block (a delimiter someone edited) is cannot-tell: the body is
|
|
233
|
+
* left out of the write entirely and the run says so. Guessing the edges would
|
|
234
|
+
* eat the team's text, and prepending would leave two blocks.
|
|
235
|
+
*/
|
|
236
|
+
function spliced(payload, key, live, config, label, lines) {
|
|
237
|
+
if (descriptionMode(config) !== 'summary' || payload[key] == null) return payload
|
|
238
|
+
const hook = config && config.remote && config.remote.description
|
|
239
|
+
const current = live && typeof hook === 'function' ? hook(live) : live ? live.description : undefined
|
|
240
|
+
// Nothing read back is not an empty body: write nothing rather than guess.
|
|
241
|
+
if (typeof current !== 'string') {
|
|
242
|
+
lines.push(` ?? ${label}: could not read its body — summary block not written`)
|
|
243
|
+
return { ...payload, [key]: undefined }
|
|
244
|
+
}
|
|
245
|
+
const next = spliceBlock(current, payload[key], config)
|
|
246
|
+
if (next == null) {
|
|
247
|
+
lines.push(` !! ${label}: its summary block's delimiters were edited — block not written; repair them and re-push`)
|
|
248
|
+
return { ...payload, [key]: undefined }
|
|
249
|
+
}
|
|
250
|
+
return { ...payload, [key]: next }
|
|
251
|
+
}
|
|
252
|
+
|
|
201
253
|
// The phase file a sub-issue ref names — the ref is the phase-file basename.
|
|
202
254
|
function resolvePhaseFileIn(snapshotDir, ref) {
|
|
203
255
|
const want = String(ref).replace(/\.md$/, '')
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
* the operator is in the tracker, which is the fact assignment rests on.
|
|
14
14
|
* - `users [<query>]` finds a person to hand a spec to.
|
|
15
15
|
*
|
|
16
|
+
* Under `sync.fieldOwnership.assignee: "pull"` the TRACKER owns the field, so
|
|
17
|
+
* `assign` writes the ticket directly and stamps nothing into the repo — there
|
|
18
|
+
* is no projection to carry it, and a stamp would be a copy someone has to
|
|
19
|
+
* keep in step. `--if-unassigned` is how `/spec-start` claims a ticket nobody
|
|
20
|
+
* holds without ever taking one from someone who does.
|
|
21
|
+
*
|
|
16
22
|
* Everything tracker-shaped arrives as a hook (`makeAssignmentCommands`): the
|
|
17
23
|
* tracker's name for messages, the frontmatter fields, the store scope, how a
|
|
18
24
|
* credential resolves and how an adapter is made. The behaviour is the Linear
|
|
@@ -21,9 +27,10 @@
|
|
|
21
27
|
|
|
22
28
|
const path = require('node:path')
|
|
23
29
|
|
|
24
|
-
const { ownsField, writeFrontmatter, deleteFrontmatter, fieldsOf } = require('../../sync-core')
|
|
30
|
+
const { ownsField, ownershipOf, writeFrontmatter, deleteFrontmatter, fieldsOf, readSnapshot } = require('../../sync-core')
|
|
25
31
|
const { resolveTransport } = require('./transport.js')
|
|
26
32
|
const { makeSpecHelpers } = require('./specs.js')
|
|
33
|
+
const { readStatus } = require('./status.js')
|
|
27
34
|
|
|
28
35
|
/**
|
|
29
36
|
* @param {object} p
|
|
@@ -58,6 +65,7 @@ function makeAssignmentCommands(p) {
|
|
|
58
65
|
|
|
59
66
|
const problems = []
|
|
60
67
|
if (flags.release && flags.to) problems.push('--release and --to are opposites — pass one')
|
|
68
|
+
if (flags.release && flags.ifUnassigned) problems.push('--if-unassigned guards an assignment — it has nothing to say about --release')
|
|
61
69
|
if (!flags.release && !flags.to) problems.push('nothing to do — pass --to <user-id> or --release')
|
|
62
70
|
// An unlinked spec has no issue to assign. Refusing beats stamping a field
|
|
63
71
|
// that would sit in the file doing nothing until someone noticed.
|
|
@@ -86,6 +94,19 @@ function makeAssignmentCommands(p) {
|
|
|
86
94
|
return 1
|
|
87
95
|
}
|
|
88
96
|
|
|
97
|
+
if (ownershipOf(config, 'assignee') === 'pull') return assignOnTracker(config, identifier, flags, out)
|
|
98
|
+
|
|
99
|
+
// Under `push` the repo's stamp IS the record, so that is what the guard asks.
|
|
100
|
+
if (flags.ifUnassigned) {
|
|
101
|
+
const { frontmatter } = readSnapshot(snapshotDir, config)
|
|
102
|
+
const recorded = frontmatter[fields.assigneeId]
|
|
103
|
+
if (recorded) {
|
|
104
|
+
const shown = (fields.assigneeName && frontmatter[fields.assigneeName]) || recorded
|
|
105
|
+
out.write(`spec-sync assign: ${rel} is already assigned to ${shown} — left alone\n`)
|
|
106
|
+
return 0
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
89
110
|
if (flags.release) {
|
|
90
111
|
const removed = deleteFrontmatter(snapshotDir, config, [fields.assigneeId, fields.assigneeName].filter(Boolean))
|
|
91
112
|
if (flags.json) {
|
|
@@ -116,6 +137,62 @@ function makeAssignmentCommands(p) {
|
|
|
116
137
|
return 0
|
|
117
138
|
}
|
|
118
139
|
|
|
140
|
+
/**
|
|
141
|
+
* The `pull` half of `assign`: write the ticket, stamp nothing.
|
|
142
|
+
*
|
|
143
|
+
* `--if-unassigned` reads the ticket first and acts only on a POSITIVE
|
|
144
|
+
* "nobody holds it". A read that could not run is cannot-tell, and the
|
|
145
|
+
* harmless branch is to assign nobody: taking a ticket from a colleague is
|
|
146
|
+
* the one mistake here that costs someone else their afternoon.
|
|
147
|
+
*
|
|
148
|
+
* Exits 0 on every cannot-tell (MCP transport, no credential, an unreadable
|
|
149
|
+
* ticket) and 1 only when the tracker refused a write it was asked to make.
|
|
150
|
+
*/
|
|
151
|
+
async function assignOnTracker(config, identifier, flags, out) {
|
|
152
|
+
const say = (line) => {
|
|
153
|
+
out.write(`spec-sync assign: ${line}\n`)
|
|
154
|
+
return 0
|
|
155
|
+
}
|
|
156
|
+
const report = (result) => {
|
|
157
|
+
if (flags.json) {
|
|
158
|
+
out.write(JSON.stringify({ issue: identifier, owner: 'tracker', ...result }, null, 2) + '\n')
|
|
159
|
+
return 0
|
|
160
|
+
}
|
|
161
|
+
return say(result.line)
|
|
162
|
+
}
|
|
163
|
+
const cred = flags.adapter ? { ok: true } : p.resolveCredential(config, flags.env || process.env)
|
|
164
|
+
const transport = resolveTransport(flags, config, cred.ok)
|
|
165
|
+
if (transport === 'mcp' || !cred.ok) {
|
|
166
|
+
const what = flags.release ? 'unassign it' : `assign it to ${flags.to}`
|
|
167
|
+
return report({
|
|
168
|
+
written: false,
|
|
169
|
+
line: `${p.tracker} owns the assignee here, and there is no API transport — ${what} on ${identifier} with the tracker's own tool; nothing was written`,
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
const adapter = flags.adapter || p.makeAdapter(config, cred, flags)
|
|
173
|
+
|
|
174
|
+
if (flags.ifUnassigned) {
|
|
175
|
+
const now = await readStatus({ adapter, ref: identifier, config })
|
|
176
|
+
if (!now.ok) {
|
|
177
|
+
return report({ written: false, line: `could not read ${identifier} (${now.reason}) — assigned nobody` })
|
|
178
|
+
}
|
|
179
|
+
if (now.assignee) {
|
|
180
|
+
const who = now.assignee.name || now.assignee.id
|
|
181
|
+
return report({ written: false, assignee: now.assignee, line: `${identifier} is already assigned to ${who} — left alone` })
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
await adapter.updateIssue(identifier, { assigneeId: flags.release ? null : flags.to })
|
|
187
|
+
} catch (error) {
|
|
188
|
+
out.write(`spec-sync assign: ${p.tracker} refused — ${String(error.message).split('\n')[0]}\n`)
|
|
189
|
+
return 1
|
|
190
|
+
}
|
|
191
|
+
if (flags.release) return report({ written: true, released: true, line: `${identifier} unassigned on ${p.tracker}` })
|
|
192
|
+
const who = flags.name ? `${flags.name} (${flags.to})` : flags.to
|
|
193
|
+
return report({ written: true, id: flags.to, name: flags.name || null, line: `${identifier} assigned to ${who} on ${p.tracker}` })
|
|
194
|
+
}
|
|
195
|
+
|
|
119
196
|
/**
|
|
120
197
|
* Exit 0 even when the answer is "unknown": this answers a question, and
|
|
121
198
|
* "nobody is identified here" is a valid answer — a shared key, an offline
|
|
@@ -236,6 +236,33 @@ function makeMergeHelpers({ configFile, ownership, lifecycleBuckets, phaseMappin
|
|
|
236
236
|
base[key] = table
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
+
// Merge (and validate) what a ticket's description carries —
|
|
240
|
+
// `mapping.description` (`spec` · `summary`) and the block's delimiter style
|
|
241
|
+
// (`summary.delimiter`: `comment` · `heading`). Loud on a bad value: a typo
|
|
242
|
+
// must not read as a choice to keep pushing the whole spec.
|
|
243
|
+
function mergeDescription(base, parsed) {
|
|
244
|
+
if (isObject(parsed.mapping) && parsed.mapping.description !== undefined) {
|
|
245
|
+
const mode = parsed.mapping.description
|
|
246
|
+
if (!DESCRIPTION_MODES.includes(mode)) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`Invalid ${configFile}: mapping.description = ${JSON.stringify(mode)} ` +
|
|
249
|
+
`(expected one of ${DESCRIPTION_MODES.join('|')})`,
|
|
250
|
+
)
|
|
251
|
+
}
|
|
252
|
+
base.mapping.description = mode
|
|
253
|
+
}
|
|
254
|
+
if (isObject(parsed.summary) && parsed.summary.delimiter !== undefined) {
|
|
255
|
+
const style = parsed.summary.delimiter
|
|
256
|
+
if (!DELIMITER_STYLES.includes(style)) {
|
|
257
|
+
throw new Error(
|
|
258
|
+
`Invalid ${configFile}: summary.delimiter = ${JSON.stringify(style)} ` +
|
|
259
|
+
`(expected one of ${DELIMITER_STYLES.join('|')})`,
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
base.summary = { ...(base.summary || {}), delimiter: style }
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
239
266
|
return {
|
|
240
267
|
mergeStates,
|
|
241
268
|
mergeStateOverrides,
|
|
@@ -243,9 +270,15 @@ function makeMergeHelpers({ configFile, ownership, lifecycleBuckets, phaseMappin
|
|
|
243
270
|
mergePhaseMapping,
|
|
244
271
|
mergeReleaseIgnorePaths,
|
|
245
272
|
mergeKeyedFields,
|
|
273
|
+
mergeDescription,
|
|
246
274
|
}
|
|
247
275
|
}
|
|
248
276
|
|
|
277
|
+
// What `mapping.description` may be. `spec` is the default and what a config
|
|
278
|
+
// that predates the key gets, so an upgrade rewrites no ticket.
|
|
279
|
+
const DESCRIPTION_MODES = Object.freeze(['spec', 'summary'])
|
|
280
|
+
const DELIMITER_STYLES = Object.freeze(['comment', 'heading'])
|
|
281
|
+
|
|
249
282
|
// Keys no provider reads any more. The merge already ignores them, as it does
|
|
250
283
|
// every unknown key — so a config still carrying one is a stale file, not a
|
|
251
284
|
// broken one, and `doctor` says so as a `warn` without touching the exit code.
|
|
@@ -292,4 +325,4 @@ function retiredKeysRow(file, configFile, row) {
|
|
|
292
325
|
)
|
|
293
326
|
}
|
|
294
327
|
|
|
295
|
-
module.exports = { isObject, stringList, assign, makeMergeHelpers, retiredKeys, retiredKeysRow, RETIRED_KEYS }
|
|
328
|
+
module.exports = { isObject, stringList, assign, makeMergeHelpers, retiredKeys, retiredKeysRow, RETIRED_KEYS, DESCRIPTION_MODES, DELIMITER_STYLES }
|
|
@@ -63,7 +63,7 @@ function storePath(env = process.env, homedir = os.homedir) {
|
|
|
63
63
|
* `absent` (no file — the normal default, not a problem), `permissions`
|
|
64
64
|
* (group/world readable), `unreadable`, `malformed`.
|
|
65
65
|
*/
|
|
66
|
-
function readStore(file, { stat = fs.statSync, read = fs.readFileSync } = {}) {
|
|
66
|
+
function readStore(file, { stat = fs.statSync, read = fs.readFileSync, platform = process.platform } = {}) {
|
|
67
67
|
let info
|
|
68
68
|
try {
|
|
69
69
|
info = stat(file)
|
|
@@ -74,7 +74,12 @@ function readStore(file, { stat = fs.statSync, read = fs.readFileSync } = {}) {
|
|
|
74
74
|
return { ok: false, code: 'unreadable', path: file, reason: `cannot read ${file}: ${err.message}` }
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
// ON WINDOWS THE MODE BITS SAY NOTHING. Node reports every file there as
|
|
78
|
+
// 0o666, so this check refused every store on Windows and no stored
|
|
79
|
+
// credential could ever be read (chore-windows-ci). Access there is the
|
|
80
|
+
// profile directory's ACL, which these bits do not describe — cannot tell,
|
|
81
|
+
// and cannot-tell does not accuse (`.claude/rules/negative-checks.md`).
|
|
82
|
+
if (platform !== 'win32' && info.mode & GROUP_OR_WORLD) {
|
|
78
83
|
const mode = (info.mode & 0o777).toString(8)
|
|
79
84
|
return {
|
|
80
85
|
ok: false,
|
|
@@ -14,22 +14,46 @@ function expandStateArgs(args, config) {
|
|
|
14
14
|
return (args || []).flatMap((arg) => (LIFECYCLE_BUCKETS.includes(arg) ? stateNamesFor(arg, config) : [arg]))
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
17
|
+
// A spec's bucket is a CODE FACT — whether `/spec-start`, `/spec-complete` or
|
|
18
|
+
// `/spec-cancel` has run — and the board holds the planning status. So almost
|
|
19
|
+
// every difference between the two is the board doing its job: a backlog spec
|
|
20
|
+
// the board calls Ready or Blocked, an in-flight one it calls In Review. Neither
|
|
21
|
+
// is a claim about the repo, and flagging them would teach a reader to ignore
|
|
22
|
+
// the column.
|
|
23
|
+
//
|
|
24
|
+
// One difference IS worth a reader's time: the board says the work is finished
|
|
25
|
+
// (Done or Cancelled) and the repo has not done the matching cleanup. Only that
|
|
26
|
+
// pairing disagrees, and it carries the command that would close it.
|
|
27
|
+
const LIVE_BUCKETS = ['backlog', 'in-progress']
|
|
28
|
+
const FINISHED_BUCKETS = ['complete', 'cancelled']
|
|
29
|
+
|
|
30
|
+
// `{ board, cleanup }` when the board has finished what the repo has not, else
|
|
31
|
+
// null. Done against a spec in flight is `/spec-complete`; every other pairing
|
|
32
|
+
// (Cancelled, or Done on a spec that never started) is `/spec-cancel`, because
|
|
33
|
+
// there is no work here to complete.
|
|
34
|
+
function boardDisagreement(specBucket, boardBucket) {
|
|
35
|
+
if (!LIVE_BUCKETS.includes(specBucket) || !FINISHED_BUCKETS.includes(boardBucket)) return null
|
|
36
|
+
const cleanup = specBucket === 'in-progress' && boardBucket === 'complete' ? '/spec-complete' : '/spec-cancel'
|
|
37
|
+
return { board: boardBucket, cleanup }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// The spec's status beside the board's, and whether they disagree in the one
|
|
41
|
+
// way above. A board state that maps to no bucket never disagrees: it is
|
|
42
|
+
// somewhere push does not manage, which is not a claim about the spec. Nor does
|
|
43
|
+
// a row whose spec is not on this machine — there is nothing to disagree WITH.
|
|
21
44
|
function specColumn(stateName, spec, config) {
|
|
22
45
|
const specStatus = spec ? spec.bucket : null
|
|
23
46
|
const seen = stateName == null ? null : remoteStateReading({ state: { name: stateName } }, config)
|
|
24
|
-
const
|
|
25
|
-
return { specStatus, disagrees }
|
|
47
|
+
const found = specStatus && seen && seen.mapped ? boardDisagreement(specStatus, seen.bucket) : null
|
|
48
|
+
return found ? { specStatus, disagrees: true, cleanup: found.cleanup } : { specStatus, disagrees: false }
|
|
26
49
|
}
|
|
27
50
|
|
|
28
|
-
// The cell itself: `in-progress`, `≠
|
|
29
|
-
// spec is not here.
|
|
30
|
-
function specCell({ specStatus, disagrees }) {
|
|
51
|
+
// The cell itself: `in-progress`, `≠ in-progress → /spec-cancel` when the board
|
|
52
|
+
// finished it, `—` when the spec is not here.
|
|
53
|
+
function specCell({ specStatus, disagrees, cleanup }) {
|
|
31
54
|
if (!specStatus) return '—'
|
|
32
|
-
|
|
55
|
+
if (!disagrees) return specStatus
|
|
56
|
+
return cleanup ? `≠ ${specStatus} → ${cleanup}` : `≠ ${specStatus}`
|
|
33
57
|
}
|
|
34
58
|
|
|
35
|
-
module.exports = { expandStateArgs, specColumn, specCell }
|
|
59
|
+
module.exports = { expandStateArgs, specColumn, specCell, boardDisagreement }
|