@spec-wave/cli 1.3.0 → 1.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/package.json +1 -1
- package/protocol/scm.v1.json +154 -0
- package/protocol/tracker.v1.json +175 -0
- package/src/api/github-rest.mjs +109 -0
- package/src/commands/audit.mjs +3 -4
- package/src/commands/code-review.mjs +11 -6
- package/src/commands/decompose.mjs +29 -9
- package/src/commands/doctor.mjs +389 -220
- package/src/commands/generate-bug.mjs +17 -7
- package/src/commands/generate-plan.mjs +21 -13
- package/src/commands/generate-qa-plan.mjs +19 -11
- package/src/commands/generate-spec.mjs +19 -6
- package/src/commands/implement.mjs +105 -49
- package/src/commands/init.mjs +36 -6
- package/src/commands/issue.mjs +6 -2
- package/src/commands/merge.mjs +31 -18
- package/src/commands/mode.mjs +18 -10
- package/src/commands/move.mjs +3 -3
- package/src/commands/order.mjs +30 -20
- package/src/commands/preflight.mjs +10 -5
- package/src/commands/qa-lead.mjs +41 -31
- package/src/commands/qa-run.mjs +83 -55
- package/src/commands/qa.mjs +10 -6
- package/src/commands/refresh.mjs +6 -3
- package/src/commands/repair-stage.mjs +1 -1
- package/src/commands/repo.mjs +7 -7
- package/src/commands/run.mjs +7 -4
- package/src/commands/story.mjs +3 -3
- package/src/commands/task.mjs +3 -3
- package/src/commands/triage.mjs +3 -3
- package/src/commands/uninstall.mjs +14 -5
- package/src/commands/update.mjs +47 -19
- package/src/commands/validate.mjs +3 -4
- package/src/commands/workspace.mjs +2 -2
- package/src/lib/artifact-publish.mjs +4 -3
- package/src/lib/board.mjs +22 -24
- package/src/lib/config-ports.mjs +114 -0
- package/src/lib/critique.mjs +11 -1
- package/src/lib/doc-source.mjs +16 -2
- package/src/lib/doctor-capabilities.mjs +168 -0
- package/src/lib/implement-board.mjs +6 -1
- package/src/lib/implement-stream.mjs +87 -0
- package/src/lib/pr-ready.mjs +24 -11
- package/src/lib/story-graph.mjs +26 -6
- package/src/lib/tag-registry.mjs +58 -0
- package/src/lib/usage-report.mjs +15 -2
- package/src/plugin/.claude-plugin/plugin.json +1 -1
- package/src/plugins/load.mjs +427 -0
- package/src/plugins/scm-github/index.mjs +71 -2
- package/src/plugins/tracker-github-projects/index.mjs +52 -10
- package/src/ports/capabilities.mjs +47 -0
- package/src/ports/index.mjs +347 -0
- package/src/ports/scm.mjs +39 -2
- package/src/ports/tracker.mjs +94 -3
- package/src/ports/types.mjs +59 -6
- package/src/setup/files.mjs +2 -2
- package/src/setup/labels.mjs +2 -2
- package/src/setup/project.mjs +2 -2
- package/src/ui/wizard.mjs +76 -1
package/src/commands/merge.mjs
CHANGED
|
@@ -20,8 +20,7 @@ import * as p from '@clack/prompts';
|
|
|
20
20
|
import chalk from 'chalk';
|
|
21
21
|
|
|
22
22
|
import { resolveToken } from '../api/auth.mjs';
|
|
23
|
-
import {
|
|
24
|
-
import { createGithubScm, githubLink } from '../plugins/scm-github/index.mjs';
|
|
23
|
+
import { requireScm, requireTracker, resolveScmLink } from '../ports/index.mjs';
|
|
25
24
|
import { missingTrailers } from '../lib/commit-trailers.mjs';
|
|
26
25
|
import { detectIssueType } from '../lib/issue-type.mjs';
|
|
27
26
|
import { orderStories } from '../lib/dependencies.mjs';
|
|
@@ -242,19 +241,30 @@ function comoPrLegado(pr) {
|
|
|
242
241
|
|
|
243
242
|
function criarScmDe(token, hub) {
|
|
244
243
|
const cache = new Map();
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
// ASSÍNCRONA desde a leva 4 do bloco E. O memo continua guardando a PORTA e não
|
|
245
|
+
// a promessa, porque o `await` fica DENTRO dele: guardar a promessa faria cada
|
|
246
|
+
// chamada esperar de novo e perderia o ponto do cache, que é não reconstruir a
|
|
247
|
+
// porta por repositório num comando que percorre a pilha inteira.
|
|
248
|
+
return async (r) => {
|
|
249
|
+
const link = resolveScmLink({
|
|
247
250
|
owner: r.owner, repo: r.repo,
|
|
248
251
|
role: r.owner === hub.owner && r.repo === hub.repo ? 'hub' : 'code',
|
|
249
252
|
});
|
|
250
|
-
if (!cache.has(link.id)) cache.set(link.id,
|
|
253
|
+
if (!cache.has(link.id)) cache.set(link.id, await requireScm({ link, token }));
|
|
251
254
|
return cache.get(link.id);
|
|
252
255
|
};
|
|
253
256
|
}
|
|
254
257
|
|
|
258
|
+
/**
|
|
259
|
+
* @param {object} [params]
|
|
260
|
+
* @param {object} [params.deps] seam de teste — `tracker` e `scmDe`. Em
|
|
261
|
+
* multi-repo o `scmDe` é uma FÁBRICA por repositório, não uma porta só: o
|
|
262
|
+
* comando fala com N repos de código mais o hub, e uma porta única esconderia
|
|
263
|
+
* exatamente o defeito que importa aqui — PR aberto no repositório errado.
|
|
264
|
+
*/
|
|
255
265
|
export async function merge({
|
|
256
266
|
feature: featureArg, yes = false, dryRun = false, keepBranches = false,
|
|
257
|
-
remote = false, refresh = false,
|
|
267
|
+
remote = false, refresh = false, deps = {},
|
|
258
268
|
} = {}) {
|
|
259
269
|
const { config: fileConfig, root: repoRoot } = loadConfig();
|
|
260
270
|
const ttlSec = resolveCacheTtl(fileConfig);
|
|
@@ -294,15 +304,18 @@ export async function merge({
|
|
|
294
304
|
const s = p.spinner();
|
|
295
305
|
s.start('Montando o plano de merge...');
|
|
296
306
|
|
|
297
|
-
const scmDe = criarScmDe(token, { owner, repo });
|
|
298
|
-
|
|
307
|
+
const scmDe = deps.scmDe ?? criarScmDe(token, { owner, repo });
|
|
308
|
+
// `await`: a fábrica virou assíncrona. Sem ele `hubScm` é Promise e todo
|
|
309
|
+
// método dela é `undefined` — o mesmo defeito que a leva 3 achou no
|
|
310
|
+
// `pr-ready`, onde o `.catch` do call site NÃO pega o TypeError sincrônico.
|
|
311
|
+
const hubScm = await scmDe({ owner, repo });
|
|
299
312
|
|
|
300
313
|
let featureIssue;
|
|
301
314
|
let defaultBranch;
|
|
302
315
|
try {
|
|
303
|
-
featureIssue = await
|
|
316
|
+
featureIssue = await (await requireTracker({ token, owner, repo, deps }))
|
|
304
317
|
.getWorkItem({ ref: { key: String(featureNumber) } });
|
|
305
|
-
defaultBranch = await scmDe({ owner, repo }).defaultBranch();
|
|
318
|
+
defaultBranch = await (await scmDe({ owner, repo })).defaultBranch();
|
|
306
319
|
} catch (err) {
|
|
307
320
|
s.stop('');
|
|
308
321
|
p.log.error(`Não foi possível ler ${owner}/${repo}#${featureNumber}: ${err.message}`);
|
|
@@ -327,7 +340,7 @@ export async function merge({
|
|
|
327
340
|
let carga;
|
|
328
341
|
try {
|
|
329
342
|
carga = await loadFeatureStories({
|
|
330
|
-
token, owner, repo, root: repoRoot,
|
|
343
|
+
token, owner, repo, root: repoRoot, tracker: deps.tracker,
|
|
331
344
|
// `ref.id`: sem ele, `loadFeatureStories` chama listChildren sem node id
|
|
332
345
|
// e o plugin paga um getIssue a mais para reidratar o que já estava aqui.
|
|
333
346
|
feature: { number: featureNumber, nodeId: featureIssue.ref?.id, title: featureIssue.title },
|
|
@@ -372,7 +385,7 @@ export async function merge({
|
|
|
372
385
|
const repos = [hub, ...codeRepos.map(r => ({ owner: r.owner, repo: r.repo, slug: r.slug }))];
|
|
373
386
|
const defaultBranches = new Map();
|
|
374
387
|
for (const r of codeRepos) {
|
|
375
|
-
const branch = await scmDe(r).defaultBranch().catch(() => null);
|
|
388
|
+
const branch = await (await scmDe(r)).defaultBranch().catch(() => null);
|
|
376
389
|
if (branch) defaultBranches.set(repoKey(r), branch);
|
|
377
390
|
else p.log.warn(`Não consegui ler a branch default de ${r.owner}/${r.repo} — assumindo "${defaultBranch}".`);
|
|
378
391
|
}
|
|
@@ -404,7 +417,7 @@ export async function merge({
|
|
|
404
417
|
if (codeRepos.length > 0 || sorted.some(story => (prsByStory.get(story) || []).length === 0)) {
|
|
405
418
|
const abertos = [];
|
|
406
419
|
for (const r of repos) {
|
|
407
|
-
const lista = (await scmDe(r).listOpenPullRequests().catch(() => [])).map(comoPrLegado);
|
|
420
|
+
const lista = (await (await scmDe(r)).listOpenPullRequests().catch(() => [])).map(comoPrLegado);
|
|
408
421
|
abertos.push(...lista.map(pr => ({ ...pr, repo: { owner: r.owner, repo: r.repo } })));
|
|
409
422
|
}
|
|
410
423
|
const linkMode = resolveLinkMode(fileConfig);
|
|
@@ -441,7 +454,7 @@ export async function merge({
|
|
|
441
454
|
// chamada extra por PR; falha de rede não afirma nada, só é pulada.
|
|
442
455
|
for (const { story, pr } of plano.fila) {
|
|
443
456
|
const r = prRepoOf(pr, hub);
|
|
444
|
-
const messages = await scmDe(r).listPullRequestCommitMessages({ number: String(pr.number) }).catch(() => null);
|
|
457
|
+
const messages = await (await scmDe(r)).listPullRequestCommitMessages({ number: String(pr.number) }).catch(() => null);
|
|
445
458
|
if (messages === null) continue;
|
|
446
459
|
const { missingStories } = missingTrailers(messages, { stories: [story] });
|
|
447
460
|
if (missingStories.length > 0) {
|
|
@@ -477,19 +490,19 @@ export async function merge({
|
|
|
477
490
|
const ref = prRef(pr, hub);
|
|
478
491
|
const prRepoOpt = sameRepo(r, hub) ? undefined : `${r.owner}/${r.repo}`;
|
|
479
492
|
// Estado fresco: a fila pode ter envelhecido entre o plano e este ponto.
|
|
480
|
-
const atual = await scmDe(r).getPullRequest({ number: String(pr.number) });
|
|
493
|
+
const atual = await (await scmDe(r)).getPullRequest({ number: String(pr.number) });
|
|
481
494
|
if (atual.state === 'merged') {
|
|
482
495
|
p.log.info(`PR ${ref} já estava mergeado — seguindo.`);
|
|
483
496
|
continue;
|
|
484
497
|
}
|
|
485
498
|
if (atual.baseRef !== def) {
|
|
486
499
|
p.log.step(`PR ${ref}: base ${atual.baseRef} → ${def}`);
|
|
487
|
-
await scmDe(r).setPullRequestBase({ number: String(pr.number), base: def });
|
|
500
|
+
await (await scmDe(r)).setPullRequestBase({ number: String(pr.number), base: def });
|
|
488
501
|
}
|
|
489
502
|
try {
|
|
490
503
|
// `merge` e não squash: squash reescreveria o merge-base dos
|
|
491
504
|
// dependentes e o retarget deixaria de ser limpo.
|
|
492
|
-
await scmDe(r).mergePullRequest({ number: String(pr.number), strategy: 'merge' });
|
|
505
|
+
await (await scmDe(r)).mergePullRequest({ number: String(pr.number), strategy: 'merge' });
|
|
493
506
|
} catch (err) {
|
|
494
507
|
// 405 = draft/check pendente/conflito. Parar AQUI preserva a ordem: os
|
|
495
508
|
// dependentes continuam com branch e PR intactos, e rodar de novo retoma.
|
|
@@ -520,7 +533,7 @@ export async function merge({
|
|
|
520
533
|
if (!keepBranches) {
|
|
521
534
|
for (const { repo: r, head } of mergedHeads) {
|
|
522
535
|
if (!head) continue;
|
|
523
|
-
await scmDe(r).deleteBranch({ branch: head }).catch(err =>
|
|
536
|
+
await (await scmDe(r)).deleteBranch({ branch: head }).catch(err =>
|
|
524
537
|
p.log.warn(`Branch ${head} (${r.owner}/${r.repo}) não apagada: ${err.message}`));
|
|
525
538
|
}
|
|
526
539
|
}
|
package/src/commands/mode.mjs
CHANGED
|
@@ -16,11 +16,14 @@ import * as p from '@clack/prompts';
|
|
|
16
16
|
import chalk from 'chalk';
|
|
17
17
|
|
|
18
18
|
import { resolveToken } from '../api/auth.mjs';
|
|
19
|
-
import {
|
|
19
|
+
import { requireScm, resolveScmLink } from '../ports/index.mjs';
|
|
20
20
|
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Porta de SCM do repositório corrente — só a variável de execução sai daqui.
|
|
23
|
+
* ASSÍNCRONA desde a leva 5 do bloco E.
|
|
24
|
+
*/
|
|
25
|
+
const scmDe = (token, owner, repo, deps = {}) =>
|
|
26
|
+
requireScm({ link: resolveScmLink({ owner, repo }), token, deps });
|
|
24
27
|
import { CONFIG_FILE, WORKFLOW_FILES } from '../config.mjs';
|
|
25
28
|
import { updateConfig } from '../lib/config-file.mjs';
|
|
26
29
|
import {
|
|
@@ -47,16 +50,21 @@ export function unguardedWorkflows(root) {
|
|
|
47
50
|
|
|
48
51
|
// A variável só é legível por quem administra o repo. 403 não é falha: é "não
|
|
49
52
|
// verificável", e quem chama distingue isso de "não existe" (null).
|
|
50
|
-
async function readVariable(token, owner, repo) {
|
|
53
|
+
async function readVariable(token, owner, repo, deps = {}) {
|
|
51
54
|
try {
|
|
52
|
-
|
|
55
|
+
// `await` DUAS vezes, e o de dentro não é enfeite: sem ele a promessa de
|
|
56
|
+
// `getVariable` sai deste `try` sem ser esperada, e a rejeição escapa o
|
|
57
|
+
// `catch` que trata o 403 — o caso que o comentário acima descreve. Foi o que
|
|
58
|
+
// minha primeira conversão para porta assíncrona fez, e o que ninguém pegaria:
|
|
59
|
+
// `mode` não tinha teste de caminho.
|
|
60
|
+
return await (await scmDe(token, owner, repo, deps)).getVariable({ name: EXECUTION_VARIABLE });
|
|
53
61
|
} catch (err) {
|
|
54
62
|
if (err.status === 403 || err.status === 404) return undefined;
|
|
55
63
|
throw err;
|
|
56
64
|
}
|
|
57
65
|
}
|
|
58
66
|
|
|
59
|
-
export async function mode({ target, dryRun = false } = {}) {
|
|
67
|
+
export async function mode({ target, dryRun = false, deps = {} } = {}) {
|
|
60
68
|
p.intro(chalk.bold('spec-wave mode'));
|
|
61
69
|
|
|
62
70
|
const { config, root, configPath } = loadConfig();
|
|
@@ -80,7 +88,7 @@ export async function mode({ target, dryRun = false } = {}) {
|
|
|
80
88
|
if (owner && repo) {
|
|
81
89
|
try {
|
|
82
90
|
token = await resolveToken();
|
|
83
|
-
variavel = await readVariable(token, owner, repo);
|
|
91
|
+
variavel = await readVariable(token, owner, repo, deps);
|
|
84
92
|
} catch (err) {
|
|
85
93
|
p.log.warn(`Não foi possível consultar a variável do repositório: ${err.message}`);
|
|
86
94
|
variavel = undefined;
|
|
@@ -146,12 +154,12 @@ export async function mode({ target, dryRun = false } = {}) {
|
|
|
146
154
|
if (token && owner && repo) {
|
|
147
155
|
try {
|
|
148
156
|
if (esperado === null) {
|
|
149
|
-
const removida = await scmDe(token, owner, repo).deleteVariable({ name: EXECUTION_VARIABLE });
|
|
157
|
+
const removida = await (await scmDe(token, owner, repo, deps)).deleteVariable({ name: EXECUTION_VARIABLE });
|
|
150
158
|
p.log.success(removida
|
|
151
159
|
? `Variável ${EXECUTION_VARIABLE} removida — os workflows voltam a disparar.`
|
|
152
160
|
: `Variável ${EXECUTION_VARIABLE} já não existia.`);
|
|
153
161
|
} else {
|
|
154
|
-
await scmDe(token, owner, repo).setVariable({ name: EXECUTION_VARIABLE, value: esperado });
|
|
162
|
+
await (await scmDe(token, owner, repo, deps)).setVariable({ name: EXECUTION_VARIABLE, value: esperado });
|
|
155
163
|
p.log.success(`Variável ${EXECUTION_VARIABLE}=${esperado} — os jobs passam a ser pulados (0 minutos).`);
|
|
156
164
|
}
|
|
157
165
|
} catch (err) {
|
package/src/commands/move.mjs
CHANGED
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
import * as p from '@clack/prompts';
|
|
14
14
|
import chalk from 'chalk';
|
|
15
15
|
import { resolveToken } from '../api/auth.mjs';
|
|
16
|
-
import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
|
|
17
16
|
import { detectIssueType } from '../lib/issue-type.mjs';
|
|
18
17
|
import { openTracker, advanceToStage, resolveStageName } from '../lib/board.mjs';
|
|
19
18
|
import { resolveHubContext } from '../lib/project-root.mjs';
|
|
19
|
+
import { requireTracker } from '../ports/index.mjs';
|
|
20
20
|
import {
|
|
21
21
|
CONFIG_FILE, PROGRESS_TODO, PROGRESS_IN_PROGRESS, PROGRESS_DONE,
|
|
22
22
|
isManualStageType, MANUAL_STAGE_TYPES, isStageInTrack, STAGE_TRACKS,
|
|
@@ -141,7 +141,7 @@ export async function move({ issue: issueArg, stage: stageArg, status: statusArg
|
|
|
141
141
|
|
|
142
142
|
let issue;
|
|
143
143
|
try {
|
|
144
|
-
issue = await (
|
|
144
|
+
issue = await (await requireTracker({ token, owner, repo, deps }))
|
|
145
145
|
.getWorkItem({ ref: { key: String(issueNumber) } });
|
|
146
146
|
} catch (err) {
|
|
147
147
|
p.log.error(`Não foi possível ler a issue #${issueNumber}: ${err.message}`);
|
|
@@ -178,7 +178,7 @@ export async function move({ issue: issueArg, stage: stageArg, status: statusArg
|
|
|
178
178
|
p.log.warn(`#${issueNumber} ${aviso}`);
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
const { tracker, error: projectError } = openTracker({ token, owner, repo, cwd: root || process.cwd(), tracker: deps.tracker });
|
|
181
|
+
const { tracker, error: projectError } = await openTracker({ token, owner, repo, cwd: root || process.cwd(), tracker: deps.tracker });
|
|
182
182
|
if (projectError) {
|
|
183
183
|
p.log.error(`${projectError} — board não atualizado. Rode \`spec-wave init\` (ou \`spec-wave refresh --config\`).`);
|
|
184
184
|
process.exitCode = 1;
|
package/src/commands/order.mjs
CHANGED
|
@@ -24,7 +24,6 @@ import path from 'node:path';
|
|
|
24
24
|
import * as p from '@clack/prompts';
|
|
25
25
|
import chalk from 'chalk';
|
|
26
26
|
import { resolveToken } from '../api/auth.mjs';
|
|
27
|
-
import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
|
|
28
27
|
import { detectIssueType } from '../lib/issue-type.mjs';
|
|
29
28
|
import { parseDependencies, orderStories } from '../lib/dependencies.mjs';
|
|
30
29
|
import { loadProjectConfig, selectOpenFeatures } from '../lib/board.mjs';
|
|
@@ -39,6 +38,7 @@ import { loadFeatureStories, loadBoardSnapshot, externalIssueInfo } from '../lib
|
|
|
39
38
|
import { resolveCacheTtl } from '../lib/net-cache.mjs';
|
|
40
39
|
import { pushWithRebase } from '../lib/git-retry.mjs';
|
|
41
40
|
import { CONFIG_FILE, STAGE_ORDER, STAGE_DEVELOPMENT, STAGE_DONE } from '../config.mjs';
|
|
41
|
+
import { requireTracker } from '../ports/index.mjs';
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Rótulo curto de uma Feature para a coluna do mapa (função PURA).
|
|
@@ -129,7 +129,7 @@ function edgesNote(origins, { remote }) {
|
|
|
129
129
|
* artefatos locais — ver o cabeçalho.) Uma query paginada de itens do project
|
|
130
130
|
* resolve Etapa e tipo de todo mundo de uma vez.
|
|
131
131
|
*/
|
|
132
|
-
async function orderBoard({ token, owner, repo, root, ttlSec, opts }) {
|
|
132
|
+
async function orderBoard({ token, owner, repo, root, ttlSec, opts, deps = {} }) {
|
|
133
133
|
const { project, error: projectError } = loadProjectConfig();
|
|
134
134
|
if (projectError) {
|
|
135
135
|
emitError(opts,
|
|
@@ -142,7 +142,7 @@ async function orderBoard({ token, owner, repo, root, ttlSec, opts }) {
|
|
|
142
142
|
|
|
143
143
|
let snapshot;
|
|
144
144
|
try {
|
|
145
|
-
snapshot = await loadBoardSnapshot({ token, owner, repo, project, root, refresh: opts.refresh, ttlSec });
|
|
145
|
+
snapshot = await loadBoardSnapshot({ token, owner, repo, project, root, refresh: opts.refresh, ttlSec, tracker: deps.tracker });
|
|
146
146
|
} catch (err) {
|
|
147
147
|
emitError(opts, `Não foi possível ler os itens do Project: ${err.message}`);
|
|
148
148
|
process.exitCode = 1;
|
|
@@ -173,7 +173,7 @@ async function orderBoard({ token, owner, repo, root, ttlSec, opts }) {
|
|
|
173
173
|
let carga;
|
|
174
174
|
try {
|
|
175
175
|
carga = await loadFeatureStories({
|
|
176
|
-
token, owner, repo, root, feature,
|
|
176
|
+
token, owner, repo, root, feature, tracker: deps.tracker,
|
|
177
177
|
remote: opts.remote, refresh: opts.refresh, ttlSec,
|
|
178
178
|
});
|
|
179
179
|
} catch (err) {
|
|
@@ -265,9 +265,19 @@ function emitInfo(opts, message) {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
/**
|
|
269
|
+
* @param {object} [params]
|
|
270
|
+
* @param {object} [params.deps] seam de teste — `tracker`, `exec` (o runner de
|
|
271
|
+
* comando, em lugar de `execSync`) e `push` (em lugar de `pushWithRebase`).
|
|
272
|
+
*
|
|
273
|
+
* A costura de GIT é o que distingue esta leva: `exec` recebe a linha de
|
|
274
|
+
* comando, então o teste pode afirmar QUAIS comandos de git rodaram — e é
|
|
275
|
+
* exatamente isso que importa aqui, porque o commit é escopado a caminhos
|
|
276
|
+
* específicos (`git commit -- <path>`) para não varrer trabalho alheio.
|
|
277
|
+
*/
|
|
268
278
|
export async function order({
|
|
269
279
|
feature: featureArg, json = false, milestone = null, remote = false,
|
|
270
|
-
refresh = false, sync = false,
|
|
280
|
+
refresh = false, sync = false, deps = {},
|
|
271
281
|
} = {}) {
|
|
272
282
|
const semArgumento = featureArg === undefined || featureArg === null
|
|
273
283
|
|| String(featureArg).trim() === '';
|
|
@@ -308,14 +318,14 @@ export async function order({
|
|
|
308
318
|
}
|
|
309
319
|
if (!json) p.intro(chalk.bold('spec-wave order --sync — dependências da API de volta ao doc'));
|
|
310
320
|
return await syncDependencies({
|
|
311
|
-
token, owner, repo, root, opts,
|
|
321
|
+
token, owner, repo, root, opts, deps,
|
|
312
322
|
featureNumber: semArgumento ? null : featureNumber,
|
|
313
323
|
});
|
|
314
324
|
}
|
|
315
325
|
|
|
316
326
|
if (semArgumento) {
|
|
317
327
|
if (!json) p.intro(chalk.bold('spec-wave order — todas as Features com trabalho'));
|
|
318
|
-
return await orderBoard({ token, owner, repo, root, ttlSec, opts });
|
|
328
|
+
return await orderBoard({ token, owner, repo, root, ttlSec, opts, deps });
|
|
319
329
|
}
|
|
320
330
|
|
|
321
331
|
if (!json) p.intro(chalk.bold(`spec-wave order #${featureNumber}`));
|
|
@@ -323,7 +333,7 @@ export async function order({
|
|
|
323
333
|
// 1. Lê a Feature e valida o tipo (1 chamada — a issue-alvo nunca vem de cache).
|
|
324
334
|
let featureIssue;
|
|
325
335
|
try {
|
|
326
|
-
featureIssue = await
|
|
336
|
+
featureIssue = await (await requireTracker({ token, owner, repo, deps }))
|
|
327
337
|
.getWorkItem({ ref: { key: String(featureNumber) } });
|
|
328
338
|
} catch (err) {
|
|
329
339
|
emitError(opts, `Não foi possível ler a issue #${featureNumber}: ${err.message}`);
|
|
@@ -344,7 +354,7 @@ export async function order({
|
|
|
344
354
|
let carga;
|
|
345
355
|
try {
|
|
346
356
|
carga = await loadFeatureStories({
|
|
347
|
-
token, owner, repo, root,
|
|
357
|
+
token, owner, repo, root, tracker: deps.tracker,
|
|
348
358
|
feature: { number: featureNumber, nodeId: featureIssue.ref.id, title: featureIssue.title },
|
|
349
359
|
remote, refresh, ttlSec,
|
|
350
360
|
});
|
|
@@ -372,7 +382,7 @@ export async function order({
|
|
|
372
382
|
if (!json) p.log.warn(`${projectError} — Etapas do board não consultadas.`);
|
|
373
383
|
} else {
|
|
374
384
|
try {
|
|
375
|
-
const snapshot = await loadBoardSnapshot({ token, owner, repo, project, root, refresh, ttlSec });
|
|
385
|
+
const snapshot = await loadBoardSnapshot({ token, owner, repo, project, root, refresh, ttlSec, tracker: deps.tracker });
|
|
376
386
|
for (const s of enriched) stageOf.set(s.number, snapshot.index.get(s.number)?.fields?.Etapa ?? null);
|
|
377
387
|
boardMeta = {
|
|
378
388
|
stages: snapshot.fromCache ? 'cache' : 'board',
|
|
@@ -503,12 +513,12 @@ export async function order({
|
|
|
503
513
|
// Commit LOCAL escopado aos artefatos reescritos + push com retry — mesmo
|
|
504
514
|
// padrão do bug.md do qa (git-retry). Falha de push degrada para aviso: os
|
|
505
515
|
// arquivos já estão certos no disco.
|
|
506
|
-
function commitSyncedFiles(root, filesRel, featureNumber) {
|
|
516
|
+
function commitSyncedFiles(root, filesRel, featureNumber, exec = execSync) {
|
|
507
517
|
try {
|
|
508
518
|
for (const rel of filesRel) {
|
|
509
|
-
|
|
519
|
+
exec(`git add -- ${JSON.stringify(rel)}`, { cwd: root, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
510
520
|
}
|
|
511
|
-
|
|
521
|
+
exec(
|
|
512
522
|
`git commit -m ${JSON.stringify(`docs: sync de dependências da Feature #${featureNumber} [spec-wave]`)} ` +
|
|
513
523
|
filesRel.map(r => `-- ${JSON.stringify(r)}`).join(' '),
|
|
514
524
|
{ cwd: root, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
@@ -519,8 +529,8 @@ function commitSyncedFiles(root, filesRel, featureNumber) {
|
|
|
519
529
|
}
|
|
520
530
|
}
|
|
521
531
|
|
|
522
|
-
async function syncDependencies({ token, owner, repo, root, opts, featureNumber }) {
|
|
523
|
-
const tracker =
|
|
532
|
+
async function syncDependencies({ token, owner, repo, root, opts, featureNumber, deps = {} }) {
|
|
533
|
+
const tracker = await requireTracker({ token, owner, repo, deps });
|
|
524
534
|
// Alvos: a Feature pedida, ou as Features abertas do board (--milestone filtra).
|
|
525
535
|
let targets = [];
|
|
526
536
|
if (featureNumber) {
|
|
@@ -545,7 +555,7 @@ async function syncDependencies({ token, owner, repo, root, opts, featureNumber
|
|
|
545
555
|
return;
|
|
546
556
|
}
|
|
547
557
|
// Sync é reconciliação: sempre parte de um snapshot FRESCO.
|
|
548
|
-
const snapshot = await loadBoardSnapshot({ token, owner, repo, project, root, refresh: true });
|
|
558
|
+
const snapshot = await loadBoardSnapshot({ token, owner, repo, project, root, refresh: true, tracker: deps.tracker });
|
|
549
559
|
let features = selectOpenFeatures(snapshot.items);
|
|
550
560
|
if (opts.milestone) features = filterItemsByMilestone(features, opts.milestone);
|
|
551
561
|
targets = features;
|
|
@@ -554,14 +564,14 @@ async function syncDependencies({ token, owner, repo, root, opts, featureNumber
|
|
|
554
564
|
let synced = 0;
|
|
555
565
|
let untouched = 0;
|
|
556
566
|
for (const feature of targets) {
|
|
557
|
-
const resultado = await syncOneFeature({ token, owner, repo, tracker, root, feature });
|
|
567
|
+
const resultado = await syncOneFeature({ token, owner, repo, tracker, root, feature, deps });
|
|
558
568
|
if (resultado === 'synced') synced += 1;
|
|
559
569
|
else if (resultado === 'unchanged') untouched += 1;
|
|
560
570
|
}
|
|
561
571
|
p.outro(`${chalk.green('✓')} sync: ${synced} Feature(s) atualizada(s), ${untouched} já em dia.`);
|
|
562
572
|
}
|
|
563
573
|
|
|
564
|
-
async function syncOneFeature({ token, owner, repo, tracker, root, feature }) {
|
|
574
|
+
async function syncOneFeature({ token, owner, repo, tracker, root, feature, deps = {} }) {
|
|
565
575
|
let paths;
|
|
566
576
|
try {
|
|
567
577
|
paths = featureDocPaths(root, { title: feature.title }, 'Feature');
|
|
@@ -649,9 +659,9 @@ async function syncOneFeature({ token, owner, repo, tracker, root, feature }) {
|
|
|
649
659
|
escritos.push(mapRel);
|
|
650
660
|
}
|
|
651
661
|
|
|
652
|
-
const committed = commitSyncedFiles(root, escritos, feature.number);
|
|
662
|
+
const committed = commitSyncedFiles(root, escritos, feature.number, deps.exec ?? execSync);
|
|
653
663
|
if (committed) {
|
|
654
|
-
const push = await pushWithRebase({ cwd: root });
|
|
664
|
+
const push = await (deps.push ?? pushWithRebase)({ cwd: root });
|
|
655
665
|
if (!push.ok) {
|
|
656
666
|
p.log.warn(`⚠️ Sync commitado, mas o push falhou: ${String(push.error).split('\n')[0]} — pushe manualmente.`);
|
|
657
667
|
}
|
|
@@ -20,8 +20,7 @@ import * as p from '@clack/prompts';
|
|
|
20
20
|
import chalk from 'chalk';
|
|
21
21
|
|
|
22
22
|
import { resolveToken } from '../api/auth.mjs';
|
|
23
|
-
import {
|
|
24
|
-
import { createGithubScm, githubLink } from '../plugins/scm-github/index.mjs';
|
|
23
|
+
import { requireScm, requireTracker, resolveScmLink } from '../ports/index.mjs';
|
|
25
24
|
import { CONFIG_FILE } from '../config.mjs';
|
|
26
25
|
import { inspectPrPublishing, readPrPublishingContext } from './doctor.mjs';
|
|
27
26
|
import { configuredMode, describeModeState, EXECUTION_VARIABLE } from '../lib/execution-mode.mjs';
|
|
@@ -198,8 +197,8 @@ export async function preflight({ milestone: milestoneArg, json = false, deps =
|
|
|
198
197
|
return falhar(`Sem token utilizável para ${owner}/${repo}: ${err.message}`);
|
|
199
198
|
}
|
|
200
199
|
|
|
201
|
-
const tracker =
|
|
202
|
-
const scm =
|
|
200
|
+
const tracker = await requireTracker({ token, owner, repo, deps });
|
|
201
|
+
const scm = await requireScm({ link: resolveScmLink({ owner, repo }), token, deps });
|
|
203
202
|
|
|
204
203
|
const s = json ? null : p.spinner();
|
|
205
204
|
s?.start('Consultando o repositório...');
|
|
@@ -226,8 +225,14 @@ export async function preflight({ milestone: milestoneArg, json = false, deps =
|
|
|
226
225
|
});
|
|
227
226
|
|
|
228
227
|
// --- Publicação por Pull Request: é o desfecho de toda geração.
|
|
228
|
+
// `deep: true` traz os fatos de automação (secrets, permissão de workflow,
|
|
229
|
+
// proteção de branch) que `inspectPrPublishing` julga. `null` quando a
|
|
230
|
+
// verificação falha: os três viram "não consegui olhar", nunca "está errado".
|
|
229
231
|
const publicacao = inspectPrPublishing(
|
|
230
|
-
|
|
232
|
+
readPrPublishingContext({
|
|
233
|
+
verificacao: await scm.verify({ deep: true }).catch(() => null),
|
|
234
|
+
root,
|
|
235
|
+
})
|
|
231
236
|
);
|
|
232
237
|
|
|
233
238
|
// --- Inventário da milestone.
|