@skitterbyte/skitterspec-azure-boards 1.2.1 → 2.0.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/MIGRATION.md +141 -1
- package/README.md +8 -7
- package/assets/core/SETUP.md +8 -20
- package/assets/core/azure-boards.config.md +53 -4
- package/assets/rules/spec-planning.md +13 -3
- package/assets/rules/spec-reports.md +19 -4
- package/assets/skills/spec-azure-setup/SKILL.md +2 -1
- package/assets/skills/spec-bug/SKILL.md +3 -1
- package/assets/skills/spec-hotfix/SKILL.md +3 -1
- package/assets/skills/spec-list/SKILL.md +28 -5
- package/assets/skills/spec-next/SKILL.md +3 -1
- package/assets/skills/spec-status/SKILL.md +28 -26
- package/assets/skills/spec-sync/SKILL.md +11 -14
- package/package.json +1 -1
- package/src/cli.js +6 -25
- package/src/env/review.js +47 -2
- package/src/vendor/azure-boards/api.js +39 -123
- package/src/vendor/azure-boards/cli-sync.js +73 -66
- package/src/vendor/azure-boards/config.js +9 -44
- package/src/vendor/provider-kit/src/config.js +101 -48
- package/src/vendor/provider-kit/src/list-assignee.js +71 -0
- package/src/vendor/provider-kit/src/list-rows.js +35 -0
- package/src/vendor/provider-kit/src/released.js +27 -77
- package/src/vendor/provider-kit/src/specs.js +89 -7
- package/src/vendor/sync-core/index.js +3 -4
- package/src/vendor/sync-core/src/compare.js +6 -6
- package/src/vendor/sync-core/src/normalize.js +30 -57
- package/src/vendor/provider-kit/src/releases.js +0 -380
|
@@ -34,7 +34,7 @@ const {
|
|
|
34
34
|
isEmptyPlan,
|
|
35
35
|
validateStates,
|
|
36
36
|
stateSuggestions,
|
|
37
|
-
|
|
37
|
+
stateNamesFor,
|
|
38
38
|
remoteDescriptionEdited,
|
|
39
39
|
writeFrontmatter,
|
|
40
40
|
stampSubIssueId,
|
|
@@ -45,7 +45,8 @@ const kit = require('../provider-kit')
|
|
|
45
45
|
const { BUCKETS, findSpecFolder, currentBranch } = require('../../env/resolve.js')
|
|
46
46
|
|
|
47
47
|
const { makeAssignmentCommands } = require('../provider-kit/src/assignment.js')
|
|
48
|
-
const {
|
|
48
|
+
const { resolveListAssignee } = require('../provider-kit/src/list-assignee.js')
|
|
49
|
+
const { expandStateArgs, specColumn, specCell } = require('../provider-kit/src/list-rows.js')
|
|
49
50
|
const { IDENTIFIER_RE } = require('../provider-kit/src/released.js')
|
|
50
51
|
|
|
51
52
|
const { loadAzureConfig, mergeConfig, defaults, CONFIG_FILE, LIFECYCLE_BUCKETS } = require('./config.js')
|
|
@@ -67,7 +68,7 @@ const BIN = 'skitterspec-azure-boards'
|
|
|
67
68
|
|
|
68
69
|
const PROGRAM = 'spec-sync'
|
|
69
70
|
const specHelpers = kit.makeSpecHelpers({ program: PROGRAM })
|
|
70
|
-
const { resolveSnapshotDir, specIdentifier, listSpecs, resolveOrExit, warnToErr, verifyLines } = specHelpers
|
|
71
|
+
const { resolveSnapshotDir, specIdentifier, listSpecs, listSpecsLive, resolveOrExit, warnToErr, verifyLines } = specHelpers
|
|
71
72
|
|
|
72
73
|
// A work item identifier: the constant AB prefix and a number. A bare number
|
|
73
74
|
// is accepted on input and normalised, so a stamp can be copied from the
|
|
@@ -257,7 +258,6 @@ function apiAdapterFor(config, flags) {
|
|
|
257
258
|
orgUrl: config.azure.orgUrl,
|
|
258
259
|
project: config.azure.project,
|
|
259
260
|
token: cred.token,
|
|
260
|
-
releaseType: (config.releases && config.releases.workItemType) || 'Release',
|
|
261
261
|
fetch: flags.fetch,
|
|
262
262
|
}),
|
|
263
263
|
}
|
|
@@ -317,12 +317,13 @@ function specSyncReleased(dir, config, rangeArg, flags, out) {
|
|
|
317
317
|
refPattern: AZURE_REF_RE,
|
|
318
318
|
foreignPatterns: foreign.patterns,
|
|
319
319
|
})
|
|
320
|
+
report.tickets = kit.nameTickets(report.tickets, listSpecs(dir, config, { urls: true }))
|
|
320
321
|
if (flags.json) {
|
|
321
322
|
out.write(JSON.stringify(report, null, 2) + '\n')
|
|
322
323
|
return 0
|
|
323
324
|
}
|
|
324
325
|
const lines = [`${PROGRAM} released: ${range} — ${report.total} commit(s)`]
|
|
325
|
-
for (const t of report.tickets) lines.push(` ${t.ref} (${t.commits} commit(s))`)
|
|
326
|
+
for (const t of report.tickets) lines.push(` ${t.ref} (${t.commits} commit(s))${t.spec ? ` ${t.spec}` : ''}`)
|
|
326
327
|
if (!report.tickets.length) lines.push(' no referenced tickets')
|
|
327
328
|
if (report.unreferenced) lines.push(` ${report.unreferenced} commit(s) carry no Refs: trailer`)
|
|
328
329
|
if (report.historical) lines.push(` ${report.historical} commit(s) reference an earlier tracker`)
|
|
@@ -331,34 +332,6 @@ function specSyncReleased(dir, config, rangeArg, flags, out) {
|
|
|
331
332
|
return 0
|
|
332
333
|
}
|
|
333
334
|
|
|
334
|
-
// ---------------------------------------------------------------------------
|
|
335
|
-
// `release create | deployed | complete` — the kit's release seam
|
|
336
|
-
// (`provider-kit/src/releases.js`), carried by a work item of
|
|
337
|
-
// `releases.workItemType` (spec Decision 12): skitterspec decides the ticket
|
|
338
|
-
// set, the item holds it, `deployed` moves the ITEM's state, `complete`
|
|
339
|
-
// closes it.
|
|
340
|
-
const releases = makeReleaseCommands({
|
|
341
|
-
tracker: 'Azure Boards',
|
|
342
|
-
program: PROGRAM,
|
|
343
|
-
readCommits: (dir, range) => readCommitRange(dir, range),
|
|
344
|
-
ticketOptions: (config) => ({
|
|
345
|
-
ignorePaths: (config.release && config.release.ignorePaths) || [],
|
|
346
|
-
refPattern: AZURE_REF_RE,
|
|
347
|
-
foreignPatterns: foreignPatternsOf(config).patterns,
|
|
348
|
-
}),
|
|
349
|
-
teamKey: () => '',
|
|
350
|
-
listSpecs: (dir, config) => listSpecs(dir, config),
|
|
351
|
-
series: (config) => (config.releases && config.releases.series) || [],
|
|
352
|
-
adapterFor: (config, flags) => apiAdapterFor(config, flags),
|
|
353
|
-
describe: (t) => `${t.ref}${t.title ? ` ${t.title}` : ''}`,
|
|
354
|
-
// The release verbs are CI commands and the engine never calls MCP tools —
|
|
355
|
-
// so over MCP this is impossible, not merely slower, and says so (exit 1).
|
|
356
|
-
impossibleOverMcp: (config, flags) =>
|
|
357
|
-
kit.resolveTransport(flags, config, true) === 'mcp'
|
|
358
|
-
? 'transport = mcp — the release verbs write over the API; set a PAT (CI: a pipeline secret) and re-run'
|
|
359
|
-
: null,
|
|
360
|
-
})
|
|
361
|
-
|
|
362
335
|
// ---------------------------------------------------------------------------
|
|
363
336
|
// Assignment: `assign`, `whoami` and `users` are the kit's
|
|
364
337
|
// (`provider-kit/src/assignment.js`); this is Azure's binding. The id is the
|
|
@@ -712,13 +685,9 @@ function specSyncStatus(dir, config, specArg, flags, out, err) {
|
|
|
712
685
|
out.write(`${PROGRAM} status: cannot read --remote: ${error.message}\n`)
|
|
713
686
|
return 1
|
|
714
687
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
lines.push(` drift: Azure says "${bucket}", the repo says "${local}" (repo wins on next push)`)
|
|
719
|
-
} else if (bucket) {
|
|
720
|
-
lines.push(' drift: none — Azure agrees with the repo')
|
|
721
|
-
}
|
|
688
|
+
// NO STATE LINE, deliberately: skitterspec tells the tracker about its own
|
|
689
|
+
// transitions and never reads a status back. A ticket someone moved there
|
|
690
|
+
// is theirs to have moved, and push resends State only when the spec does.
|
|
722
691
|
// SILENT ON EVERYTHING EXCEPT A POSITIVE ANSWER: `remoteDescriptionEdited`
|
|
723
692
|
// returns null for every cannot-tell, and none of those is evidence.
|
|
724
693
|
if (remoteDescriptionEdited(readBase(dir, identifier, config), remote, config) === true) {
|
|
@@ -831,6 +800,12 @@ async function specSyncStates(dir, config, flags, out) {
|
|
|
831
800
|
? `ok${catOf.get(name) ? ` [${catOf.get(name)}]` : ''}`
|
|
832
801
|
: `MISSING from these types${suggestions.get(bucket) ? ` — closest: "${suggestions.get(bucket)}"` : ''}`
|
|
833
802
|
lines.push(` ${bucket.padEnd(bw)} -> ${String(name).padEnd(nw)} ${tail}`)
|
|
803
|
+
// Aliases are read-only, so a missing one never blocks a push — but it
|
|
804
|
+
// reads as nothing, so it is still named.
|
|
805
|
+
for (const alias of stateNamesFor(bucket, config).slice(1)) {
|
|
806
|
+
const here = names.includes(alias)
|
|
807
|
+
lines.push(` ${''.padEnd(bw)} ${String(alias).padEnd(nw)} ${here ? 'also reads as ' + bucket : 'alias MISSING — reads as nothing'}`)
|
|
808
|
+
}
|
|
834
809
|
}
|
|
835
810
|
if (missing.length) lines.push(` remap: ${PROGRAM} init-config --force --state <bucket>="<state>"`)
|
|
836
811
|
out.write(lines.join('\n') + '\n')
|
|
@@ -838,6 +813,15 @@ async function specSyncStates(dir, config, flags, out) {
|
|
|
838
813
|
}
|
|
839
814
|
|
|
840
815
|
async function specSyncList(dir, config, flags, out) {
|
|
816
|
+
// `--next N` is the top of the BACKLOG in the backlog's own order, so it
|
|
817
|
+
// fixes the scope itself — combined with --state or --all one would have to
|
|
818
|
+
// lose, silently. Refused before any transport work, as Linear does.
|
|
819
|
+
const next = Number.isFinite(flags.next) && flags.next > 0 ? flags.next : null
|
|
820
|
+
const scopeFlags = [next !== null && '--next', flags.all === true && '--all', (flags.stateArgs || []).length > 0 && '--state'].filter(Boolean)
|
|
821
|
+
if (scopeFlags.length > 1) {
|
|
822
|
+
out.write(`${PROGRAM} list: ${scopeFlags.join(' and ')} each pick the scope, so they cannot be combined\n`)
|
|
823
|
+
return 1
|
|
824
|
+
}
|
|
841
825
|
const cred = apiAdapterFor(config, flags)
|
|
842
826
|
const transport = kit.resolveTransport(flags, config, cred.ok)
|
|
843
827
|
if (transport === 'mcp' || !cred.ok) {
|
|
@@ -850,20 +834,38 @@ async function specSyncList(dir, config, flags, out) {
|
|
|
850
834
|
out.write(`${PROGRAM} list: no azure.project configured — fix ${CONFIG_FILE}\n`)
|
|
851
835
|
return 1
|
|
852
836
|
}
|
|
837
|
+
const who = await resolveListAssignee({
|
|
838
|
+
flags,
|
|
839
|
+
config,
|
|
840
|
+
env: flags.env || process.env,
|
|
841
|
+
adapter: cred.adapter,
|
|
842
|
+
resolveIdentity,
|
|
843
|
+
displayNameOf,
|
|
844
|
+
tracker: 'Azure DevOps',
|
|
845
|
+
prog: PROGRAM,
|
|
846
|
+
})
|
|
847
|
+
if (who.code != null) {
|
|
848
|
+
out.write(who.lines.join('\n') + '\n')
|
|
849
|
+
return who.code
|
|
850
|
+
}
|
|
851
|
+
const assignee = who.assignee
|
|
853
852
|
let items
|
|
854
853
|
try {
|
|
855
854
|
items = await cred.adapter.searchIssues({
|
|
856
855
|
query: '',
|
|
857
856
|
workItemType: config.azure.workItemType,
|
|
858
|
-
|
|
857
|
+
assignedTo: assignee ? assignee.id : null,
|
|
858
|
+
states: next !== null ? stateNamesFor('backlog', config) : null,
|
|
859
|
+
orderBy: next !== null ? config.azure.backlogOrderField : null,
|
|
860
|
+
limit: next !== null ? next : flags.limit || 50,
|
|
859
861
|
})
|
|
860
|
-
const stateNames = flags.stateArgs
|
|
862
|
+
const stateNames = expandStateArgs(flags.stateArgs, config)
|
|
861
863
|
if (stateNames.length) {
|
|
862
864
|
const want = new Set(stateNames.map((s) => s.toLowerCase()))
|
|
863
865
|
items = items.filter((i) => i.state && want.has(String(i.state.name).toLowerCase()))
|
|
864
|
-
} else if (!flags.all) {
|
|
866
|
+
} else if (!flags.all && next === null) {
|
|
865
867
|
const terminal = new Set(
|
|
866
|
-
[
|
|
868
|
+
[...stateNamesFor('complete', config), ...stateNamesFor('cancelled', config)].map((s) => s.toLowerCase()),
|
|
867
869
|
)
|
|
868
870
|
items = items.filter((i) => !i.state || !terminal.has(String(i.state.name).toLowerCase()))
|
|
869
871
|
}
|
|
@@ -871,26 +873,35 @@ async function specSyncList(dir, config, flags, out) {
|
|
|
871
873
|
out.write(`${PROGRAM} list: ${error.message}\n`)
|
|
872
874
|
return 1
|
|
873
875
|
}
|
|
874
|
-
const linked = new Map(
|
|
876
|
+
const linked = new Map(listSpecsLive(dir, config).filter((s) => s.identifier).map((s) => [s.identifier, s]))
|
|
875
877
|
const rows = items
|
|
876
878
|
.filter((i) => !i.parent)
|
|
877
|
-
.map((i) =>
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
879
|
+
.map((i) => {
|
|
880
|
+
const spec = linked.get(i.identifier) || null
|
|
881
|
+
const state = i.state ? i.state.name : null
|
|
882
|
+
return {
|
|
883
|
+
identifier: i.identifier,
|
|
884
|
+
title: i.title,
|
|
885
|
+
state,
|
|
886
|
+
...specColumn(state, spec, config),
|
|
887
|
+
assignee: i.assignee ? i.assignee.name || i.assignee.email || i.assignee.id : null,
|
|
888
|
+
spec: spec ? spec.spec : null,
|
|
889
|
+
}
|
|
890
|
+
})
|
|
883
891
|
if (flags.json) {
|
|
884
892
|
out.write(JSON.stringify(rows, null, 2) + '\n')
|
|
885
893
|
return 0
|
|
886
894
|
}
|
|
887
895
|
if (!rows.length) {
|
|
888
|
-
out.write(`${PROGRAM} list: nothing matched\n`)
|
|
896
|
+
out.write(`${PROGRAM} list: nothing matched${assignee ? ` for ${assignee.name}` : ''}\n`)
|
|
889
897
|
return 0
|
|
890
898
|
}
|
|
891
|
-
const
|
|
899
|
+
const scope = next !== null ? ` · next ${next} by ${config.azure.backlogOrderField}` : ''
|
|
900
|
+
const lines = [`${PROGRAM} list: ${config.azure.project}${assignee ? ` · assigned to ${assignee.name}` : ''}${scope}`]
|
|
892
901
|
for (const r of rows) {
|
|
893
|
-
lines.push(
|
|
902
|
+
lines.push(
|
|
903
|
+
` ${r.identifier}\t${r.state || '—'}\t${specCell(r)}\t${r.assignee || 'unassigned'}\t${r.title || ''}${r.spec ? ` -> ${r.spec}` : ' (no spec)'}`,
|
|
904
|
+
)
|
|
894
905
|
}
|
|
895
906
|
out.write(lines.join('\n') + '\n')
|
|
896
907
|
return 0
|
|
@@ -1242,6 +1253,8 @@ async function specSyncDoctor(dir, flags, out) {
|
|
|
1242
1253
|
checks.push(row('tracker', 'Azure config', 'broken', 'orgUrl or project is empty', `fix ${CONFIG_FILE}`))
|
|
1243
1254
|
} else {
|
|
1244
1255
|
checks.push(row('tracker', 'Azure config', 'ok', `${loaded.config.azure.project} @ ${loaded.config.azure.orgUrl}`))
|
|
1256
|
+
const retired = kit.retiredKeysRow(path.join(dir, CONFIG_FILE), CONFIG_FILE, row)
|
|
1257
|
+
if (retired) checks.push(retired)
|
|
1245
1258
|
// A worktree forks from a COMMIT, so a config that exists only in the
|
|
1246
1259
|
// working tree is invisible in every spec worktree — where the sync
|
|
1247
1260
|
// skills actually run — and sync there reports itself off with no clue
|
|
@@ -1354,11 +1367,10 @@ const USAGE = `Usage: skitterspec-azure-boards spec-sync <subcommand>
|
|
|
1354
1367
|
status <spec> [--remote <f>] read-only drift report
|
|
1355
1368
|
verify <spec> --stored <f> compare a read-back against the repo
|
|
1356
1369
|
states [--json] the configured types' state names
|
|
1357
|
-
list [--all | --state NAME]
|
|
1370
|
+
list [--all | --state NAME|BUCKET | --next N] [--mine | --by USER] tracker listing
|
|
1358
1371
|
linked [--json] specs and their linked items (offline)
|
|
1359
1372
|
ref [<spec>] the Refs: trailer value for this branch
|
|
1360
1373
|
released [<range>] tickets a commit range contains
|
|
1361
|
-
release create|deployed|complete <tag> the release work item (CI; --apply)
|
|
1362
1374
|
preserve <spec> [--text <f>] keep an adopted item's original report
|
|
1363
1375
|
assign <spec> --to <id> | --release stamp who is building it
|
|
1364
1376
|
whoami [--set <id>] [--unset] who you are on Azure (cached)
|
|
@@ -1437,16 +1449,8 @@ async function specSync(rest, io = {}) {
|
|
|
1437
1449
|
return specSyncRef(dir, config, positional[0], flags, out, err)
|
|
1438
1450
|
case 'released':
|
|
1439
1451
|
return specSyncReleased(dir, config, positional[0], flags, out)
|
|
1440
|
-
case 'release':
|
|
1441
|
-
|
|
1442
|
-
// one silently would re-count that tracker's history as unreferenced.
|
|
1443
|
-
const foreign = foreignPatternsOf(config)
|
|
1444
|
-
if (foreign.bad.length) {
|
|
1445
|
-
out.write(`${PROGRAM} release: refs.foreignPatterns has invalid pattern(s): ${foreign.bad.join(', ')} — fix ${CONFIG_FILE}\n`)
|
|
1446
|
-
return 1
|
|
1447
|
-
}
|
|
1448
|
-
return releases.run(dir, config, positional, flags, out)
|
|
1449
|
-
}
|
|
1452
|
+
case 'release':
|
|
1453
|
+
return kit.refuseRemovedVerb(out, PROGRAM, 'release')
|
|
1450
1454
|
case 'preserve':
|
|
1451
1455
|
return specSyncPreserve(dir, config, positional[0], flags, out)
|
|
1452
1456
|
case 'assign':
|
|
@@ -1500,6 +1504,9 @@ function parseArgs(args, sub) {
|
|
|
1500
1504
|
'--to': { kind: 'string' },
|
|
1501
1505
|
'--name': { kind: 'string' },
|
|
1502
1506
|
'--release': { kind: 'boolean' },
|
|
1507
|
+
'--mine': { kind: 'boolean' },
|
|
1508
|
+
'--next': { kind: 'number' },
|
|
1509
|
+
'--by': { kind: 'string' },
|
|
1503
1510
|
'--set': { kind: 'string' },
|
|
1504
1511
|
'--unset': { kind: 'boolean' },
|
|
1505
1512
|
'--stdin': { kind: 'boolean' },
|
|
@@ -41,6 +41,10 @@ const DEFAULT_CONFIG = Object.freeze({
|
|
|
41
41
|
workItemType: 'Issue',
|
|
42
42
|
childType: 'Task',
|
|
43
43
|
areaPath: '',
|
|
44
|
+
// The field `list --next` orders the backlog by. StackRank is the rank
|
|
45
|
+
// the Basic, Agile and CMMI backlogs drag-order; a Scrum process ranks by
|
|
46
|
+
// `Microsoft.VSTS.Common.BacklogPriority` instead.
|
|
47
|
+
backlogOrderField: 'Microsoft.VSTS.Common.StackRank',
|
|
44
48
|
// The mint type per SPEC KIND (`feature`/`bug`/`hotfix`, from the spec
|
|
45
49
|
// folder's prefix), falling back to `workItemType`. In Agile, Scrum and
|
|
46
50
|
// CMMI a bug is a work item TYPE, so `/spec-bug` minting a User Story
|
|
@@ -95,14 +99,8 @@ const DEFAULT_CONFIG = Object.freeze({
|
|
|
95
99
|
// accuses.
|
|
96
100
|
refs: Object.freeze({ foreignPatterns: Object.freeze([]) }),
|
|
97
101
|
release: Object.freeze({
|
|
98
|
-
stages: Object.freeze([]),
|
|
99
102
|
ignorePaths: Object.freeze(['specs/', 'CHANGELOG.md', 'RELEASES.md']),
|
|
100
103
|
}),
|
|
101
|
-
// The release seam's Azure carrier (spec Decision 12): one work item of
|
|
102
|
-
// `workItemType` per release, found by WIQL title lookup, its state moved
|
|
103
|
-
// through `series[].envs`. Phase 5 implements the verbs; the config shape
|
|
104
|
-
// lives here so setup writes one file.
|
|
105
|
-
releases: Object.freeze({ workItemType: 'Release', series: Object.freeze([]) }),
|
|
106
104
|
branch: Object.freeze({ pattern: '{type}/{slug}' }),
|
|
107
105
|
// An env-var NAME, not a value — the official CLI's, so a machine already
|
|
108
106
|
// set up for `az boards` needs nothing new.
|
|
@@ -141,6 +139,7 @@ function defaults() {
|
|
|
141
139
|
azure: { ...DEFAULT_CONFIG.azure },
|
|
142
140
|
mapping: { ...DEFAULT_CONFIG.mapping },
|
|
143
141
|
states: { ...DEFAULT_CONFIG.states },
|
|
142
|
+
stateAliases: {},
|
|
144
143
|
intake: {
|
|
145
144
|
tag: DEFAULT_CONFIG.intake.tag,
|
|
146
145
|
bugTags: [...DEFAULT_CONFIG.intake.bugTags],
|
|
@@ -152,13 +151,8 @@ function defaults() {
|
|
|
152
151
|
fields: { ...DEFAULT_CONFIG.fields },
|
|
153
152
|
refs: { foreignPatterns: [...DEFAULT_CONFIG.refs.foreignPatterns] },
|
|
154
153
|
release: {
|
|
155
|
-
stages: DEFAULT_CONFIG.release.stages.map((s) => ({ ...s })),
|
|
156
154
|
ignorePaths: [...DEFAULT_CONFIG.release.ignorePaths],
|
|
157
155
|
},
|
|
158
|
-
releases: {
|
|
159
|
-
workItemType: DEFAULT_CONFIG.releases.workItemType,
|
|
160
|
-
series: DEFAULT_CONFIG.releases.series.map((s) => ({ ...s })),
|
|
161
|
-
},
|
|
162
156
|
branch: { ...DEFAULT_CONFIG.branch },
|
|
163
157
|
auth: { ...DEFAULT_CONFIG.auth },
|
|
164
158
|
apply: { ...DEFAULT_CONFIG.apply },
|
|
@@ -173,7 +167,7 @@ function defaults() {
|
|
|
173
167
|
}
|
|
174
168
|
|
|
175
169
|
const { isObject, stringList, assign } = kitConfig
|
|
176
|
-
const { mergeFieldOwnership, mergePhaseMapping,
|
|
170
|
+
const { mergeStates, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
|
|
177
171
|
kitConfig.makeMergeHelpers({
|
|
178
172
|
configFile: CONFIG_FILE,
|
|
179
173
|
ownership: OWNERSHIP,
|
|
@@ -181,22 +175,6 @@ const { mergeFieldOwnership, mergePhaseMapping, mergeReleaseStages, mergeRelease
|
|
|
181
175
|
phaseMappings: PHASE_MAPPINGS,
|
|
182
176
|
})
|
|
183
177
|
|
|
184
|
-
// A release series entry carries the tag prefix it scans and the state each
|
|
185
|
-
// env moves the release item to. Lenient on extras, strict on shape: a series
|
|
186
|
-
// that is not a list of objects is a config error worth naming now.
|
|
187
|
-
function mergeReleaseSeries(base, parsed) {
|
|
188
|
-
if (parsed.series === undefined) return
|
|
189
|
-
if (!Array.isArray(parsed.series) || parsed.series.some((s) => !isObject(s))) {
|
|
190
|
-
throw new Error(`Invalid ${CONFIG_FILE}: releases.series must be a list of objects`)
|
|
191
|
-
}
|
|
192
|
-
base.series = parsed.series.map((s) => ({
|
|
193
|
-
tagPrefix: typeof s.tagPrefix === 'string' ? s.tagPrefix : '',
|
|
194
|
-
envs: isObject(s.envs)
|
|
195
|
-
? Object.fromEntries(Object.entries(s.envs).filter(([, v]) => typeof v === 'string'))
|
|
196
|
-
: {},
|
|
197
|
-
}))
|
|
198
|
-
}
|
|
199
|
-
|
|
200
178
|
/**
|
|
201
179
|
* Merge a parsed config over the defaults. Only known keys are copied (unknown
|
|
202
180
|
* keys ignored for forward-compat). Nested objects are merged field-by-field.
|
|
@@ -210,6 +188,7 @@ function mergeConfig(base, parsed) {
|
|
|
210
188
|
assign(base.azure, parsed.azure, 'workItemType', 'string')
|
|
211
189
|
assign(base.azure, parsed.azure, 'childType', 'string')
|
|
212
190
|
assign(base.azure, parsed.azure, 'areaPath', 'string?')
|
|
191
|
+
assign(base.azure, parsed.azure, 'backlogOrderField', 'string')
|
|
213
192
|
if (isObject(parsed.azure.workItemTypeByKind)) {
|
|
214
193
|
// Only the kinds a spec folder can actually be — an unknown key is
|
|
215
194
|
// dropped rather than carried into `states` validation it can never pass.
|
|
@@ -236,11 +215,7 @@ function mergeConfig(base, parsed) {
|
|
|
236
215
|
mergePhaseMapping(base.mapping, parsed.mapping)
|
|
237
216
|
}
|
|
238
217
|
|
|
239
|
-
|
|
240
|
-
for (const key of Object.keys(base.states)) {
|
|
241
|
-
assign(base.states, parsed.states, key, 'string')
|
|
242
|
-
}
|
|
243
|
-
}
|
|
218
|
+
mergeStates(base, parsed)
|
|
244
219
|
|
|
245
220
|
if (isObject(parsed.intake)) {
|
|
246
221
|
assign(base.intake, parsed.intake, 'tag', 'string?')
|
|
@@ -261,14 +236,9 @@ function mergeConfig(base, parsed) {
|
|
|
261
236
|
}
|
|
262
237
|
|
|
263
238
|
if (isObject(parsed.release)) {
|
|
264
|
-
mergeReleaseStages(base.release, parsed.release)
|
|
265
239
|
mergeReleaseIgnorePaths(base.release, parsed.release)
|
|
266
240
|
}
|
|
267
241
|
|
|
268
|
-
if (isObject(parsed.releases)) {
|
|
269
|
-
assign(base.releases, parsed.releases, 'workItemType', 'string')
|
|
270
|
-
mergeReleaseSeries(base.releases, parsed.releases)
|
|
271
|
-
}
|
|
272
242
|
|
|
273
243
|
if (isObject(parsed.branch)) {
|
|
274
244
|
assign(base.branch, parsed.branch, 'pattern', 'string')
|
|
@@ -368,18 +338,13 @@ function loadAzureConfig(dir = process.cwd()) {
|
|
|
368
338
|
return { config: withRuntime(mergeConfig(base, parsed)), present: true }
|
|
369
339
|
}
|
|
370
340
|
|
|
371
|
-
// The
|
|
372
|
-
// accessors the other providers expose, reading this provider's config.
|
|
373
|
-
const releaseStages = (config) => (config.release && config.release.stages) || []
|
|
374
|
-
const stageFor = (config, key) => releaseStages(config).find((s) => s.key === key) || null
|
|
341
|
+
// The bookkeeping path prefixes `released` ignores.
|
|
375
342
|
const releaseIgnorePaths = (config) => (config.release && config.release.ignorePaths) || []
|
|
376
343
|
|
|
377
344
|
module.exports = {
|
|
378
345
|
loadAzureConfig,
|
|
379
346
|
mergeConfig,
|
|
380
347
|
defaults,
|
|
381
|
-
releaseStages,
|
|
382
|
-
stageFor,
|
|
383
348
|
releaseIgnorePaths,
|
|
384
349
|
DEFAULT_CONFIG,
|
|
385
350
|
CONFIG_FILE,
|
|
@@ -98,52 +98,6 @@ function makeMergeHelpers({ configFile, ownership, lifecycleBuckets, phaseMappin
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
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
101
|
// Merge (and validate) release.ignorePaths — the path prefixes whose commits
|
|
148
102
|
// are bookkeeping. Loud on anything but an array of non-empty strings: a bad
|
|
149
103
|
// value that quietly fell back would let a project believe it had opted out
|
|
@@ -186,13 +140,112 @@ function makeMergeHelpers({ configFile, ownership, lifecycleBuckets, phaseMappin
|
|
|
186
140
|
}
|
|
187
141
|
}
|
|
188
142
|
|
|
143
|
+
// Merge (and validate) `states`. A bucket's value is a string — the one state
|
|
144
|
+
// push writes, exactly as it always was — or a non-empty array whose FIRST
|
|
145
|
+
// name is the one push writes and whose rest are read-only aliases: tracker
|
|
146
|
+
// states that also mean this bucket ("Blocked" for in-progress). The first
|
|
147
|
+
// name lands in `states[bucket]`, so every writer is unchanged; the rest go
|
|
148
|
+
// to `stateAliases[bucket]`, read only by code that interprets a remote state.
|
|
149
|
+
//
|
|
150
|
+
// An ALIAS in two buckets is refused: it would make a remote state mean two
|
|
151
|
+
// things, and which one won would be an accident of iteration order. Two
|
|
152
|
+
// buckets sharing one written name stays legal, as it always was — a tracker
|
|
153
|
+
// with no Cancelled state maps cancelled to "Done" — so only a name that an
|
|
154
|
+
// alias contributes is checked.
|
|
155
|
+
function mergeStates(base, parsed) {
|
|
156
|
+
const value = parsed.states
|
|
157
|
+
if (!isObject(value)) return
|
|
158
|
+
const aliases = {}
|
|
159
|
+
for (const bucket of Object.keys(base.states)) {
|
|
160
|
+
const entry = value[bucket]
|
|
161
|
+
if (entry === undefined) continue
|
|
162
|
+
if (typeof entry === 'string') {
|
|
163
|
+
if (entry.trim()) base.states[bucket] = entry.trim()
|
|
164
|
+
continue
|
|
165
|
+
}
|
|
166
|
+
if (!Array.isArray(entry) || !entry.length || entry.some((n) => typeof n !== 'string' || !n.trim())) {
|
|
167
|
+
throw new Error(
|
|
168
|
+
`Invalid ${configFile}: states.${bucket} = ${JSON.stringify(entry)} ` +
|
|
169
|
+
'(expected a state name, or a non-empty array of them — the first is what push writes)',
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
const names = entry.map((n) => n.trim())
|
|
173
|
+
base.states[bucket] = names[0]
|
|
174
|
+
aliases[bucket] = names.slice(1)
|
|
175
|
+
}
|
|
176
|
+
const owner = new Map()
|
|
177
|
+
for (const bucket of Object.keys(base.states)) {
|
|
178
|
+
const key = base.states[bucket].toLowerCase()
|
|
179
|
+
if (!owner.has(key)) owner.set(key, bucket)
|
|
180
|
+
}
|
|
181
|
+
for (const bucket of Object.keys(aliases)) {
|
|
182
|
+
for (const name of aliases[bucket]) {
|
|
183
|
+
const key = name.toLowerCase()
|
|
184
|
+
if (owner.has(key) && owner.get(key) !== bucket) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`Invalid ${configFile}: states name ${JSON.stringify(name)} is in both ` +
|
|
187
|
+
`${owner.get(key)} and ${bucket} (a tracker state can mean only one bucket)`,
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
owner.set(key, bucket)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
base.stateAliases = aliases
|
|
194
|
+
}
|
|
195
|
+
|
|
189
196
|
return {
|
|
197
|
+
mergeStates,
|
|
190
198
|
mergeFieldOwnership,
|
|
191
199
|
mergePhaseMapping,
|
|
192
|
-
mergeReleaseStages,
|
|
193
200
|
mergeReleaseIgnorePaths,
|
|
194
201
|
mergeKeyedFields,
|
|
195
202
|
}
|
|
196
203
|
}
|
|
197
204
|
|
|
198
|
-
|
|
205
|
+
// Keys no provider reads any more. The merge already ignores them, as it does
|
|
206
|
+
// every unknown key — so a config still carrying one is a stale file, not a
|
|
207
|
+
// broken one, and `doctor` says so as a `warn` without touching the exit code.
|
|
208
|
+
//
|
|
209
|
+
// WHAT WOULD FOOL THIS: it reads the committed file, so a key set only in a
|
|
210
|
+
// working-tree edit is still reported — which is the file a person would edit.
|
|
211
|
+
const RETIRED_KEYS = Object.freeze([
|
|
212
|
+
{ path: ['releases'], name: 'releases' },
|
|
213
|
+
{ path: ['release', 'stages'], name: 'release.stages' },
|
|
214
|
+
])
|
|
215
|
+
|
|
216
|
+
// The retired keys present in a parsed config. Not an object, or none present,
|
|
217
|
+
// is `[]`: nothing to say is the safe answer to every cannot-tell.
|
|
218
|
+
function retiredKeys(parsed) {
|
|
219
|
+
if (!isObject(parsed)) return []
|
|
220
|
+
return RETIRED_KEYS.filter(({ path }) => {
|
|
221
|
+
let node = parsed
|
|
222
|
+
for (const key of path) {
|
|
223
|
+
if (!isObject(node) || !(key in node)) return false
|
|
224
|
+
node = node[key]
|
|
225
|
+
}
|
|
226
|
+
return true
|
|
227
|
+
}).map((k) => k.name)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// A doctor row naming the retired keys in the config at `file`, or null when
|
|
231
|
+
// there are none — or when the file cannot be read or parsed, which is the
|
|
232
|
+
// loader's to report, not this row's.
|
|
233
|
+
function retiredKeysRow(file, configFile, row) {
|
|
234
|
+
let parsed = null
|
|
235
|
+
try {
|
|
236
|
+
parsed = JSON.parse(require('node:fs').readFileSync(file, 'utf-8'))
|
|
237
|
+
} catch {
|
|
238
|
+
return null
|
|
239
|
+
}
|
|
240
|
+
const names = retiredKeys(parsed)
|
|
241
|
+
if (!names.length) return null
|
|
242
|
+
return row(
|
|
243
|
+
'retired',
|
|
244
|
+
'Retired config',
|
|
245
|
+
'warn',
|
|
246
|
+
`${names.join(', ')} in ${configFile} is no longer read — release and deploy state is the host project's to write (see \`spec-sync released --json\`)`,
|
|
247
|
+
`remove ${names.join(', ')} from ${configFile}`,
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
module.exports = { isObject, stringList, assign, makeMergeHelpers, retiredKeys, retiredKeysRow, RETIRED_KEYS }
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `spec-sync list --mine | --by <user>` — whose tickets to list.
|
|
5
|
+
*
|
|
6
|
+
* Linear defined the contract (`linear/src/cli-sync.js`, decision 9 of
|
|
7
|
+
* `feat-linear-assignment`); this is the same contract for every provider that
|
|
8
|
+
* lists over the API, so the two sentences below mean the same thing anywhere:
|
|
9
|
+
*
|
|
10
|
+
* - `--mine` with an UNKNOWN identity lists nothing and exits 0. Identity is
|
|
11
|
+
* an ordinary unknown (a bot token, an offline machine). What must never
|
|
12
|
+
* happen is dropping the filter and printing everyone's work under a
|
|
13
|
+
* heading that promised yours.
|
|
14
|
+
* - `--by` that matches nobody, or more than one person, exits 1. The
|
|
15
|
+
* argument is wrong and only the caller can fix it — the same shape as an
|
|
16
|
+
* unknown `--state` — and a fallback to everyone would be the same lie.
|
|
17
|
+
*
|
|
18
|
+
* Returns `{ assignee: { id, name } | null }` to carry on with, or
|
|
19
|
+
* `{ code, lines }` to print and stop.
|
|
20
|
+
*/
|
|
21
|
+
async function resolveListAssignee({ flags, config, env, adapter, resolveIdentity, displayNameOf, tracker, prog }) {
|
|
22
|
+
if (flags.mine && flags.by) {
|
|
23
|
+
return {
|
|
24
|
+
code: 1,
|
|
25
|
+
lines: [
|
|
26
|
+
`${prog} list: --mine and --by both filter by assignee, so they cannot be combined`,
|
|
27
|
+
' use --mine for your own, or --by <user> for someone else.',
|
|
28
|
+
],
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (flags.mine) {
|
|
32
|
+
const who = await resolveIdentity(config, env, { adapter })
|
|
33
|
+
if (!who || !who.ok) {
|
|
34
|
+
return {
|
|
35
|
+
code: 0,
|
|
36
|
+
lines: [
|
|
37
|
+
`${prog} list: --mine needs to know who you are, and it does not (${(who && who.reason) || 'no identity'})`,
|
|
38
|
+
' run `spec-sync whoami --set <id>` to say so, or use --by <user>.',
|
|
39
|
+
],
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { assignee: { id: who.id, name: who.name || who.id } }
|
|
43
|
+
}
|
|
44
|
+
if (flags.by) {
|
|
45
|
+
const term = String(flags.by)
|
|
46
|
+
let found
|
|
47
|
+
try {
|
|
48
|
+
found = await adapter.searchUsers(term, { limit: 50 })
|
|
49
|
+
} catch (error) {
|
|
50
|
+
return { code: 1, lines: [`${prog} list: could not search users (${error.message})`] }
|
|
51
|
+
}
|
|
52
|
+
const users = (found && found.users) || []
|
|
53
|
+
if (!users.length) {
|
|
54
|
+
return {
|
|
55
|
+
code: 1,
|
|
56
|
+
lines: [`${prog} list: no ${tracker} user matches ${JSON.stringify(term)}`, ' `spec-sync users <term>` lists who there is.'],
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (users.length > 1) {
|
|
60
|
+
const lines = [`${prog} list: ${users.length} users match ${JSON.stringify(term)}`]
|
|
61
|
+
for (const u of users.slice(0, 10)) lines.push(` ${displayNameOf(u) || '(unnamed)'}${u.email ? ` ${u.email}` : ''}`)
|
|
62
|
+
if (users.length > 10) lines.push(` … and ${users.length - 10} more`)
|
|
63
|
+
lines.push(' narrow it — an email address matches exactly one person.')
|
|
64
|
+
return { code: 1, lines }
|
|
65
|
+
}
|
|
66
|
+
return { assignee: { id: users[0].id, name: displayNameOf(users[0]) || users[0].id } }
|
|
67
|
+
}
|
|
68
|
+
return { assignee: null }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = { resolveListAssignee }
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared pieces of `spec-sync list`: what `--state` means, and how a row's
|
|
5
|
+
* board state and its spec's own status are put side by side.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { remoteStateReading, stateNamesFor, LIFECYCLE_BUCKETS } = require('../../sync-core')
|
|
9
|
+
|
|
10
|
+
// `--state` takes a lifecycle bucket as well as a tracker state. A bucket
|
|
11
|
+
// expands to every tracker name it has (`stateNamesFor`, aliases included); any
|
|
12
|
+
// other value is a tracker state, matched as it always was.
|
|
13
|
+
function expandStateArgs(args, config) {
|
|
14
|
+
return (args || []).flatMap((arg) => (LIFECYCLE_BUCKETS.includes(arg) ? stateNamesFor(arg, config) : [arg]))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// The spec's status beside the board's, and whether they disagree. A board
|
|
18
|
+
// state that maps to no bucket never disagrees: it is somewhere push does not
|
|
19
|
+
// manage, which is not a claim about the spec. Nor does a row whose spec is not
|
|
20
|
+
// on this machine — there is nothing to disagree WITH.
|
|
21
|
+
function specColumn(stateName, spec, config) {
|
|
22
|
+
const specStatus = spec ? spec.bucket : null
|
|
23
|
+
const seen = stateName == null ? null : remoteStateReading({ state: { name: stateName } }, config)
|
|
24
|
+
const disagrees = Boolean(specStatus && seen && seen.mapped && seen.bucket !== specStatus)
|
|
25
|
+
return { specStatus, disagrees }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// The cell itself: `in-progress`, `≠ backlog` when it disagrees, `—` when the
|
|
29
|
+
// spec is not here.
|
|
30
|
+
function specCell({ specStatus, disagrees }) {
|
|
31
|
+
if (!specStatus) return '—'
|
|
32
|
+
return disagrees ? `≠ ${specStatus}` : specStatus
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = { expandStateArgs, specColumn, specCell }
|