@futurelastic/colab-handbook 1.12.0-rc.17 → 1.12.0-rc.18
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/tools/colab +19 -9
- package/tools/lib/git.js +20 -1
- package/tools/lib/group-labels.js +65 -0
package/package.json
CHANGED
package/tools/colab
CHANGED
|
@@ -6231,9 +6231,15 @@ function cmdDoctor(argv) {
|
|
|
6231
6231
|
const entry = { repo: shortRepo(repo), label: v.name, verdict: v.verdict,
|
|
6232
6232
|
total: v.total, open: v.open, members: v.members, deleted: false, error: null };
|
|
6233
6233
|
if (opts.prune && v.verdict === 'spent') {
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6234
|
+
// #448: `spent` came from the search-backed listing; confirm through the issues table.
|
|
6235
|
+
const t = groupLabels.teardownSpentGroupLabel(v.name, {
|
|
6236
|
+
searchOpen: [],
|
|
6237
|
+
confirmOpen: (name) => git.ghOpenIssueNumbersByLabel(repo, name),
|
|
6238
|
+
deleteLabel: (name) => git.ghLabelDelete(repo, name),
|
|
6239
|
+
});
|
|
6240
|
+
entry.deleted = t.deleted;
|
|
6241
|
+
if (t.action === 'keep') entry.error = groupLabels.keptReason(v.name, t);
|
|
6242
|
+
else if (!t.deleted) entry.error = t.error;
|
|
6237
6243
|
}
|
|
6238
6244
|
report.spentGroupLabels.push(entry);
|
|
6239
6245
|
}
|
|
@@ -12412,12 +12418,16 @@ function shipLandedTail({ repoAbs, sess, target, trunk, gh, sha, closeIssues, re
|
|
|
12412
12418
|
// its last member.
|
|
12413
12419
|
if (gh) {
|
|
12414
12420
|
for (const gl of groupLabelsCarried) {
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
+
// #448: search says zero → a non-search read must agree before the repo-wide delete.
|
|
12422
|
+
const t = groupLabels.teardownSpentGroupLabel(gl, {
|
|
12423
|
+
searchOpen: (name) => git.ghIssueListByLabel(repoAbs, name, 'open', ['number']),
|
|
12424
|
+
confirmOpen: (name) => git.ghOpenIssueNumbersByLabel(repoAbs, name),
|
|
12425
|
+
deleteLabel: (name) => git.ghLabelDelete(repoAbs, name),
|
|
12426
|
+
});
|
|
12427
|
+
if (t.reason === 'open') continue; // still binds the remainder — leave it
|
|
12428
|
+
if (t.action === 'keep') { warn(groupLabels.keptReason(gl, t)); continue; }
|
|
12429
|
+
if (t.deleted) print(` deleted spent group label ${gl} (every member now closed)`);
|
|
12430
|
+
else warn(`could not delete spent group label ${gl}: ${t.error}`);
|
|
12421
12431
|
}
|
|
12422
12432
|
}
|
|
12423
12433
|
|
package/tools/lib/git.js
CHANGED
|
@@ -695,6 +695,25 @@ function ghIssueListByLabel(repo, label, state, fields) {
|
|
|
695
695
|
catch (_) { return null; }
|
|
696
696
|
}
|
|
697
697
|
|
|
698
|
+
/**
|
|
699
|
+
* #448: the open issues carrying `label`, as numbers, read through the REST issues list — NOT
|
|
700
|
+
* search. `gh issue list --label` (ghIssueListByLabel above) is served by GraphQL `search(...)`,
|
|
701
|
+
* whose index can lag a burst of closes and answer "0 open" for a label still on an open issue;
|
|
702
|
+
* this endpoint reads the issues table directly. Pull requests share the endpoint and are dropped.
|
|
703
|
+
* Null on any failure — "could not read", never "none open", same contract as ghIssueListByLabel.
|
|
704
|
+
* Used as the confirming read before a `group:` label is deleted (group-labels.js
|
|
705
|
+
* teardownSpentGroupLabel).
|
|
706
|
+
*/
|
|
707
|
+
function ghOpenIssueNumbersByLabel(repo, label) {
|
|
708
|
+
const r = ghApi(repo, [
|
|
709
|
+
'--method', 'GET', '--paginate', 'repos/{owner}/{repo}/issues',
|
|
710
|
+
'-f', `labels=${label}`, '-f', 'state=open', '-f', 'per_page=100',
|
|
711
|
+
'--jq', '.[] | select(.pull_request == null) | .number',
|
|
712
|
+
]);
|
|
713
|
+
if (!r.ok) return null;
|
|
714
|
+
return String(r.stdout || '').split('\n').map((l) => l.trim()).filter(Boolean).map(Number);
|
|
715
|
+
}
|
|
716
|
+
|
|
698
717
|
/**
|
|
699
718
|
* `gh label delete <name> --yes` — returns {ok, stderr}. Deletes the LABEL OBJECT from the
|
|
700
719
|
* repo's tracker, not one issue's use of it — every issue that carried it loses it. Callers
|
|
@@ -1050,7 +1069,7 @@ module.exports = {
|
|
|
1050
1069
|
claimRemote, remoteHeads,
|
|
1051
1070
|
worktreeList, worktreeListDetailed, resolveWorktreePathForBranch, gitFailureLine,
|
|
1052
1071
|
dirtyTracked, dirtyUntracked, dirtyAny,
|
|
1053
|
-
ghAvailable, ghState, ghIssueEdit, ghListLabels, ghAssignedIssues,
|
|
1072
|
+
ghAvailable, ghState, ghIssueEdit, ghListLabels, ghOpenIssueNumbersByLabel, ghAssignedIssues,
|
|
1054
1073
|
ghCurrentLogin, ghIssueView, ghIssueComment, ghRunForSha, ghRunForCommit, ghRunsForCommit, ghRunsForRef, ghRunsAtCommit, ghRunForCommitAnyRef, commitTimeMs, ghRunsSince, summarizeRunsForCommit,
|
|
1055
1074
|
ghRunJobCount, ghRunJobs,
|
|
1056
1075
|
ghIssueListByLabel, ghLabelDelete, ghLabelCreate, ghListLabelsDetailed, ghLabelEditDescription,
|
|
@@ -115,6 +115,71 @@ function reportableLabels(verdicts) {
|
|
|
115
115
|
return (verdicts || []).filter((v) => v && v.verdict !== 'mid-flight');
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
/**
|
|
119
|
+
* #448: the second read before a destructive delete. Measured in an adopting repo: ship's (i)
|
|
120
|
+
* teardown deleted `group:<key>` while a fourth, deliberately-unshipped member still carried it
|
|
121
|
+
* OPEN — the open-member listing had come back empty 29 s after the squash closed the other three.
|
|
122
|
+
* That listing is `gh issue list --label`, which `gh` serves through GraphQL `search(...)`
|
|
123
|
+
* (verified with GH_DEBUG=api), and the search index lags the issues table: a burst of closes and
|
|
124
|
+
* label writes can leave it answering "0 open" for a label still on an open issue.
|
|
125
|
+
*
|
|
126
|
+
* `gh label delete` is repo-wide and cannot be undone per issue, so "0 open" from search alone is
|
|
127
|
+
* not enough to act on. The confirming read is the REST issues list (`ghOpenIssueNumbersByLabel`),
|
|
128
|
+
* which reads the issues table, not the index. The two failures are asymmetric exactly as
|
|
129
|
+
* isOpenMember's note says — keeping a spent label costs one stale picker entry until the next
|
|
130
|
+
* ship or `doctor --sync --prune`; deleting a live one strips a grouping from work in flight — so
|
|
131
|
+
* every case but "both reads agree on zero" keeps the label.
|
|
132
|
+
*
|
|
133
|
+
* @param {Array|null} searchOpen open members per the search-backed listing; null = could not read
|
|
134
|
+
* @param {Array|null} confirmOpen open member NUMBERS per the non-search read; null = could not read
|
|
135
|
+
* @returns {{action:'delete'|'keep', reason:string, open:number[]}}
|
|
136
|
+
* reason ∈ unread · open · unconfirmed · disagree · spent
|
|
137
|
+
*/
|
|
138
|
+
function spentLabelDecision(searchOpen, confirmOpen) {
|
|
139
|
+
if (searchOpen === null || searchOpen === undefined) return { action: 'keep', reason: 'unread', open: [] };
|
|
140
|
+
if (Array.isArray(searchOpen) && searchOpen.length > 0) return { action: 'keep', reason: 'open', open: [] };
|
|
141
|
+
if (confirmOpen === null || confirmOpen === undefined || !Array.isArray(confirmOpen)) {
|
|
142
|
+
return { action: 'keep', reason: 'unconfirmed', open: [] };
|
|
143
|
+
}
|
|
144
|
+
if (confirmOpen.length > 0) {
|
|
145
|
+
const nums = confirmOpen.map((m) => (m && typeof m === 'object' ? m.number : m))
|
|
146
|
+
.filter((n) => n !== undefined && n !== null);
|
|
147
|
+
return { action: 'keep', reason: 'disagree', open: nums };
|
|
148
|
+
}
|
|
149
|
+
return { action: 'delete', reason: 'spent', open: [] };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The I/O shell around spentLabelDecision, with every call injected so the delete path is pinned by
|
|
154
|
+
* a test with no network (#448). `searchOpen` may be passed pre-read (doctor already has the
|
|
155
|
+
* membership from its classify pass) or as a function; `confirmOpen` and `deleteLabel` are always
|
|
156
|
+
* functions and are only CALLED when needed — the confirm read only when search said zero, the
|
|
157
|
+
* delete only when both reads agree.
|
|
158
|
+
*
|
|
159
|
+
* @returns {{action:'delete'|'keep', reason:string, open:number[], deleted:boolean, error:string|null}}
|
|
160
|
+
*/
|
|
161
|
+
function teardownSpentGroupLabel(name, { searchOpen, confirmOpen, deleteLabel }) {
|
|
162
|
+
if (!isGroupLabel(name)) return { action: 'keep', reason: 'unread', open: [], deleted: false, error: null };
|
|
163
|
+
const s = typeof searchOpen === 'function' ? searchOpen(name) : searchOpen;
|
|
164
|
+
const needConfirm = Array.isArray(s) && s.length === 0;
|
|
165
|
+
const c = needConfirm ? confirmOpen(name) : null;
|
|
166
|
+
const d = spentLabelDecision(s, needConfirm ? c : null);
|
|
167
|
+
if (d.action !== 'delete') return { ...d, deleted: false, error: null };
|
|
168
|
+
const r = deleteLabel(name) || {};
|
|
169
|
+
return { ...d, deleted: !!r.ok, error: r.ok ? null : (r.stderr || 'gh label delete failed') };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** One human line for a kept label — the CLI and its test read the same words. */
|
|
173
|
+
function keptReason(name, d) {
|
|
174
|
+
switch (d.reason) {
|
|
175
|
+
case 'unread': return `could not check membership of ${name} — left in place`;
|
|
176
|
+
case 'unconfirmed': return `${name} reads 0 open members by search but the confirming (non-search) read failed — left in place`;
|
|
177
|
+
case 'disagree': return `${name} reads 0 open members by search, but #${d.open.join(', #')} still carr${d.open.length === 1 ? 'ies' : 'y'} it open (non-search read) — left in place; the search index is lagging (#448)`;
|
|
178
|
+
default: return '';
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
118
182
|
module.exports = {
|
|
119
183
|
isOpenMember, classifyGroupLabel, classifyGroupLabels, deletableLabels, reportableLabels,
|
|
184
|
+
spentLabelDecision, teardownSpentGroupLabel, keptReason,
|
|
120
185
|
};
|