@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,94 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Flatten markdown tables that sit INSIDE a list item, because both tracker
|
|
5
|
+
* dialects need it: Linear's renderer corrupts nested-table data cells
|
|
6
|
+
* (measured on probe SKI-28, 2026-08-28 — every data cell loses its first N
|
|
7
|
+
* characters, N being the rendered list indent; the auth header
|
|
8
|
+
* `X-Extraction-Key` was stored as `Extraction-Key`), and ADF's `listItem`
|
|
9
|
+
* cannot contain a `table` node at all, so a Jira render would drop or mangle
|
|
10
|
+
* it. The re-emitted shapes are ones proven to survive nesting unchanged:
|
|
11
|
+
*
|
|
12
|
+
* - 2 columns → a bullet list (`- a — b`), the key/value case
|
|
13
|
+
* - otherwise → a fenced code block wrapping the original rows verbatim
|
|
14
|
+
*
|
|
15
|
+
* This shapes the PROJECTION only. Repo files are never rewritten: the source
|
|
16
|
+
* markdown is valid and renders correctly in GitHub and every editor.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const { fenceMask } = require('../../sync-core/src/task-block.js')
|
|
20
|
+
|
|
21
|
+
// A table row: optional indent, then a `|`-delimited line. We only ever act on
|
|
22
|
+
// indented ones — a column-0 table (the `## Phases` index, every Impact map) is
|
|
23
|
+
// rendered correctly by Linear and must project byte-identically.
|
|
24
|
+
const ROW_RE = /^([ \t]+)\|(.*)\|[ \t]*$/
|
|
25
|
+
// The separator under the header — `|---|:--:|`. Its presence is what makes the
|
|
26
|
+
// block a table rather than prose that happens to contain pipes.
|
|
27
|
+
const SEPARATOR_RE = /^[ \t]+\|[\s:|-]+\|[ \t]*$/
|
|
28
|
+
|
|
29
|
+
// Split a row into cells on pipes that are OUTSIDE an inline-code span, so a
|
|
30
|
+
// documented `` `a | b` `` alternation stays one cell instead of splitting.
|
|
31
|
+
function splitCells(body) {
|
|
32
|
+
const cells = []
|
|
33
|
+
let cur = ''
|
|
34
|
+
let code = false
|
|
35
|
+
for (const ch of body) {
|
|
36
|
+
if (ch === '`') code = !code
|
|
37
|
+
if (ch === '|' && !code) {
|
|
38
|
+
cells.push(cur.trim())
|
|
39
|
+
cur = ''
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
cur += ch
|
|
43
|
+
}
|
|
44
|
+
cells.push(cur.trim())
|
|
45
|
+
return cells
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Rewrite every indented table in `md`. Returns the text unchanged when there is
|
|
50
|
+
* nothing nested to flatten.
|
|
51
|
+
* @param {string} md
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
function flattenNestedTables(md) {
|
|
55
|
+
if (md == null) return md
|
|
56
|
+
const lines = String(md).split('\n')
|
|
57
|
+
const inFence = fenceMask(lines)
|
|
58
|
+
const out = []
|
|
59
|
+
|
|
60
|
+
for (let i = 0; i < lines.length; i++) {
|
|
61
|
+
const header = ROW_RE.exec(lines[i])
|
|
62
|
+
// A table shown as an EXAMPLE inside a ``` block is documentation — often of
|
|
63
|
+
// this very bug — so it is left exactly as written.
|
|
64
|
+
if (!header || inFence[i] || !SEPARATOR_RE.test(lines[i + 1] || '')) {
|
|
65
|
+
out.push(lines[i])
|
|
66
|
+
continue
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const indent = header[1]
|
|
70
|
+
const rows = [splitCells(header[2])]
|
|
71
|
+
const raw = [lines[i], lines[i + 1]]
|
|
72
|
+
let j = i + 2
|
|
73
|
+
for (; j < lines.length && !inFence[j]; j++) {
|
|
74
|
+
const row = ROW_RE.exec(lines[j])
|
|
75
|
+
if (!row) break
|
|
76
|
+
rows.push(splitCells(row[2]))
|
|
77
|
+
raw.push(lines[j])
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (rows[0].length === 2) {
|
|
81
|
+
// Header first, bolded: dropping it would lose content and inventing a
|
|
82
|
+
// caption would invent it.
|
|
83
|
+
out.push(`${indent}- **${rows[0][0]}** — **${rows[0][1]}**`)
|
|
84
|
+
for (const r of rows.slice(1)) out.push(`${indent}- ${r[0]} — ${r[1]}`)
|
|
85
|
+
} else {
|
|
86
|
+
out.push(`${indent}\`\`\``, ...raw, `${indent}\`\`\``)
|
|
87
|
+
}
|
|
88
|
+
i = j - 1
|
|
89
|
+
}
|
|
90
|
+
return out.join('\n')
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
module.exports = { flattenNestedTables, splitCells }
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Terminal input helpers for a credentials CLI — reading a piped secret, and
|
|
5
|
+
* prompting for one with the echo off.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Read stdin to completion (for `--stdin`).
|
|
9
|
+
function readAllStdin(input) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
let data = ''
|
|
12
|
+
input.setEncoding('utf-8')
|
|
13
|
+
input.on('data', (chunk) => (data += chunk))
|
|
14
|
+
input.on('end', () => resolve(data))
|
|
15
|
+
input.on('error', reject)
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Prompt on a TTY with the input hidden. `_writeToOutput` is readline's own echo
|
|
20
|
+
// hook — filtering it is what keeps the key off the screen (and out of a
|
|
21
|
+
// screen-shared terminal or a recorded session).
|
|
22
|
+
//
|
|
23
|
+
// READLINE OWNS THE PROMPT, deliberately. Writing it ourselves and then starting
|
|
24
|
+
// the interface loses it: readline clears from the cursor to the end of the
|
|
25
|
+
// screen (`ESC[0J`) before its first redraw, so the prompt was wiped the instant
|
|
26
|
+
// it appeared and the user was left staring at a blank line while the process
|
|
27
|
+
// waited for a key — indistinguishable from a hang.
|
|
28
|
+
//
|
|
29
|
+
// The hook is assigned BEFORE `question`, so the very first redraw goes through
|
|
30
|
+
// it. readline hands it `prompt + what has been typed`; re-writing only the
|
|
31
|
+
// prompt is what keeps the key hidden while the prompt survives every redraw.
|
|
32
|
+
function promptHidden(question, input, out) {
|
|
33
|
+
const readline = require('node:readline')
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
// `out`, never `process.stdout`: they are the same stream in production, and
|
|
36
|
+
// hardcoding one half meant readline cleared a screen the prompt had not
|
|
37
|
+
// been written to under test — the split that hid this bug from the suite.
|
|
38
|
+
const rl = readline.createInterface({ input, output: out, terminal: true })
|
|
39
|
+
rl._writeToOutput = (s) => {
|
|
40
|
+
if (s.includes(question)) out.write(question)
|
|
41
|
+
}
|
|
42
|
+
rl.question(question, (answer) => {
|
|
43
|
+
out.write('\n')
|
|
44
|
+
rl.close()
|
|
45
|
+
resolve(answer)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = { readAllStdin, promptHidden }
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Which tickets a release contains.
|
|
5
|
+
*
|
|
6
|
+
* The repo lands specs with `merge --ff-only`, so history is linear and branch
|
|
7
|
+
* names never reach it. A commit's `Refs:` trailer is therefore the only place
|
|
8
|
+
* the ticket survives into the range a release scans — see the
|
|
9
|
+
* `commit-trailers` rule. Nothing here is tracker-specific: the identifier
|
|
10
|
+
* shape defaults to `KEY-123` (Linear, Jira), and a provider whose refs look
|
|
11
|
+
* different (GitHub's `#123`) passes its own `refPattern`.
|
|
12
|
+
*
|
|
13
|
+
* The parsing half is pure and takes commits as data, so the rules below are
|
|
14
|
+
* testable without git. Reading the range, and enriching refs with issue titles,
|
|
15
|
+
* belong to the caller.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// An issue identifier: uppercase team key, dash, number. The default, used
|
|
19
|
+
// whenever a caller passes no `refPattern`.
|
|
20
|
+
const IDENTIFIER_RE = /\b[A-Z][A-Z0-9]*-\d+\b/g
|
|
21
|
+
// A GitHub issue ref in the same repo: `#123`.
|
|
22
|
+
//
|
|
23
|
+
// WHAT WOULD FOOL IT: `#` is also how a commit says "issue number" in prose and
|
|
24
|
+
// how `owner/repo#123` names ANOTHER repo's issue. Prose is excluded by the
|
|
25
|
+
// trailer anchor (only a `Refs:` line is scanned); the cross-repo form is
|
|
26
|
+
// excluded by the lookbehind, so a ref into some other repo never lands on this
|
|
27
|
+
// one's release — the GitHub twin of `partitionStageMoves`' foreign team key.
|
|
28
|
+
const GITHUB_REF_RE = /(?<![\w/.-])#\d+\b/g
|
|
29
|
+
// A `Refs:` trailer line. Anchored, so it is a line of its own — never prose
|
|
30
|
+
// that happens to mention the word.
|
|
31
|
+
const TRAILER_RE = /^Refs:[ \t]*(.+?)[ \t]*$/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The refs a single commit body claims.
|
|
35
|
+
*
|
|
36
|
+
* Deliberately blind to three things that LOOK like trailers and are not:
|
|
37
|
+
*
|
|
38
|
+
* - a line inside a ``` fence — a commit explaining the convention quotes it;
|
|
39
|
+
* - a quoted line (`> Refs: …`) — same reason, in review replies;
|
|
40
|
+
* - an indented line (4+ spaces) — markdown code, e.g. a sample message.
|
|
41
|
+
*
|
|
42
|
+
* Counting any of those would make a release claim work it does not contain,
|
|
43
|
+
* which is worse than missing a ticket: the missing one is noticed when someone
|
|
44
|
+
* looks for it, the invented one never is.
|
|
45
|
+
*/
|
|
46
|
+
function refsInBody(body, refPattern) {
|
|
47
|
+
const pattern = asGlobal(refPattern) || IDENTIFIER_RE
|
|
48
|
+
const found = []
|
|
49
|
+
let fenced = false
|
|
50
|
+
for (const raw of String(body || '').split('\n')) {
|
|
51
|
+
const line = raw.replace(/\r$/, '')
|
|
52
|
+
if (/^\s*```/.test(line)) {
|
|
53
|
+
fenced = !fenced
|
|
54
|
+
continue
|
|
55
|
+
}
|
|
56
|
+
if (fenced) continue
|
|
57
|
+
if (/^\s*>/.test(line)) continue
|
|
58
|
+
if (/^ {4,}|\t/.test(line)) continue
|
|
59
|
+
const m = TRAILER_RE.exec(line.trim() === line ? line : line.trimStart())
|
|
60
|
+
if (!m) continue
|
|
61
|
+
for (const id of m[1].match(pattern) || []) found.push(id)
|
|
62
|
+
}
|
|
63
|
+
return found
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// `String.prototype.match` only returns every hit for a GLOBAL regex; a
|
|
67
|
+
// provider passing `/#\d+/` would otherwise get its first ref and lose the rest
|
|
68
|
+
// in silence. Anything that is not a RegExp is no pattern at all.
|
|
69
|
+
function asGlobal(pattern) {
|
|
70
|
+
if (!(pattern instanceof RegExp)) return null
|
|
71
|
+
return pattern.global ? pattern : new RegExp(pattern.source, `${pattern.flags}g`)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Whether a commit's changed paths are ENTIRELY bookkeeping.
|
|
76
|
+
*
|
|
77
|
+
* The problem it solves: a spec's `chore(spec): complete <name>` commit carries
|
|
78
|
+
* the same `Refs:` trailer as the code it describes, but lands after the tag
|
|
79
|
+
* that shipped that code — so the ticket turns up in two consecutive release
|
|
80
|
+
* ranges, once for its code and once for its paperwork.
|
|
81
|
+
*
|
|
82
|
+
* Deliberately a POSITIVE signal: it says yes only when it actually saw paths
|
|
83
|
+
* and every one of them sits under an ignored prefix. It never reasons from an
|
|
84
|
+
* absence.
|
|
85
|
+
*
|
|
86
|
+
* WHAT WOULD FOOL THE OTHER PHRASING ("no unignored path was found"): git lists
|
|
87
|
+
* no files at all for a MERGE commit (without `-m`) — verified, not assumed —
|
|
88
|
+
* nor for a genuinely empty one, and a `git log` that failed outright yields no
|
|
89
|
+
* paths for anything. Under that phrasing every one of those becomes a release
|
|
90
|
+
* silently losing its tickets. Under this one they mean "nothing was seen, so
|
|
91
|
+
* nothing is known", which keeps the pre-filter behaviour: an over-claimed
|
|
92
|
+
* ticket is noticed when someone looks for it, whereas a ticket that quietly
|
|
93
|
+
* belongs to no release never is.
|
|
94
|
+
*
|
|
95
|
+
* Matching is path-prefix, not glob: `specs` and `specs/` both mean the
|
|
96
|
+
* directory, and a prefix only matches on a path SEGMENT boundary, so `specs/`
|
|
97
|
+
* never swallows `specs-archive/`.
|
|
98
|
+
*
|
|
99
|
+
* @param {string[]|null|undefined} paths repo-relative paths the commit changed
|
|
100
|
+
* @param {string[]} ignorePaths repo-relative prefixes that are bookkeeping
|
|
101
|
+
*/
|
|
102
|
+
function onlyIgnoredPaths(paths, ignorePaths) {
|
|
103
|
+
if (!Array.isArray(paths) || !paths.length) return false
|
|
104
|
+
const prefixes = (Array.isArray(ignorePaths) ? ignorePaths : [])
|
|
105
|
+
.filter((p) => typeof p === 'string' && p.trim())
|
|
106
|
+
.map((p) => p.trim().replace(/^\.\//, '').replace(/\/+$/, ''))
|
|
107
|
+
.filter(Boolean)
|
|
108
|
+
if (!prefixes.length) return false
|
|
109
|
+
return paths.every((raw) => {
|
|
110
|
+
const file = String(raw == null ? '' : raw)
|
|
111
|
+
.trim()
|
|
112
|
+
.replace(/^\.\//, '')
|
|
113
|
+
// An unreadable entry is an unknown, not an ignored one — it makes the whole
|
|
114
|
+
// commit count, per the bias above.
|
|
115
|
+
if (!file) return false
|
|
116
|
+
return prefixes.some((prefix) => file === prefix || file.startsWith(`${prefix}/`))
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Fold commits into the report a release needs.
|
|
122
|
+
*
|
|
123
|
+
* @param {Array<{sha?:string, subject?:string, body?:string, paths?:string[]}>} commits
|
|
124
|
+
* @param {{ignorePaths?:string[], refPattern?:RegExp, foreignPatterns?:RegExp[]}} [options]
|
|
125
|
+
* `ignorePaths` marks bookkeeping — see `onlyIgnoredPaths`. Omitted (or
|
|
126
|
+
* empty) means nothing is ignored, so the report is what it was before the
|
|
127
|
+
* filter existed. `refPattern` is this provider's ref shape (see
|
|
128
|
+
* `refsInBody`). `foreignPatterns` are OTHER trackers' ref shapes this repo
|
|
129
|
+
* used before — a repo that moved from Linear to GitHub still has
|
|
130
|
+
* `Refs: SKS-29` all through its history, and those commits were referenced,
|
|
131
|
+
* just not to this tracker. They are counted as `historical` rather than
|
|
132
|
+
* `unreferenced`, which exists to surface a MISSED trailer.
|
|
133
|
+
* @returns {{tickets: Array<{ref:string, commits:number}>, unreferenced:number, ignored:number, total:number, historical?:number}}
|
|
134
|
+
* `historical` is present only when `foreignPatterns` was given, so a
|
|
135
|
+
* provider that never moved trackers sees exactly the shape it always did.
|
|
136
|
+
* `tickets` is deduped in FIRST-SEEN order: a ticket touched by eight commits
|
|
137
|
+
* is listed once, where it first appears, not eight times. `ignored` is
|
|
138
|
+
* reported rather than merely subtracted — a filter that removes commits in
|
|
139
|
+
* silence reads as "there was nothing there".
|
|
140
|
+
*/
|
|
141
|
+
function ticketsInRange(commits, options = {}) {
|
|
142
|
+
const ignorePaths = (options && options.ignorePaths) || []
|
|
143
|
+
const refPattern = options && options.refPattern
|
|
144
|
+
const foreign = ((options && options.foreignPatterns) || []).map(asGlobal).filter(Boolean)
|
|
145
|
+
const seen = new Map()
|
|
146
|
+
let unreferenced = 0
|
|
147
|
+
let ignored = 0
|
|
148
|
+
let historical = 0
|
|
149
|
+
for (const commit of commits || []) {
|
|
150
|
+
if (onlyIgnoredPaths(commit && commit.paths, ignorePaths)) {
|
|
151
|
+
// Not counted as unreferenced either: that number exists to surface a
|
|
152
|
+
// MISSED trailer, and a paperwork commit is not a gap someone should hunt.
|
|
153
|
+
ignored++
|
|
154
|
+
continue
|
|
155
|
+
}
|
|
156
|
+
const refs = [...new Set(refsInBody(commit && commit.body, refPattern))]
|
|
157
|
+
if (!refs.length) {
|
|
158
|
+
// A POSITIVE signal, never an absence: only a trailer that actually
|
|
159
|
+
// carries an older tracker's ref makes a commit historical. A commit with
|
|
160
|
+
// no trailer at all is still the gap `unreferenced` is there to name.
|
|
161
|
+
if (foreign.some((p) => refsInBody(commit && commit.body, p).length)) historical++
|
|
162
|
+
else unreferenced++
|
|
163
|
+
continue
|
|
164
|
+
}
|
|
165
|
+
for (const ref of refs) seen.set(ref, (seen.get(ref) || 0) + 1)
|
|
166
|
+
}
|
|
167
|
+
const report = {
|
|
168
|
+
tickets: [...seen.entries()].map(([ref, count]) => ({ ref, commits: count })),
|
|
169
|
+
unreferenced,
|
|
170
|
+
ignored,
|
|
171
|
+
total: (commits || []).length,
|
|
172
|
+
}
|
|
173
|
+
if (foreign.length) report.historical = historical
|
|
174
|
+
return report
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Split a release's tickets into the ones a stage move may touch and the ones it
|
|
179
|
+
* must not, with a reason for every exclusion.
|
|
180
|
+
*
|
|
181
|
+
* Three reasons to leave a ticket alone, and each is a case where acting would
|
|
182
|
+
* be worse than not acting:
|
|
183
|
+
*
|
|
184
|
+
* - **foreign** — the ref is not this repo's team. A range can carry another
|
|
185
|
+
* team's ref (a shared dependency, a quoted ticket), and writing to a team
|
|
186
|
+
* this repo was never configured for is the worst failure available here.
|
|
187
|
+
* - **unlinked** — the ref is this team's, but no spec in the repo claims it.
|
|
188
|
+
* It may be tracker-only work, or a typo in a trailer. Either way nothing
|
|
189
|
+
* here knows what it is, so it is reported, not moved.
|
|
190
|
+
* - **unfinished** — a spec that has not reached the ceded bucket. Its code
|
|
191
|
+
* really is in the release (it landed via `/spec-to-main`), but push still
|
|
192
|
+
* owns its workflow state and would bounce it straight back. Exactly one
|
|
193
|
+
* writer per issue at any moment beats a visible flip-flop.
|
|
194
|
+
*
|
|
195
|
+
* Pure: it takes the spec list as data, so the rules are testable without a repo.
|
|
196
|
+
*/
|
|
197
|
+
function partitionStageMoves({ tickets, teamKey, specs, cededBucket = 'complete' }) {
|
|
198
|
+
const bucketOf = new Map()
|
|
199
|
+
for (const spec of specs || []) {
|
|
200
|
+
if (spec && spec.identifier) bucketOf.set(spec.identifier, spec.bucket)
|
|
201
|
+
}
|
|
202
|
+
const key = String(teamKey || '').trim().toUpperCase()
|
|
203
|
+
const movable = []
|
|
204
|
+
const foreign = []
|
|
205
|
+
const unlinked = []
|
|
206
|
+
const unfinished = []
|
|
207
|
+
for (const ticket of tickets || []) {
|
|
208
|
+
const ref = ticket && ticket.ref
|
|
209
|
+
if (!ref) continue
|
|
210
|
+
if (key && !ref.toUpperCase().startsWith(`${key}-`)) {
|
|
211
|
+
foreign.push(ticket)
|
|
212
|
+
} else if (!bucketOf.has(ref)) {
|
|
213
|
+
unlinked.push(ticket)
|
|
214
|
+
} else if (bucketOf.get(ref) !== cededBucket) {
|
|
215
|
+
unfinished.push({ ...ticket, bucket: bucketOf.get(ref) })
|
|
216
|
+
} else {
|
|
217
|
+
movable.push(ticket)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return { movable, foreign, unlinked, unfinished }
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Whether moving from `fromState` to the rung `toKey` runs against the declared
|
|
225
|
+
* order — and if so, how to say it.
|
|
226
|
+
*
|
|
227
|
+
* WARNS, never refuses. A rollback from test and a hotfix going straight to prod
|
|
228
|
+
* are both legitimate, and a check that blocked either would be wrong on healthy
|
|
229
|
+
* input. An issue that is on no rung yet is entering the ladder, which is the
|
|
230
|
+
* normal case and says nothing.
|
|
231
|
+
*
|
|
232
|
+
* `lifecycleStates` is the bucket map's own state names, and a state among them
|
|
233
|
+
* means the issue is at its LIFECYCLE position, not on a rung — even when the
|
|
234
|
+
* two names coincide. They routinely do: `states.complete` and a final `prod`
|
|
235
|
+
* rung are both naturally "Done", and without this a spec that had merely been
|
|
236
|
+
* completed would read as already deployed to prod, so its first real deploy
|
|
237
|
+
* would be warned about as a move backwards. Bucket wins over ladder here for
|
|
238
|
+
* the same reason it wins in `bucketForState`.
|
|
239
|
+
*
|
|
240
|
+
* @returns {string|null}
|
|
241
|
+
*/
|
|
242
|
+
function stageOrderWarning(stages, fromState, toKey, lifecycleStates = []) {
|
|
243
|
+
const list = Array.isArray(stages) ? stages : []
|
|
244
|
+
const to = list.findIndex((s) => s && s.key === toKey)
|
|
245
|
+
if (to < 0) return null
|
|
246
|
+
const want = String(fromState || '').toLowerCase().trim()
|
|
247
|
+
if (!want) return null
|
|
248
|
+
const lifecycle = new Set(
|
|
249
|
+
(Array.isArray(lifecycleStates) ? lifecycleStates : [])
|
|
250
|
+
.filter((n) => typeof n === 'string')
|
|
251
|
+
.map((n) => n.toLowerCase().trim()),
|
|
252
|
+
)
|
|
253
|
+
if (lifecycle.has(want)) return null
|
|
254
|
+
const from = list.findIndex((s) => s && typeof s.state === 'string' && s.state.toLowerCase().trim() === want)
|
|
255
|
+
if (from < 0) return null
|
|
256
|
+
if (to < from) return `moves back from "${list[from].key}"`
|
|
257
|
+
if (to > from + 1) return `skips ${to - from - 1} rung(s) from "${list[from].key}"`
|
|
258
|
+
return null
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
module.exports = {
|
|
262
|
+
ticketsInRange,
|
|
263
|
+
refsInBody,
|
|
264
|
+
onlyIgnoredPaths,
|
|
265
|
+
partitionStageMoves,
|
|
266
|
+
stageOrderWarning,
|
|
267
|
+
IDENTIFIER_RE,
|
|
268
|
+
GITHUB_REF_RE,
|
|
269
|
+
}
|