@skitterbyte/skitterspec-github 0.0.0-stage → 1.0.1
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/MIGRATION.md +1126 -0
- package/README.md +53 -2
- package/assets/claude-md-section.md +85 -0
- package/assets/commands/allow-main.md +33 -0
- package/assets/commands/spec-connect.md +13 -0
- package/assets/commands/spec-live.md +14 -0
- package/assets/commands/spec-remote-review.md +37 -0
- package/assets/commands/spec-skip.md +24 -0
- package/assets/core/SETUP.md +112 -0
- package/assets/core/env.config.json.example +56 -0
- package/assets/core/env.config.md +557 -0
- package/assets/core/gating.config.json.example +4 -0
- package/assets/core/gating.config.md +81 -0
- package/assets/core/github.config.json.example +18 -0
- package/assets/core/github.config.md +66 -0
- package/assets/hooks/main-guard.cjs +162 -0
- package/assets/hooks/review-gate.cjs +146 -0
- package/assets/review/page.html +3384 -0
- package/assets/rules/commit-trailers.md +103 -0
- package/assets/rules/negative-checks.md +69 -0
- package/assets/rules/offered-unblocks.md +100 -0
- package/assets/rules/spec-planning.md +692 -0
- package/assets/rules/spec-reports.md +557 -0
- package/assets/skills/no-spec/SKILL.md +246 -0
- package/assets/skills/spec/SKILL.md +718 -0
- package/assets/skills/spec-bug/SKILL.md +646 -0
- package/assets/skills/spec-cancel/SKILL.md +263 -0
- package/assets/skills/spec-claim/SKILL.md +122 -0
- package/assets/skills/spec-complete/SKILL.md +450 -0
- package/assets/skills/spec-diff/SKILL.md +870 -0
- package/assets/skills/spec-github-setup/SKILL.md +236 -0
- package/assets/skills/spec-hotfix/SKILL.md +668 -0
- package/assets/skills/spec-init/SKILL.md +178 -0
- package/assets/skills/spec-list/SKILL.md +172 -0
- package/assets/skills/spec-next/SKILL.md +685 -0
- package/assets/skills/spec-push/SKILL.md +307 -0
- package/assets/skills/spec-review/SKILL.md +258 -0
- package/assets/skills/spec-reviewed/SKILL.md +284 -0
- package/assets/skills/spec-start/SKILL.md +554 -0
- package/assets/skills/spec-status/SKILL.md +112 -0
- package/assets/skills/spec-sync/SKILL.md +226 -0
- package/assets/skills/spec-to-main/SKILL.md +139 -0
- package/bin/skitterspec-github.js +61 -0
- package/package.json +41 -4
- package/src/cli.js +5907 -0
- package/src/deprecate.js +138 -0
- package/src/env/bootstrap.js +188 -0
- package/src/env/building.js +143 -0
- package/src/env/classify.js +176 -0
- package/src/env/commitcmd.js +108 -0
- package/src/env/config.js +753 -0
- package/src/env/dev.js +63 -0
- package/src/env/hooks.js +226 -0
- package/src/env/hotfix.js +411 -0
- package/src/env/hotfixland.js +302 -0
- package/src/env/integrate.js +126 -0
- package/src/env/live.js +504 -0
- package/src/env/mainguard.js +299 -0
- package/src/env/provision.js +466 -0
- package/src/env/proxy.js +225 -0
- package/src/env/prune.js +119 -0
- package/src/env/registry.js +159 -0
- package/src/env/render.js +17 -0
- package/src/env/resolve.js +716 -0
- package/src/env/review.js +2577 -0
- package/src/env/reviewers/coderabbit.js +228 -0
- package/src/env/reviewers.js +517 -0
- package/src/env/serve.js +1044 -0
- package/src/env/supervise.js +157 -0
- package/src/env/teardown.js +248 -0
- package/src/env/trust.js +87 -0
- package/src/gating.js +155 -0
- package/src/init.js +1150 -0
- package/src/lines-diff.js +114 -0
- package/src/prompts.js +129 -0
- package/src/vendor/github/api.js +800 -0
- package/src/vendor/github/cli-sync.js +1530 -0
- package/src/vendor/github/commands.js +44 -0
- package/src/vendor/github/config.js +414 -0
- package/src/vendor/github/credentials.js +109 -0
- package/src/vendor/github/dialect.js +62 -0
- package/src/vendor/github/identity.js +38 -0
- package/src/vendor/github/mcp.js +85 -0
- package/src/vendor/provider-kit/index.js +41 -0
- package/src/vendor/provider-kit/src/adapter.js +23 -0
- package/src/vendor/provider-kit/src/apply.js +207 -0
- package/src/vendor/provider-kit/src/args.js +68 -0
- package/src/vendor/provider-kit/src/assignment.js +277 -0
- package/src/vendor/provider-kit/src/config.js +198 -0
- package/src/vendor/provider-kit/src/credentials.js +404 -0
- package/src/vendor/provider-kit/src/doctor.js +35 -0
- package/src/vendor/provider-kit/src/http.js +63 -0
- package/src/vendor/provider-kit/src/identity.js +93 -0
- package/src/vendor/provider-kit/src/md-compare.js +39 -0
- package/src/vendor/provider-kit/src/md-tables.js +94 -0
- package/src/vendor/provider-kit/src/prompt.js +50 -0
- package/src/vendor/provider-kit/src/released.js +269 -0
- package/src/vendor/provider-kit/src/releases.js +380 -0
- package/src/vendor/provider-kit/src/specs.js +166 -0
- package/src/vendor/provider-kit/src/transport.js +22 -0
- package/src/vendor/sync-core/index.js +93 -0
- package/src/vendor/sync-core/src/base.js +81 -0
- package/src/vendor/sync-core/src/compare.js +338 -0
- package/src/vendor/sync-core/src/dialect.js +51 -0
- package/src/vendor/sync-core/src/fields.js +36 -0
- package/src/vendor/sync-core/src/legacy.js +100 -0
- package/src/vendor/sync-core/src/normalize.js +998 -0
- package/src/vendor/sync-core/src/push.js +85 -0
- package/src/vendor/sync-core/src/retarget.js +278 -0
- package/src/vendor/sync-core/src/task-block.js +308 -0
- package/src/vendor/sync-core/src/verify.js +67 -0
- package/src/vendor/sync-core/src/write.js +191 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Assignment — who is building a spec, mirrored to the tracker's assignee.
|
|
5
|
+
*
|
|
6
|
+
* Three commands every provider with assignment shares, hoisted from the
|
|
7
|
+
* Linear provider when GitHub became the second consumer:
|
|
8
|
+
*
|
|
9
|
+
* - `assign <spec> --to <id> [--name <n>] | --release` stamps (or clears) the
|
|
10
|
+
* assignee fields in the overview frontmatter. It writes the REPO and
|
|
11
|
+
* nothing else; the next push carries it, like any other field.
|
|
12
|
+
* - `whoami [--set <id> [--name <n>]] [--unset]` reports — and caches — who
|
|
13
|
+
* the operator is in the tracker, which is the fact assignment rests on.
|
|
14
|
+
* - `users [<query>]` finds a person to hand a spec to.
|
|
15
|
+
*
|
|
16
|
+
* Everything tracker-shaped arrives as a hook (`makeAssignmentCommands`): the
|
|
17
|
+
* tracker's name for messages, the frontmatter fields, the store scope, how a
|
|
18
|
+
* credential resolves and how an adapter is made. The behaviour is the Linear
|
|
19
|
+
* provider's, unchanged — its tests still pin every message.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const path = require('node:path')
|
|
23
|
+
|
|
24
|
+
const { ownsField, writeFrontmatter, deleteFrontmatter, fieldsOf } = require('../../sync-core')
|
|
25
|
+
const { resolveTransport } = require('./transport.js')
|
|
26
|
+
const { makeSpecHelpers } = require('./specs.js')
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {object} p
|
|
30
|
+
* - `tracker` the tracker's name in messages ("Linear", "GitHub")
|
|
31
|
+
* - `configFile` the provider config path, for refusals
|
|
32
|
+
* - `bin` the command a person types (for the hints)
|
|
33
|
+
* - `idHint` how a user id is described ("<linear-user-id>", "<login>")
|
|
34
|
+
* - `scopeOf(config)` → `{ id, label }` the credentials-store scope, or `{ id: '' , missing }` with
|
|
35
|
+
* `missing` the refusal text when the config cannot name one
|
|
36
|
+
* - `storePath(env)`, `writeUser(file, scope, user)`, `removeUser(file, scope)`
|
|
37
|
+
* - `resolveIdentity(config, env, deps)` the provider's identity binding
|
|
38
|
+
* - `resolveCredential(config, env)` → `{ ok, error? }`
|
|
39
|
+
* - `makeAdapter(config, credential, flags)` → an adapter with `searchUsers`
|
|
40
|
+
* - `displayNameOf(user)`
|
|
41
|
+
* - `validateAssignee(config, id, flags)` OPTIONAL — async, resolves to a
|
|
42
|
+
* refusal string or null. Absent means "do not check", which is the Linear
|
|
43
|
+
* provider's behaviour.
|
|
44
|
+
* - `usersOverMcp` the hint printed when users must be searched over MCP
|
|
45
|
+
* - `unknownHint` OPTIONAL extra lines for the unknown-identity whoami report
|
|
46
|
+
*/
|
|
47
|
+
function makeAssignmentCommands(p) {
|
|
48
|
+
const helpers = makeSpecHelpers({ program: 'spec-sync' })
|
|
49
|
+
|
|
50
|
+
async function assign(dir, config, specArg, flags, out) {
|
|
51
|
+
const snapshotDir = helpers.resolveOrExit(specArg, dir, out)
|
|
52
|
+
if (!snapshotDir) return 1
|
|
53
|
+
const fields = fieldsOf(config)
|
|
54
|
+
|
|
55
|
+
const overviewFile = (config.snapshot && config.snapshot.overviewFile) || '00-overview.md'
|
|
56
|
+
const identifier = helpers.linkedIdentifier(path.join(snapshotDir, overviewFile), config)
|
|
57
|
+
const rel = path.relative(dir, snapshotDir)
|
|
58
|
+
|
|
59
|
+
const problems = []
|
|
60
|
+
if (flags.release && flags.to) problems.push('--release and --to are opposites — pass one')
|
|
61
|
+
if (!flags.release && !flags.to) problems.push('nothing to do — pass --to <user-id> or --release')
|
|
62
|
+
// An unlinked spec has no issue to assign. Refusing beats stamping a field
|
|
63
|
+
// that would sit in the file doing nothing until someone noticed.
|
|
64
|
+
if (!identifier) problems.push(`${rel} is not linked to ${p.tracker} — /spec-push it first`)
|
|
65
|
+
// AND THE SAME REASONING FOR THE FIELD ITSELF. A field the repo does not own
|
|
66
|
+
// is dropped from the projection, so a stamp written here would never reach
|
|
67
|
+
// the tracker — while the success line says `next: push it`. That is not a
|
|
68
|
+
// silent skip, it is an untrue assertion. Applies to `--release` too.
|
|
69
|
+
if (!ownsField(config, 'assignee')) {
|
|
70
|
+
problems.push(
|
|
71
|
+
'this repo does not own the assignee field — set sync.fieldOwnership.assignee ' +
|
|
72
|
+
`to "push" in ${p.configFile}`,
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
// A POSITIVE refusal only: the hook answers "this id cannot be assigned"
|
|
76
|
+
// or null, and every cannot-tell inside it must be null.
|
|
77
|
+
if (!problems.length && flags.to && p.validateAssignee) {
|
|
78
|
+
const refusal = await p.validateAssignee(config, flags.to, flags)
|
|
79
|
+
if (refusal) problems.push(refusal)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (problems.length) {
|
|
83
|
+
out.write(
|
|
84
|
+
['spec-sync assign: refusing to write — nothing was changed', ...problems.map((x) => ` ${x}`)].join('\n') + '\n',
|
|
85
|
+
)
|
|
86
|
+
return 1
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (flags.release) {
|
|
90
|
+
const removed = deleteFrontmatter(snapshotDir, config, [fields.assigneeId, fields.assigneeName].filter(Boolean))
|
|
91
|
+
if (flags.json) {
|
|
92
|
+
out.write(JSON.stringify({ spec: rel, issue: identifier, released: removed.length > 0 }, null, 2) + '\n')
|
|
93
|
+
return 0
|
|
94
|
+
}
|
|
95
|
+
out.write(
|
|
96
|
+
(removed.length
|
|
97
|
+
? `spec-sync assign: ${rel} released (${identifier})\n`
|
|
98
|
+
: `spec-sync assign: ${rel} records no assignee — nothing to release\n`) +
|
|
99
|
+
` next: push it, so ${p.tracker} is unassigned too\n`,
|
|
100
|
+
)
|
|
101
|
+
return 0
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
writeFrontmatter(snapshotDir, config, {
|
|
105
|
+
[fields.assigneeId]: flags.to,
|
|
106
|
+
// Display only — the projection never sends it. It exists so a reader (and
|
|
107
|
+
// `/spec-claim`) can name the person without a tracker round trip.
|
|
108
|
+
...(fields.assigneeName ? { [fields.assigneeName]: flags.name || null } : {}),
|
|
109
|
+
})
|
|
110
|
+
if (flags.json) {
|
|
111
|
+
out.write(JSON.stringify({ spec: rel, issue: identifier, id: flags.to, name: flags.name || null }, null, 2) + '\n')
|
|
112
|
+
return 0
|
|
113
|
+
}
|
|
114
|
+
const who = flags.name ? `${flags.name} (${flags.to})` : flags.to
|
|
115
|
+
out.write(`spec-sync assign: ${rel} assigned to ${who} (${identifier})\n next: push it, so ${p.tracker} agrees\n`)
|
|
116
|
+
return 0
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Exit 0 even when the answer is "unknown": this answers a question, and
|
|
121
|
+
* "nobody is identified here" is a valid answer — a shared key, an offline
|
|
122
|
+
* machine. A successful DERIVE is cached; a cache read is not re-written, and
|
|
123
|
+
* the caching lives here so that asking never has a side effect.
|
|
124
|
+
*/
|
|
125
|
+
async function whoami(dir, config, flags, out) {
|
|
126
|
+
const env = flags.env || process.env
|
|
127
|
+
const file = p.storePath(env)
|
|
128
|
+
const scope = p.scopeOf(config)
|
|
129
|
+
|
|
130
|
+
// The store is keyed by scope, so without one there is nowhere to read from
|
|
131
|
+
// or write to. That IS a broken config, so it exits non-zero.
|
|
132
|
+
if (!scope.id) {
|
|
133
|
+
out.write(scope.missing + '\n')
|
|
134
|
+
return 1
|
|
135
|
+
}
|
|
136
|
+
const label = scope.label || scope.id
|
|
137
|
+
|
|
138
|
+
if (flags.unset) {
|
|
139
|
+
const r = p.removeUser(file, scope.id, {})
|
|
140
|
+
if (!r.ok) {
|
|
141
|
+
out.write(`spec-sync whoami: ${r.reason}\n`)
|
|
142
|
+
return 1
|
|
143
|
+
}
|
|
144
|
+
out.write(
|
|
145
|
+
r.removed
|
|
146
|
+
? `spec-sync whoami: forgot the identity for ${label} (the ${p.credentialNoun || 'API key'} is untouched)\n`
|
|
147
|
+
: `spec-sync whoami: no identity stored for ${label} — nothing to forget\n`,
|
|
148
|
+
)
|
|
149
|
+
return 0
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (flags.set) {
|
|
153
|
+
const r = p.writeUser(file, scope.id, { id: flags.set, name: flags.name }, {})
|
|
154
|
+
if (!r.ok) {
|
|
155
|
+
out.write(`spec-sync whoami: ${r.reason}\n`)
|
|
156
|
+
return 1
|
|
157
|
+
}
|
|
158
|
+
if (flags.json) {
|
|
159
|
+
out.write(JSON.stringify({ id: flags.set, name: flags.name || null, source: 'set', store: r.path }, null, 2) + '\n')
|
|
160
|
+
return 0
|
|
161
|
+
}
|
|
162
|
+
const shown = flags.name ? `${flags.name} (${flags.set})` : flags.set
|
|
163
|
+
out.write(`spec-sync whoami: identity for ${label} set to ${shown} in ${r.path} (600)\n`)
|
|
164
|
+
return 0
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const identity = await p.resolveIdentity(config, env, { adapter: flags.adapter, fetch: flags.fetch })
|
|
168
|
+
|
|
169
|
+
if (identity.ok && identity.source === 'viewer') {
|
|
170
|
+
// A failed write is not fatal: we HAVE the answer, and re-deriving it next
|
|
171
|
+
// time is a slower success, not a wrong one.
|
|
172
|
+
const cached = p.writeUser(file, scope.id, { id: identity.id, name: identity.name }, {})
|
|
173
|
+
if (!cached.ok) identity.cacheWarning = cached.reason
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (flags.json) {
|
|
177
|
+
out.write(
|
|
178
|
+
JSON.stringify(
|
|
179
|
+
{
|
|
180
|
+
[p.scopeJsonKey || 'team']: label,
|
|
181
|
+
store: file,
|
|
182
|
+
ok: identity.ok,
|
|
183
|
+
id: identity.id || null,
|
|
184
|
+
name: identity.name || null,
|
|
185
|
+
source: identity.source,
|
|
186
|
+
reason: identity.ok ? null : identity.reason || null,
|
|
187
|
+
},
|
|
188
|
+
null,
|
|
189
|
+
2,
|
|
190
|
+
) + '\n',
|
|
191
|
+
)
|
|
192
|
+
return 0
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (!identity.ok) {
|
|
196
|
+
out.write(
|
|
197
|
+
[
|
|
198
|
+
'spec-sync whoami: unknown — no identity for this workspace',
|
|
199
|
+
` ${identity.reason}`,
|
|
200
|
+
' Set one by hand:',
|
|
201
|
+
` ${p.bin} spec-sync whoami --set ${p.idHint} --name "<your name>"`,
|
|
202
|
+
` Find the id with: ${p.bin} spec-sync users <name-or-email>`,
|
|
203
|
+
].join('\n') + '\n',
|
|
204
|
+
)
|
|
205
|
+
return 0
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const where = identity.source === 'store' ? `cached in ${file}` : `derived from the ${p.credentialNoun || 'API key'}`
|
|
209
|
+
const lines = [
|
|
210
|
+
`spec-sync whoami: ${identity.name || '(unnamed)'} <${identity.id}>`,
|
|
211
|
+
` ${(p.scopeLineLabel || 'team:').padEnd(7)} ${label}`,
|
|
212
|
+
` source: ${where}`,
|
|
213
|
+
]
|
|
214
|
+
if (identity.cacheWarning) lines.push(` note: not cached — ${identity.cacheWarning}`)
|
|
215
|
+
out.write(lines.join('\n') + '\n')
|
|
216
|
+
return 0
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The engine answers on the API path and steps aside on the MCP path — the
|
|
221
|
+
* same contract `states` follows.
|
|
222
|
+
*/
|
|
223
|
+
async function users(dir, config, query, flags, out) {
|
|
224
|
+
const cred = p.resolveCredential(config, flags.env || process.env)
|
|
225
|
+
const transport = resolveTransport(flags, config, cred.ok || !!flags.adapter)
|
|
226
|
+
|
|
227
|
+
if (transport === 'mcp') {
|
|
228
|
+
if (flags.json) {
|
|
229
|
+
out.write(JSON.stringify({ transport: 'mcp', reason: cred.ok ? 'requested' : cred.error, users: null }, null, 2) + '\n')
|
|
230
|
+
return 0
|
|
231
|
+
}
|
|
232
|
+
out.write(
|
|
233
|
+
['spec-sync users: transport = mcp', ` ${cred.ok ? '--via mcp was requested' : cred.error}`, ` ${p.usersOverMcp}`].join('\n') +
|
|
234
|
+
'\n',
|
|
235
|
+
)
|
|
236
|
+
return 0
|
|
237
|
+
}
|
|
238
|
+
if (!cred.ok && !flags.adapter) {
|
|
239
|
+
out.write(`spec-sync users: refusing — ${cred.error}\n`)
|
|
240
|
+
return 1
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const adapter = flags.adapter || p.makeAdapter(config, cred, flags)
|
|
244
|
+
let page
|
|
245
|
+
try {
|
|
246
|
+
page = await adapter.searchUsers(query || '', { limit: flags.limit || 50, cursor: flags.cursor || null })
|
|
247
|
+
} catch (error) {
|
|
248
|
+
out.write(`spec-sync users: ${error.message}\n`)
|
|
249
|
+
return 1
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const list = (page && page.users) || []
|
|
253
|
+
if (flags.json) {
|
|
254
|
+
out.write(JSON.stringify({ transport: 'api', users: list, nextCursor: (page && page.nextCursor) || null }, null, 2) + '\n')
|
|
255
|
+
return 0
|
|
256
|
+
}
|
|
257
|
+
if (!list.length) {
|
|
258
|
+
out.write(`spec-sync users: no match for ${JSON.stringify(query || '')}\n`)
|
|
259
|
+
return 0
|
|
260
|
+
}
|
|
261
|
+
const lines = [`spec-sync users: ${list.length} match(es)`]
|
|
262
|
+
for (const u of list) {
|
|
263
|
+
// A deactivated user still resolves by id and can still be assigned, so
|
|
264
|
+
// the marker is the difference between a valid pick and a silently dead one.
|
|
265
|
+
const inactive = u && u.active === false ? ' [deactivated]' : ''
|
|
266
|
+
const email = u && u.email ? ` ${u.email}` : ''
|
|
267
|
+
lines.push(` ${p.displayNameOf(u) || '(unnamed)'} <${u && u.id}>${email}${inactive}`)
|
|
268
|
+
}
|
|
269
|
+
if (page && page.nextCursor) lines.push(` … more — re-run with --cursor ${page.nextCursor}`)
|
|
270
|
+
out.write(lines.join('\n') + '\n')
|
|
271
|
+
return 0
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return { assign, whoami, users }
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
module.exports = { makeAssignmentCommands }
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Config-merge machinery shared by every provider's loader.
|
|
5
|
+
*
|
|
6
|
+
* A provider's config is a committed JSON file merged over its own defaults —
|
|
7
|
+
* only known keys copied (unknown ignored for forward-compat), typed fields
|
|
8
|
+
* validated LOUDLY where a typo would otherwise read as a deliberate choice.
|
|
9
|
+
* The defaults, the file name and the vocabularies are the provider's; the
|
|
10
|
+
* merge and validation shapes are identical across providers, so they live
|
|
11
|
+
* here, bound to the provider by `makeMergeHelpers`.
|
|
12
|
+
*
|
|
13
|
+
* Every thrown message names the provider's own config file, so a refusal
|
|
14
|
+
* points at the file the user actually edits.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function isObject(value) {
|
|
18
|
+
return value != null && typeof value === 'object' && !Array.isArray(value)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Normalise an array config value to trimmed, non-empty strings.
|
|
22
|
+
function stringList(value) {
|
|
23
|
+
return value.filter((s) => typeof s === 'string' && s.trim()).map((s) => s.trim())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Copy a typed field from parsed[key] onto base[key] when it matches `type`.
|
|
27
|
+
// Strings are trimmed and must be non-empty to override; `string?` may be empty.
|
|
28
|
+
function assign(base, parsed, key, type) {
|
|
29
|
+
const v = parsed[key]
|
|
30
|
+
if (type === 'string') {
|
|
31
|
+
if (typeof v === 'string' && v.trim()) base[key] = v.trim()
|
|
32
|
+
} else if (type === 'string?') {
|
|
33
|
+
if (typeof v === 'string') base[key] = v
|
|
34
|
+
} else if (type === 'boolean') {
|
|
35
|
+
if (typeof v === 'boolean') base[key] = v
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The provider-bound validators. `configFile` is only used in messages;
|
|
41
|
+
* `ownership` / `lifecycleBuckets` / `phaseMappings` are the provider's own
|
|
42
|
+
* vocabularies (they rarely differ between providers, but they are the
|
|
43
|
+
* provider's to declare).
|
|
44
|
+
*/
|
|
45
|
+
function makeMergeHelpers({ configFile, ownership, lifecycleBuckets, phaseMappings }) {
|
|
46
|
+
// Merge (and validate) sync.fieldOwnership. Any key the caller lists joins
|
|
47
|
+
// the compared field set; the value MUST be one of the ownership modes.
|
|
48
|
+
function mergeFieldOwnership(base, parsed) {
|
|
49
|
+
if (!isObject(parsed)) return
|
|
50
|
+
for (const [field, dir] of Object.entries(parsed)) {
|
|
51
|
+
if (!ownership.includes(dir)) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Invalid ${configFile}: sync.fieldOwnership.${field} = ${JSON.stringify(dir)} ` +
|
|
54
|
+
`(expected one of ${ownership.join('|')})`,
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
base[field] = dir
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Merge (and validate) `mapping.phases` in either of its two forms: a scalar
|
|
62
|
+
// mode for the whole repo, or a map of lifecycle bucket → mode. Loud on a bad
|
|
63
|
+
// key or value — a misspelt bucket would otherwise read as a deliberate
|
|
64
|
+
// default and go on minting the sub-issues the config was written to stop.
|
|
65
|
+
function mergePhaseMapping(base, parsed) {
|
|
66
|
+
const value = parsed.phases
|
|
67
|
+
if (typeof value === 'string') {
|
|
68
|
+
if (value.trim()) base.phases = value.trim()
|
|
69
|
+
} else if (isObject(value)) {
|
|
70
|
+
const byBucket = {}
|
|
71
|
+
for (const [bucket, mode] of Object.entries(value)) {
|
|
72
|
+
if (!lifecycleBuckets.includes(bucket)) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Invalid ${configFile}: mapping.phases.${bucket} is not a lifecycle bucket ` +
|
|
75
|
+
`(expected one of ${lifecycleBuckets.join('|')})`,
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
if (!phaseMappings.includes(mode)) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Invalid ${configFile}: mapping.phases.${bucket} = ${JSON.stringify(mode)} ` +
|
|
81
|
+
`(expected one of ${phaseMappings.join('|')})`,
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
byBucket[bucket] = mode
|
|
85
|
+
}
|
|
86
|
+
base.phases = byBucket
|
|
87
|
+
} else if (value !== undefined) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Invalid ${configFile}: mapping.phases = ${JSON.stringify(value)} ` +
|
|
90
|
+
`(expected one of ${phaseMappings.join('|')}, or a map of lifecycle bucket to mode)`,
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
if (typeof base.phases === 'string' && !phaseMappings.includes(base.phases)) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Invalid ${configFile}: mapping.phases = ${JSON.stringify(base.phases)} ` +
|
|
96
|
+
`(expected one of ${phaseMappings.join('|')}, or a map of lifecycle bucket to mode)`,
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Merge (and validate) `release.stages` — the project's deployment ladder.
|
|
102
|
+
//
|
|
103
|
+
// Loud on a malformed entry: this list names tracker states, and a tracker
|
|
104
|
+
// that silently ignores an unknown state would let a half-typed ladder push
|
|
105
|
+
// clean and move nothing — so a bad shape fails here, at load, rather than at
|
|
106
|
+
// the first deploy nobody is watching. An ABSENT `release` block is not an
|
|
107
|
+
// error: it is the opt-out, and the whole feature is unused without it.
|
|
108
|
+
function mergeReleaseStages(base, parsed) {
|
|
109
|
+
const value = parsed.stages
|
|
110
|
+
if (value === undefined) return
|
|
111
|
+
if (!Array.isArray(value)) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`Invalid ${configFile}: release.stages = ${JSON.stringify(value)} ` +
|
|
114
|
+
'(expected an array of { key, state })',
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
const stages = []
|
|
118
|
+
const seen = new Set()
|
|
119
|
+
value.forEach((entry, i) => {
|
|
120
|
+
if (!isObject(entry)) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
`Invalid ${configFile}: release.stages[${i}] = ${JSON.stringify(entry)} ` +
|
|
123
|
+
'(expected { key, state })',
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
for (const field of ['key', 'state']) {
|
|
127
|
+
if (typeof entry[field] !== 'string' || !entry[field].trim()) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`Invalid ${configFile}: release.stages[${i}].${field} = ${JSON.stringify(entry[field])} ` +
|
|
130
|
+
'(expected a non-empty string)',
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const key = entry.key.trim()
|
|
135
|
+
if (seen.has(key)) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Invalid ${configFile}: release.stages[${i}].key = ${JSON.stringify(key)} is a duplicate ` +
|
|
138
|
+
'(a stage key is how CI names the rung, so it must be unique)',
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
seen.add(key)
|
|
142
|
+
stages.push({ key, state: entry.state.trim() })
|
|
143
|
+
})
|
|
144
|
+
base.stages = stages
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Merge (and validate) release.ignorePaths — the path prefixes whose commits
|
|
148
|
+
// are bookkeeping. Loud on anything but an array of non-empty strings: a bad
|
|
149
|
+
// value that quietly fell back would let a project believe it had opted out
|
|
150
|
+
// and go on double-counting tickets. A BLANK entry is rejected rather than
|
|
151
|
+
// dropped — `""` is a prefix of every path, so a stray empty string would
|
|
152
|
+
// silently ignore every commit in the range and report a release as
|
|
153
|
+
// containing nothing: the loudest possible wrong answer, arriving as silence.
|
|
154
|
+
function mergeReleaseIgnorePaths(base, parsed) {
|
|
155
|
+
const value = parsed.ignorePaths
|
|
156
|
+
if (value === undefined) return
|
|
157
|
+
if (!Array.isArray(value)) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`Invalid ${configFile}: release.ignorePaths = ${JSON.stringify(value)} ` +
|
|
160
|
+
'(expected an array of repo-relative path prefixes)',
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
value.forEach((entry, i) => {
|
|
164
|
+
if (typeof entry !== 'string' || !entry.trim()) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
`Invalid ${configFile}: release.ignorePaths[${i}] = ${JSON.stringify(entry)} ` +
|
|
167
|
+
'(expected a non-empty repo-relative path prefix, e.g. "specs/")',
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
base.ignorePaths = stringList(value)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Merge (and validate) sync.keyedFields. Each value is the item's id property
|
|
175
|
+
// name (a non-empty string); a field listed here is compared per item.
|
|
176
|
+
function mergeKeyedFields(base, parsed) {
|
|
177
|
+
if (!isObject(parsed)) return
|
|
178
|
+
for (const [field, idKey] of Object.entries(parsed)) {
|
|
179
|
+
if (typeof idKey !== 'string' || !idKey.trim()) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
`Invalid ${configFile}: sync.keyedFields.${field} = ${JSON.stringify(idKey)} ` +
|
|
182
|
+
'(expected the item id property name, a non-empty string)',
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
base[field] = idKey.trim()
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
mergeFieldOwnership,
|
|
191
|
+
mergePhaseMapping,
|
|
192
|
+
mergeReleaseStages,
|
|
193
|
+
mergeReleaseIgnorePaths,
|
|
194
|
+
mergeKeyedFields,
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
module.exports = { isObject, stringList, assign, makeMergeHelpers }
|