@kaynooo/cli-forgejo 0.0.0-stage → 0.10.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/LICENSE +21 -0
- package/README.md +53 -2
- package/dist/cli.js +3720 -0
- package/package.json +31 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,3720 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// src/cli.ts
|
|
5
|
+
import process15 from "process";
|
|
6
|
+
|
|
7
|
+
// ../kit/src/args.ts
|
|
8
|
+
import process4 from "process";
|
|
9
|
+
import { parseArgs } from "util";
|
|
10
|
+
|
|
11
|
+
// ../kit/src/format.ts
|
|
12
|
+
import process3 from "process";
|
|
13
|
+
|
|
14
|
+
// ../kit/src/style.ts
|
|
15
|
+
import process2 from "process";
|
|
16
|
+
|
|
17
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
18
|
+
function x(s) {
|
|
19
|
+
let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
|
|
20
|
+
if (!/^[a-f0-9]+$/.test(r))
|
|
21
|
+
return [0, 0, 0];
|
|
22
|
+
let t = r.length, n = (c) => Number.parseInt(c, 16);
|
|
23
|
+
if (t === 3 || t === 4) {
|
|
24
|
+
let c = n(r[0] + r[0]), u = n(r[1] + r[1]), h = n(r[2] + r[2]), g = t === 4 ? n(r[3] + r[3]) : undefined;
|
|
25
|
+
return g !== undefined ? [c, u, h, g] : [c, u, h];
|
|
26
|
+
}
|
|
27
|
+
if (t !== 6 && t !== 8)
|
|
28
|
+
throw Error(`Invalid hex color length: ${t}`);
|
|
29
|
+
let a = n(r.slice(0, 2)), b = n(r.slice(2, 4)), o = n(r.slice(4, 6)), y = t === 8 ? n(r.slice(6, 8)) : undefined;
|
|
30
|
+
if ([a, b, o].some(Number.isNaN) || y !== undefined && Number.isNaN(y))
|
|
31
|
+
throw Error(`Invalid hex color value: ${s}`);
|
|
32
|
+
return y !== undefined ? [a, b, o, y] : [a, b, o];
|
|
33
|
+
}
|
|
34
|
+
function A(s) {
|
|
35
|
+
let [r, t, n, a] = s;
|
|
36
|
+
if (a)
|
|
37
|
+
return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
|
|
38
|
+
return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
|
|
39
|
+
}
|
|
40
|
+
function R(s, r, t) {
|
|
41
|
+
s = (s % 360 + 360) % 360, t /= 100;
|
|
42
|
+
let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
|
|
43
|
+
let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
|
|
44
|
+
return Math.round(255 * y);
|
|
45
|
+
};
|
|
46
|
+
return [a(0), a(8), a(4)];
|
|
47
|
+
}
|
|
48
|
+
function k(s) {
|
|
49
|
+
let [r, t, n] = s;
|
|
50
|
+
r /= 255, t /= 255, n /= 255;
|
|
51
|
+
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
|
|
52
|
+
if (a !== b) {
|
|
53
|
+
let u = a - b;
|
|
54
|
+
if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
|
|
55
|
+
o = (t - n) / u + (t < n ? 6 : 0);
|
|
56
|
+
else if (a === t)
|
|
57
|
+
o = (n - r) / u + 2;
|
|
58
|
+
else
|
|
59
|
+
o = (r - t) / u + 4;
|
|
60
|
+
o /= 6;
|
|
61
|
+
}
|
|
62
|
+
return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
|
|
63
|
+
}
|
|
64
|
+
function H(s, r, t) {
|
|
65
|
+
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
66
|
+
let n = (a) => {
|
|
67
|
+
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
68
|
+
return Math.round(255 * o);
|
|
69
|
+
};
|
|
70
|
+
return [n(5), n(3), n(1)];
|
|
71
|
+
}
|
|
72
|
+
function f(s) {
|
|
73
|
+
let [r, t, n] = s;
|
|
74
|
+
r /= 255, t /= 255, n /= 255;
|
|
75
|
+
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
|
|
76
|
+
if (o !== 0) {
|
|
77
|
+
if (a === r)
|
|
78
|
+
y = (t - n) / o + (t < n ? 6 : 0);
|
|
79
|
+
else if (a === t)
|
|
80
|
+
y = (n - r) / o + 2;
|
|
81
|
+
else
|
|
82
|
+
y = (r - t) / o + 4;
|
|
83
|
+
y /= 6;
|
|
84
|
+
}
|
|
85
|
+
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
86
|
+
}
|
|
87
|
+
function O(s) {
|
|
88
|
+
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
89
|
+
if (a === 1)
|
|
90
|
+
return [0, 0, 0, 100];
|
|
91
|
+
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
92
|
+
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
93
|
+
}
|
|
94
|
+
function v(s, r, t, n) {
|
|
95
|
+
return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
|
|
96
|
+
}
|
|
97
|
+
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
98
|
+
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
99
|
+
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
100
|
+
function T(s) {
|
|
101
|
+
let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
|
|
102
|
+
return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
|
|
103
|
+
}
|
|
104
|
+
function M(s, r, t) {
|
|
105
|
+
let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
|
|
106
|
+
return [u(o), u(y), u(c)];
|
|
107
|
+
}
|
|
108
|
+
function d(s) {
|
|
109
|
+
let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
|
|
110
|
+
return [i(r, 4), i(a, 4), i(b, 2)];
|
|
111
|
+
}
|
|
112
|
+
function C(s, r, t) {
|
|
113
|
+
let n = t * Math.PI / 180;
|
|
114
|
+
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
115
|
+
}
|
|
116
|
+
function l(s) {
|
|
117
|
+
let r = s / 255;
|
|
118
|
+
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
class e {
|
|
122
|
+
r;
|
|
123
|
+
g;
|
|
124
|
+
b;
|
|
125
|
+
a;
|
|
126
|
+
constructor(s, r, t, n = 1) {
|
|
127
|
+
this.r = s, this.g = r, this.b = t, this.a = n;
|
|
128
|
+
}
|
|
129
|
+
static from(s, r) {
|
|
130
|
+
if (s === "hex") {
|
|
131
|
+
let [t, n, a, b] = x(r);
|
|
132
|
+
return new e(t, n, a, b);
|
|
133
|
+
}
|
|
134
|
+
if (s === "rgb") {
|
|
135
|
+
if (Array.isArray(r)) {
|
|
136
|
+
let [o, y, c, u] = r;
|
|
137
|
+
return new e(o, y, c, u);
|
|
138
|
+
}
|
|
139
|
+
let { r: t, g: n, b: a, a: b } = r;
|
|
140
|
+
return new e(t, n, a, b);
|
|
141
|
+
}
|
|
142
|
+
if (s === "hsl") {
|
|
143
|
+
let t, n, a, b;
|
|
144
|
+
if (Array.isArray(r))
|
|
145
|
+
[t, n, a, b] = r;
|
|
146
|
+
else
|
|
147
|
+
({ h: t, s: n, l: a, a: b } = r);
|
|
148
|
+
let [o, y, c] = R(t, n, a);
|
|
149
|
+
return new e(o, y, c, b);
|
|
150
|
+
}
|
|
151
|
+
if (s === "hsv") {
|
|
152
|
+
let t, n, a, b;
|
|
153
|
+
if (Array.isArray(r))
|
|
154
|
+
[t, n, a, b] = r;
|
|
155
|
+
else
|
|
156
|
+
({ h: t, s: n, v: a, a: b } = r);
|
|
157
|
+
let [o, y, c] = H(t, n, a);
|
|
158
|
+
return new e(o, y, c, b);
|
|
159
|
+
}
|
|
160
|
+
if (s === "cmyk") {
|
|
161
|
+
let t, n, a, b, o;
|
|
162
|
+
if (Array.isArray(r))
|
|
163
|
+
[t, n, a, b, o] = r;
|
|
164
|
+
else
|
|
165
|
+
({ c: t, m: n, y: a, k: b, a: o } = r);
|
|
166
|
+
let [y, c, u] = v(t, n, a, b);
|
|
167
|
+
return new e(y, c, u, o);
|
|
168
|
+
}
|
|
169
|
+
if (s === "oklch") {
|
|
170
|
+
let t, n, a, b;
|
|
171
|
+
if (Array.isArray(r))
|
|
172
|
+
[t, n, a, b] = r;
|
|
173
|
+
else
|
|
174
|
+
({ l: t, c: n, h: a, a: b } = r);
|
|
175
|
+
let [o, y, c] = C(t, n, a);
|
|
176
|
+
return new e(o, y, c, b);
|
|
177
|
+
}
|
|
178
|
+
if (s === "oklab") {
|
|
179
|
+
let t, n, a, b;
|
|
180
|
+
if (Array.isArray(r))
|
|
181
|
+
[t, n, a, b] = r;
|
|
182
|
+
else
|
|
183
|
+
({ l: t, a: n, b: a, alpha: b } = r);
|
|
184
|
+
let [o, y, c] = M(t, n, a);
|
|
185
|
+
return new e(o, y, c, b);
|
|
186
|
+
}
|
|
187
|
+
throw Error("Invalid input");
|
|
188
|
+
}
|
|
189
|
+
to(s) {
|
|
190
|
+
switch (s) {
|
|
191
|
+
case "rgb":
|
|
192
|
+
return [this.r, this.g, this.b];
|
|
193
|
+
case "rgba":
|
|
194
|
+
return [this.r, this.g, this.b, this.a];
|
|
195
|
+
case "hex":
|
|
196
|
+
return A([this.r, this.g, this.b]);
|
|
197
|
+
case "hexa":
|
|
198
|
+
return A([this.r, this.g, this.b, this.a]);
|
|
199
|
+
case "hsl":
|
|
200
|
+
return k([this.r, this.g, this.b]);
|
|
201
|
+
case "hsla":
|
|
202
|
+
return [...k([this.r, this.g, this.b]), this.a];
|
|
203
|
+
case "hsv":
|
|
204
|
+
return f([this.r, this.g, this.b]);
|
|
205
|
+
case "hsva":
|
|
206
|
+
return [...f([this.r, this.g, this.b]), this.a];
|
|
207
|
+
case "cmyk":
|
|
208
|
+
return O([this.r, this.g, this.b]);
|
|
209
|
+
case "cmyka":
|
|
210
|
+
return [...O([this.r, this.g, this.b]), this.a];
|
|
211
|
+
case "oklch":
|
|
212
|
+
return d([this.r, this.g, this.b]);
|
|
213
|
+
case "oklcha":
|
|
214
|
+
return [...d([this.r, this.g, this.b]), this.a];
|
|
215
|
+
case "oklab":
|
|
216
|
+
return T([this.r, this.g, this.b]);
|
|
217
|
+
case "oklaba":
|
|
218
|
+
return [...T([this.r, this.g, this.b]), this.a];
|
|
219
|
+
default:
|
|
220
|
+
return [this.r, this.g, this.b];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
getLuminance() {
|
|
224
|
+
let s = l(this.r), r = l(this.g), t = l(this.b);
|
|
225
|
+
return 0.2126 * s + 0.7152 * r + 0.0722 * t;
|
|
226
|
+
}
|
|
227
|
+
contrastRatio(s) {
|
|
228
|
+
let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
|
|
229
|
+
return (n + 0.05) / (a + 0.05);
|
|
230
|
+
}
|
|
231
|
+
bestContrastForeground() {
|
|
232
|
+
let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
|
|
233
|
+
return t >= n ? s : r;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
238
|
+
var r = 39;
|
|
239
|
+
var o = 49;
|
|
240
|
+
var f2 = "\x1B[";
|
|
241
|
+
var C2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
|
|
242
|
+
let [a, l, s] = e.from("hex", i).to("rgb");
|
|
243
|
+
return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
|
|
244
|
+
}, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
|
|
245
|
+
var b = new Set(["", "1", "2", "3", "true"]);
|
|
246
|
+
function h(i, n = globalThis.process?.env ?? {}) {
|
|
247
|
+
if (n.FORCE_COLOR !== undefined)
|
|
248
|
+
return b.has(n.FORCE_COLOR);
|
|
249
|
+
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
250
|
+
return false;
|
|
251
|
+
return i?.isTTY === true;
|
|
252
|
+
}
|
|
253
|
+
function d2(i, n, a) {
|
|
254
|
+
if (!h(a.stream ?? globalThis.process?.stdout, a.env))
|
|
255
|
+
return n;
|
|
256
|
+
let l = "", s = "";
|
|
257
|
+
for (let g = 0, y = i.length;g < y; g++) {
|
|
258
|
+
let [c, p] = i[g];
|
|
259
|
+
l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
|
|
260
|
+
}
|
|
261
|
+
return l + n + s;
|
|
262
|
+
}
|
|
263
|
+
function u(i, n = []) {
|
|
264
|
+
return new Proxy((l) => d2(n, l, i), { get(l, s) {
|
|
265
|
+
let g = C2[s];
|
|
266
|
+
if (Array.isArray(g))
|
|
267
|
+
return u(i, [...n, g]);
|
|
268
|
+
if (typeof g === "function")
|
|
269
|
+
return (...y) => u(i, [...n, g(...y)]);
|
|
270
|
+
throw Error(`Unknown style: ${String(s)}`);
|
|
271
|
+
} });
|
|
272
|
+
}
|
|
273
|
+
function le(i = {}) {
|
|
274
|
+
return u(i);
|
|
275
|
+
}
|
|
276
|
+
var t = le();
|
|
277
|
+
|
|
278
|
+
// ../kit/src/style.ts
|
|
279
|
+
var MARKS = {
|
|
280
|
+
ok: { symbol: "\u2713", word: "ok:", paint: (colors) => colors.green },
|
|
281
|
+
warn: { symbol: "!", word: "warning:", paint: (colors) => colors.yellow },
|
|
282
|
+
problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
|
|
283
|
+
note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
|
|
284
|
+
};
|
|
285
|
+
function takesControlCodes(stream, env = process2.env) {
|
|
286
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
287
|
+
}
|
|
288
|
+
function paint(stream, env = process2.env) {
|
|
289
|
+
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
290
|
+
}
|
|
291
|
+
function marked(mark, text, stream, detail, env = process2.env) {
|
|
292
|
+
const colors = paint(stream, env);
|
|
293
|
+
const { symbol, word, paint: tint } = MARKS[mark];
|
|
294
|
+
const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
|
|
295
|
+
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
296
|
+
}
|
|
297
|
+
function note(text, detail) {
|
|
298
|
+
console.log(marked("note", text, process2.stdout, detail));
|
|
299
|
+
}
|
|
300
|
+
function warn(text, detail) {
|
|
301
|
+
console.error(marked("warn", text, process2.stderr, detail));
|
|
302
|
+
}
|
|
303
|
+
var STATUSES = {
|
|
304
|
+
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
305
|
+
failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
|
|
306
|
+
running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
|
|
307
|
+
queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
|
|
308
|
+
skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
|
|
309
|
+
};
|
|
310
|
+
var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
|
|
311
|
+
function statusOf(word) {
|
|
312
|
+
return STATUS_OF.get(word.toLowerCase());
|
|
313
|
+
}
|
|
314
|
+
function badge(word, stream, env = process2.env) {
|
|
315
|
+
const status = statusOf(word);
|
|
316
|
+
if (status === undefined || !takesControlCodes(stream, env))
|
|
317
|
+
return word;
|
|
318
|
+
const { symbol, paint: tint } = STATUSES[status];
|
|
319
|
+
return tint(paint(stream, env))(`${symbol} ${word}`);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ../kit/src/format.ts
|
|
323
|
+
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
324
|
+
function formatSeconds(total) {
|
|
325
|
+
let rest = Math.max(0, Math.round(total));
|
|
326
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
327
|
+
const amount = Math.floor(rest / size);
|
|
328
|
+
rest -= amount * size;
|
|
329
|
+
return `${amount}${unit}`;
|
|
330
|
+
});
|
|
331
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
332
|
+
if (first === -1)
|
|
333
|
+
return "0s";
|
|
334
|
+
const next = amounts[first + 1];
|
|
335
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
336
|
+
}
|
|
337
|
+
function formatDuration(ms) {
|
|
338
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
339
|
+
}
|
|
340
|
+
function formatElapsed(ms) {
|
|
341
|
+
return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
|
|
342
|
+
}
|
|
343
|
+
function upTo(text, separator) {
|
|
344
|
+
const end = text.indexOf(separator);
|
|
345
|
+
return end === -1 ? text : text.slice(0, end);
|
|
346
|
+
}
|
|
347
|
+
function formatAge(date, now = Date.now()) {
|
|
348
|
+
const at = typeof date === "number" ? date : Date.parse(date);
|
|
349
|
+
if (Number.isNaN(at))
|
|
350
|
+
return "-";
|
|
351
|
+
const seconds = (now - at) / 1000;
|
|
352
|
+
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
353
|
+
}
|
|
354
|
+
function truncate(text, width) {
|
|
355
|
+
return text.length <= width ? text : `${text.slice(0, Math.max(0, width - 1))}\u2026`;
|
|
356
|
+
}
|
|
357
|
+
var LINE_BREAKS = /\s*\n\s*/g;
|
|
358
|
+
var ESCAPE = String.fromCharCode(27);
|
|
359
|
+
function textWidth(text) {
|
|
360
|
+
return Bun.stringWidth(text);
|
|
361
|
+
}
|
|
362
|
+
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
363
|
+
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
364
|
+
const widths = [];
|
|
365
|
+
for (const row of cells) {
|
|
366
|
+
for (const [index, cell] of row.entries())
|
|
367
|
+
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
368
|
+
}
|
|
369
|
+
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
370
|
+
const colors = paint(process3.stdout);
|
|
371
|
+
const lines = shown.map((row) => row.map((cell, index) => {
|
|
372
|
+
const width = widths[index] ?? 0;
|
|
373
|
+
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
374
|
+
if (align[index] === "right")
|
|
375
|
+
return `${gap}${cell}`;
|
|
376
|
+
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
377
|
+
}).join(" ").trimEnd());
|
|
378
|
+
return lines.map((line, index) => header && index === 0 ? colors.bold(line) : line).join(`
|
|
379
|
+
`);
|
|
380
|
+
}
|
|
381
|
+
function narrow(rows, widths, limit) {
|
|
382
|
+
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
383
|
+
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
384
|
+
const floor = 8;
|
|
385
|
+
while (used() > limit) {
|
|
386
|
+
let widest = -1;
|
|
387
|
+
for (const [index, width] of widths.entries()) {
|
|
388
|
+
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
389
|
+
widest = index;
|
|
390
|
+
}
|
|
391
|
+
if (widest === -1)
|
|
392
|
+
break;
|
|
393
|
+
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
394
|
+
}
|
|
395
|
+
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
396
|
+
}
|
|
397
|
+
function printJson(value) {
|
|
398
|
+
console.log(JSON.stringify(value, undefined, 2));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// ../kit/src/text.ts
|
|
402
|
+
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
403
|
+
function distance(a, b) {
|
|
404
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
405
|
+
for (const [i, left] of [...a].entries()) {
|
|
406
|
+
const current = [i + 1];
|
|
407
|
+
for (const [j, right] of [...b].entries())
|
|
408
|
+
current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
|
|
409
|
+
previous = current;
|
|
410
|
+
}
|
|
411
|
+
return previous[b.length] ?? 0;
|
|
412
|
+
}
|
|
413
|
+
function closest(name, names) {
|
|
414
|
+
const started = names.find((known) => known.startsWith(name));
|
|
415
|
+
if (started !== undefined)
|
|
416
|
+
return started;
|
|
417
|
+
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
418
|
+
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// ../kit/src/args.ts
|
|
422
|
+
function jsonOption(holds) {
|
|
423
|
+
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
class Exit extends Error {
|
|
427
|
+
code;
|
|
428
|
+
hint;
|
|
429
|
+
constructor(message, code, hint) {
|
|
430
|
+
super(message);
|
|
431
|
+
this.code = code;
|
|
432
|
+
this.hint = hint;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function fail(message, code = 2, hint) {
|
|
436
|
+
throw new Exit(message, code, hint);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
class UsageError extends Exit {
|
|
440
|
+
constructor(message, hint) {
|
|
441
|
+
super(message, 2, hint);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
function badUsage(message) {
|
|
445
|
+
throw new UsageError(message);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
class HelpShown extends Exit {
|
|
449
|
+
constructor() {
|
|
450
|
+
super("help shown", 0);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
class Completing {
|
|
455
|
+
options;
|
|
456
|
+
constructor(options) {
|
|
457
|
+
this.options = options;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
var completion = { active: false };
|
|
461
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
462
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
463
|
+
var FULL_STOP = /\.$/;
|
|
464
|
+
var DASHES = /^-+/;
|
|
465
|
+
function usageLine(usage, colors = paint(process4.stdout)) {
|
|
466
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
467
|
+
}
|
|
468
|
+
function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces } = {}) {
|
|
469
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
470
|
+
`);
|
|
471
|
+
}
|
|
472
|
+
function replacesRows(replaces, colors = paint(process4.stdout)) {
|
|
473
|
+
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
474
|
+
}
|
|
475
|
+
function wantsHelpJson(env = process4.env) {
|
|
476
|
+
return env.KIT_HELP === "json";
|
|
477
|
+
}
|
|
478
|
+
function description(usage, { examples = [], replaces } = {}) {
|
|
479
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
480
|
+
`);
|
|
481
|
+
const first = lines[0];
|
|
482
|
+
const colon = first.indexOf(": ");
|
|
483
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
484
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
485
|
+
return {
|
|
486
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
487
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
488
|
+
...replaces === undefined ? {} : { replaces },
|
|
489
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function exampleRows(examples, colors = paint(process4.stdout)) {
|
|
493
|
+
if (examples.length === 0)
|
|
494
|
+
return [];
|
|
495
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
496
|
+
}
|
|
497
|
+
function optionRows(options, colors = paint(process4.stdout)) {
|
|
498
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
499
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
500
|
+
const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
|
|
501
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
|
|
502
|
+
});
|
|
503
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
504
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
505
|
+
}
|
|
506
|
+
var OUTPUT_OPTIONS = {
|
|
507
|
+
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
508
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
509
|
+
};
|
|
510
|
+
function applyOutput(color, plain, env = process4.env) {
|
|
511
|
+
const when = plain === true ? "never" : color ?? "auto";
|
|
512
|
+
if (when === "auto")
|
|
513
|
+
return;
|
|
514
|
+
if (when !== "always" && when !== "never")
|
|
515
|
+
badUsage(`--color takes auto, always or never, not ${when}`);
|
|
516
|
+
if (when === "always") {
|
|
517
|
+
env.FORCE_COLOR = "1";
|
|
518
|
+
delete env.NO_COLOR;
|
|
519
|
+
} else {
|
|
520
|
+
env.NO_COLOR = "1";
|
|
521
|
+
delete env.FORCE_COLOR;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function parse(args, usage, options, settings = {}) {
|
|
525
|
+
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
526
|
+
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
527
|
+
if (completion.active)
|
|
528
|
+
throw new Completing(all);
|
|
529
|
+
const separator = settings.rest === true ? args.indexOf("--") : -1;
|
|
530
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
531
|
+
const rest = separator === -1 ? undefined : args.slice(separator + 1);
|
|
532
|
+
let parsed;
|
|
533
|
+
try {
|
|
534
|
+
parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
535
|
+
} catch (error) {
|
|
536
|
+
const message = parseError(error);
|
|
537
|
+
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
538
|
+
}
|
|
539
|
+
const values = parsed.values;
|
|
540
|
+
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
541
|
+
if (values.help === true) {
|
|
542
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, all, undefined, settings));
|
|
543
|
+
throw new HelpShown;
|
|
544
|
+
}
|
|
545
|
+
if (settings.positionals !== undefined)
|
|
546
|
+
checkPositionals(parsed.positionals, settings.positionals);
|
|
547
|
+
return { ...parsed, positionals: parsed.positionals, rest };
|
|
548
|
+
}
|
|
549
|
+
function checkPositionals(given, names) {
|
|
550
|
+
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
551
|
+
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
552
|
+
if (given.length < required)
|
|
553
|
+
badUsage(`missing ${names[given.length]}`);
|
|
554
|
+
if (!variadic && given.length > names.length)
|
|
555
|
+
badUsage(`unexpected argument ${given[names.length]}`);
|
|
556
|
+
}
|
|
557
|
+
function joinDashValues(args, options) {
|
|
558
|
+
const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
|
|
559
|
+
const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
|
|
560
|
+
const joined = [];
|
|
561
|
+
for (let i = 0;i < args.length; i++) {
|
|
562
|
+
const arg = args[i] ?? "";
|
|
563
|
+
if (arg === "--")
|
|
564
|
+
return [...joined, ...args.slice(i)];
|
|
565
|
+
const name = longOf.get(arg);
|
|
566
|
+
const next = args[i + 1];
|
|
567
|
+
if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
|
|
568
|
+
joined.push(`--${name}=${next}`);
|
|
569
|
+
i++;
|
|
570
|
+
} else {
|
|
571
|
+
joined.push(arg);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return joined;
|
|
575
|
+
}
|
|
576
|
+
function parseError(error) {
|
|
577
|
+
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
578
|
+
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
579
|
+
}
|
|
580
|
+
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
581
|
+
function nearestOption(message, options, allowNegative) {
|
|
582
|
+
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
583
|
+
if (typed === undefined)
|
|
584
|
+
return;
|
|
585
|
+
const word = typed.replace(DASHES, "");
|
|
586
|
+
if (word.length < 2 && !typed.startsWith("--"))
|
|
587
|
+
return;
|
|
588
|
+
const known = Object.entries(options).flatMap(([name, option]) => [
|
|
589
|
+
...option.short === undefined ? [] : [`-${option.short}`],
|
|
590
|
+
`--${name}`,
|
|
591
|
+
...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
|
|
592
|
+
]);
|
|
593
|
+
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
594
|
+
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
595
|
+
}
|
|
596
|
+
var WHOLE = /^\d+$/;
|
|
597
|
+
function wholeNumber(value, name, fallback, min = 1) {
|
|
598
|
+
if (value === undefined)
|
|
599
|
+
return fallback;
|
|
600
|
+
const number = Number(value);
|
|
601
|
+
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
602
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
603
|
+
return number;
|
|
604
|
+
}
|
|
605
|
+
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
606
|
+
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
607
|
+
function duration(value, name, fallback, unit = "s") {
|
|
608
|
+
if (value === undefined)
|
|
609
|
+
return fallback;
|
|
610
|
+
const match = DURATION.exec(value.trim());
|
|
611
|
+
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
612
|
+
if (ms < 1)
|
|
613
|
+
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
614
|
+
return ms;
|
|
615
|
+
}
|
|
616
|
+
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
617
|
+
if (path === "-") {
|
|
618
|
+
if (process4.stdin.isTTY)
|
|
619
|
+
fail(noStdin);
|
|
620
|
+
return Bun.stdin.text();
|
|
621
|
+
}
|
|
622
|
+
const file = Bun.file(path);
|
|
623
|
+
if (!await file.exists())
|
|
624
|
+
fail(`no file ${path}`);
|
|
625
|
+
return file.text();
|
|
626
|
+
}
|
|
627
|
+
// ../kit/src/progress.ts
|
|
628
|
+
import process6 from "process";
|
|
629
|
+
|
|
630
|
+
// ../kit/src/process.ts
|
|
631
|
+
import { constants } from "os";
|
|
632
|
+
import process5 from "process";
|
|
633
|
+
var KILL_GRACE_MS = 2000;
|
|
634
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
635
|
+
function exitCodeOf(code, signal) {
|
|
636
|
+
if (code !== null)
|
|
637
|
+
return code;
|
|
638
|
+
if (typeof signal === "number")
|
|
639
|
+
return 128 + signal;
|
|
640
|
+
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
641
|
+
}
|
|
642
|
+
function holdSignals(cleanup) {
|
|
643
|
+
let received;
|
|
644
|
+
let child;
|
|
645
|
+
const held = {
|
|
646
|
+
get signal() {
|
|
647
|
+
return received;
|
|
648
|
+
},
|
|
649
|
+
forward: (to) => {
|
|
650
|
+
child = to;
|
|
651
|
+
},
|
|
652
|
+
release: () => {
|
|
653
|
+
for (const signal of SIGNALS)
|
|
654
|
+
process5.off(signal, onSignal);
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
function onSignal(signal) {
|
|
658
|
+
received = signal;
|
|
659
|
+
if (child !== undefined) {
|
|
660
|
+
child.kill(signal);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (cleanup === undefined)
|
|
664
|
+
return;
|
|
665
|
+
held.release();
|
|
666
|
+
cleanup(signal);
|
|
667
|
+
process5.kill(process5.pid, signal);
|
|
668
|
+
}
|
|
669
|
+
for (const signal of SIGNALS)
|
|
670
|
+
process5.on(signal, onSignal);
|
|
671
|
+
return held;
|
|
672
|
+
}
|
|
673
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
674
|
+
const chunks = [];
|
|
675
|
+
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
676
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
677
|
+
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
678
|
+
const timers = [];
|
|
679
|
+
const killGroup = (killing) => {
|
|
680
|
+
if (state.done)
|
|
681
|
+
return;
|
|
682
|
+
try {
|
|
683
|
+
if (grouped)
|
|
684
|
+
process5.kill(-proc.pid, killing);
|
|
685
|
+
else
|
|
686
|
+
proc.kill(killing);
|
|
687
|
+
} catch {}
|
|
688
|
+
};
|
|
689
|
+
const stop = () => {
|
|
690
|
+
killGroup("SIGTERM");
|
|
691
|
+
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
692
|
+
};
|
|
693
|
+
const onAbort = () => stop();
|
|
694
|
+
if (timeoutMs !== undefined) {
|
|
695
|
+
timers.push(setTimeout(() => {
|
|
696
|
+
state.timedOut = true;
|
|
697
|
+
stop();
|
|
698
|
+
}, timeoutMs));
|
|
699
|
+
}
|
|
700
|
+
if (signal?.aborted === true)
|
|
701
|
+
onAbort();
|
|
702
|
+
else
|
|
703
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
704
|
+
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
705
|
+
const drain = async (stream, name) => {
|
|
706
|
+
for await (const data of stream) {
|
|
707
|
+
if (state.failure !== undefined)
|
|
708
|
+
continue;
|
|
709
|
+
try {
|
|
710
|
+
onChunk?.({ stream: name, data });
|
|
711
|
+
} catch (error) {
|
|
712
|
+
state.failure = error;
|
|
713
|
+
stop();
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
if (state.kept + data.length > maxBytes) {
|
|
717
|
+
state.truncated = true;
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
state.kept += data.length;
|
|
721
|
+
chunks.push({ stream: name, data });
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
try {
|
|
725
|
+
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
726
|
+
await proc.exited;
|
|
727
|
+
} finally {
|
|
728
|
+
state.done = true;
|
|
729
|
+
for (const timer of timers)
|
|
730
|
+
clearTimeout(timer);
|
|
731
|
+
signal?.removeEventListener("abort", onAbort);
|
|
732
|
+
}
|
|
733
|
+
if (state.failure !== undefined)
|
|
734
|
+
throw state.failure;
|
|
735
|
+
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
736
|
+
let output;
|
|
737
|
+
let text;
|
|
738
|
+
return {
|
|
739
|
+
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
740
|
+
chunks,
|
|
741
|
+
timedOut: state.timedOut,
|
|
742
|
+
truncated: state.truncated,
|
|
743
|
+
get output() {
|
|
744
|
+
return output ??= joined();
|
|
745
|
+
},
|
|
746
|
+
get text() {
|
|
747
|
+
return text ??= (output ??= joined()).toString();
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// ../kit/src/progress.ts
|
|
753
|
+
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
754
|
+
var FRAME_MS = 200;
|
|
755
|
+
var CLEAR_LINE = "\r\x1B[2K";
|
|
756
|
+
var LINE_UP = "\x1B[1A\x1B[2K";
|
|
757
|
+
var ESC = String.fromCharCode(27);
|
|
758
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
759
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
760
|
+
var CTRL_C = 3;
|
|
761
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
762
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
763
|
+
function liveRegion(render, stream = process6.stderr, env = process6.env) {
|
|
764
|
+
if (!takesControlCodes(stream, env))
|
|
765
|
+
return { redraw: () => {
|
|
766
|
+
return;
|
|
767
|
+
}, print: (text) => void stream.write(`${text}
|
|
768
|
+
`), stop: () => {
|
|
769
|
+
return;
|
|
770
|
+
} };
|
|
771
|
+
const write = stream.write.bind(stream);
|
|
772
|
+
let frame = 0;
|
|
773
|
+
let drawn = 0;
|
|
774
|
+
const clear = () => {
|
|
775
|
+
if (drawn > 0)
|
|
776
|
+
write(`${CLEAR_LINE}${LINE_UP.repeat(drawn - 1)}`);
|
|
777
|
+
drawn = 0;
|
|
778
|
+
};
|
|
779
|
+
const draw = () => {
|
|
780
|
+
const width = (stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns) - 1;
|
|
781
|
+
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
782
|
+
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
783
|
+
if (lines.length === 0) {
|
|
784
|
+
clear();
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
write(`${drawn > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(drawn - 1)}` : CLEAR_LINE}${lines.join(`
|
|
788
|
+
`)}`);
|
|
789
|
+
drawn = lines.length;
|
|
790
|
+
};
|
|
791
|
+
const timer = setInterval(draw, FRAME_MS);
|
|
792
|
+
const restore = interceptOutput(clear);
|
|
793
|
+
const release = swallowInput();
|
|
794
|
+
const onExit = () => {
|
|
795
|
+
clear();
|
|
796
|
+
release();
|
|
797
|
+
};
|
|
798
|
+
const signals = holdSignals(stop);
|
|
799
|
+
function stop() {
|
|
800
|
+
clearInterval(timer);
|
|
801
|
+
clear();
|
|
802
|
+
restore();
|
|
803
|
+
release();
|
|
804
|
+
process6.off("exit", onExit);
|
|
805
|
+
signals.release();
|
|
806
|
+
}
|
|
807
|
+
timer.unref();
|
|
808
|
+
process6.on("exit", onExit);
|
|
809
|
+
return {
|
|
810
|
+
redraw: draw,
|
|
811
|
+
print: (text) => {
|
|
812
|
+
clear();
|
|
813
|
+
write(`${text}
|
|
814
|
+
`);
|
|
815
|
+
draw();
|
|
816
|
+
},
|
|
817
|
+
stop
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
function cutToWidth(line, width) {
|
|
821
|
+
if (Bun.stringWidth(line) <= width)
|
|
822
|
+
return line;
|
|
823
|
+
let room = width;
|
|
824
|
+
let kept = "";
|
|
825
|
+
let index = 0;
|
|
826
|
+
let linked = false;
|
|
827
|
+
while (index < line.length) {
|
|
828
|
+
ESCAPE_CODE.lastIndex = index;
|
|
829
|
+
const escape = ESCAPE_CODE.exec(line);
|
|
830
|
+
if (escape !== null) {
|
|
831
|
+
kept += escape[0];
|
|
832
|
+
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
833
|
+
index = ESCAPE_CODE.lastIndex;
|
|
834
|
+
continue;
|
|
835
|
+
}
|
|
836
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
837
|
+
const columns = Bun.stringWidth(char);
|
|
838
|
+
if (columns > room)
|
|
839
|
+
break;
|
|
840
|
+
kept += char;
|
|
841
|
+
room -= columns;
|
|
842
|
+
index += char.length;
|
|
843
|
+
}
|
|
844
|
+
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
845
|
+
}
|
|
846
|
+
function swallowInput() {
|
|
847
|
+
const input = process6.stdin;
|
|
848
|
+
if (!input.isTTY)
|
|
849
|
+
return () => {
|
|
850
|
+
return;
|
|
851
|
+
};
|
|
852
|
+
const onData = (data) => {
|
|
853
|
+
if (data.includes(CTRL_C))
|
|
854
|
+
process6.kill(process6.pid, "SIGINT");
|
|
855
|
+
};
|
|
856
|
+
input.setRawMode(true);
|
|
857
|
+
input.on("data", onData);
|
|
858
|
+
input.resume();
|
|
859
|
+
let released = false;
|
|
860
|
+
return () => {
|
|
861
|
+
if (released)
|
|
862
|
+
return;
|
|
863
|
+
released = true;
|
|
864
|
+
input.off("data", onData);
|
|
865
|
+
input.pause();
|
|
866
|
+
input.setRawMode(false);
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
function interceptOutput(clear) {
|
|
870
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process6.stdout, "write"], [process6.stderr, "write"]];
|
|
871
|
+
const wrapped = targets.map(([target, name]) => {
|
|
872
|
+
const original = Reflect.get(target, name);
|
|
873
|
+
const wrapper = (...args) => {
|
|
874
|
+
clear();
|
|
875
|
+
return original.apply(target, args);
|
|
876
|
+
};
|
|
877
|
+
Reflect.set(target, name, wrapper);
|
|
878
|
+
return { target, name, original, wrapper };
|
|
879
|
+
});
|
|
880
|
+
return () => {
|
|
881
|
+
for (const { target, name, original, wrapper } of wrapped) {
|
|
882
|
+
if (Reflect.get(target, name) === wrapper)
|
|
883
|
+
Reflect.set(target, name, original);
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// ../kit/src/tool.ts
|
|
889
|
+
import process7 from "process";
|
|
890
|
+
var PERMANENT = /\bHTTP (?:401|403|404)\b|unauthorized|forbidden|not found|couldn't be found|token is required/i;
|
|
891
|
+
function cwdGone() {
|
|
892
|
+
try {
|
|
893
|
+
process7.cwd();
|
|
894
|
+
return false;
|
|
895
|
+
} catch {
|
|
896
|
+
return true;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
class SpawnError extends Error {
|
|
901
|
+
missing;
|
|
902
|
+
constructor(message, missing) {
|
|
903
|
+
super(message);
|
|
904
|
+
this.missing = missing;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
function spawnFailure(command, error) {
|
|
908
|
+
const gone = cwdGone();
|
|
909
|
+
const missing = !gone && error?.code === "ENOENT";
|
|
910
|
+
return new SpawnError(`${command}: ${error instanceof Error ? error.message : String(error)}${gone ? " (the working directory was removed)" : ""}`, missing);
|
|
911
|
+
}
|
|
912
|
+
function isPermanentFailure(error) {
|
|
913
|
+
if (!(error instanceof Error))
|
|
914
|
+
return false;
|
|
915
|
+
return error instanceof SpawnError && error.missing || PERMANENT.test(error.message);
|
|
916
|
+
}
|
|
917
|
+
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
918
|
+
let ran;
|
|
919
|
+
try {
|
|
920
|
+
ran = await runCommand(argv, { env: process7.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
921
|
+
} catch (error) {
|
|
922
|
+
throw spawnFailure(label, error);
|
|
923
|
+
}
|
|
924
|
+
if (ran.timedOut)
|
|
925
|
+
throw new Error(`${label}: no answer in ${formatDuration(timeoutMs ?? 0)}`);
|
|
926
|
+
const decoder = new TextDecoder;
|
|
927
|
+
const streams = { stdout: "", stderr: "" };
|
|
928
|
+
for (const { stream, data } of ran.chunks)
|
|
929
|
+
streams[stream] += decoder.decode(data, { stream: true });
|
|
930
|
+
return { code: ran.code, ...streams };
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
// ../kit/src/ci.ts
|
|
934
|
+
var POLL = 15000;
|
|
935
|
+
async function waitForCi(wait) {
|
|
936
|
+
const { tool, short, giveUpMs, noneMs, stalledMs, pollMs = POLL } = wait;
|
|
937
|
+
const started = Date.now();
|
|
938
|
+
let seen = started;
|
|
939
|
+
let moving = started;
|
|
940
|
+
let followed = "";
|
|
941
|
+
let found;
|
|
942
|
+
const region = wait.lines === undefined ? undefined : liveRegion((spinner) => wait.lines?.(spinner, found, started) ?? []);
|
|
943
|
+
const suffix = () => found === undefined ? "" : `: ${wait.links(found)}`;
|
|
944
|
+
async function stallOf(current) {
|
|
945
|
+
try {
|
|
946
|
+
return await wait.stall?.(current);
|
|
947
|
+
} catch (error) {
|
|
948
|
+
if (error instanceof Exit || isPermanentFailure(error))
|
|
949
|
+
throw error;
|
|
950
|
+
console.warn(`${tool}: ${error instanceof Error ? error.message : String(error)}, polling again`);
|
|
951
|
+
return "unknown";
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
try {
|
|
955
|
+
for (;; ) {
|
|
956
|
+
if (Date.now() - started > giveUpMs)
|
|
957
|
+
fail(`CI has not finished on ${short} in ${formatDuration(giveUpMs)}${suffix()}`);
|
|
958
|
+
try {
|
|
959
|
+
found = await wait.covering();
|
|
960
|
+
} catch (error) {
|
|
961
|
+
if (error instanceof Exit)
|
|
962
|
+
throw error;
|
|
963
|
+
if (cwdGone())
|
|
964
|
+
fail(`the working directory was removed while waiting for CI on ${short}${suffix()}`);
|
|
965
|
+
if (isPermanentFailure(error))
|
|
966
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
967
|
+
console.warn(`${tool}: ${error instanceof Error ? error.message : String(error)}, polling again`);
|
|
968
|
+
const latest = found === undefined ? undefined : await wait.settle(found);
|
|
969
|
+
if (latest !== undefined)
|
|
970
|
+
return latest;
|
|
971
|
+
await Bun.sleep(pollMs);
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
if (found !== undefined) {
|
|
975
|
+
seen = Date.now();
|
|
976
|
+
const key = wait.key(found);
|
|
977
|
+
if (key !== followed) {
|
|
978
|
+
followed = key;
|
|
979
|
+
moving = Date.now();
|
|
980
|
+
wait.announce(found);
|
|
981
|
+
}
|
|
982
|
+
if (wait.finished(found))
|
|
983
|
+
return found;
|
|
984
|
+
const stall = await stallOf(found);
|
|
985
|
+
if (stall === undefined)
|
|
986
|
+
moving = Date.now();
|
|
987
|
+
else if (stall !== "unknown" && (stall.certain === true || Date.now() - moving > stalledMs))
|
|
988
|
+
fail(stall.message);
|
|
989
|
+
} else if (Date.now() - seen > noneMs) {
|
|
990
|
+
fail(wait.noneMessage);
|
|
991
|
+
}
|
|
992
|
+
await Bun.sleep(pollMs);
|
|
993
|
+
}
|
|
994
|
+
} finally {
|
|
995
|
+
region?.stop();
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
// ../kit/src/cli.ts
|
|
999
|
+
import process8 from "process";
|
|
1000
|
+
var LEVEL_OPTIONS = {
|
|
1001
|
+
...OUTPUT_OPTIONS,
|
|
1002
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1003
|
+
};
|
|
1004
|
+
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
1005
|
+
async function commandRows(commands, colors) {
|
|
1006
|
+
const width = Math.max(...Object.keys(commands).map((name) => name.length));
|
|
1007
|
+
const groups = new Map([["Commands:", []]]);
|
|
1008
|
+
const summaries = await Promise.all(Object.values(commands).map(async ({ summary }) => resolveSummary(summary)));
|
|
1009
|
+
for (const [index, [name, { group }]] of Object.entries(commands).entries()) {
|
|
1010
|
+
const heading = group === undefined ? "Commands:" : `${group}:`;
|
|
1011
|
+
const rows = groups.get(heading) ?? [];
|
|
1012
|
+
rows.push(` ${colors.cyan(name.padEnd(width))} ${colors.dim(summaries[index])}`);
|
|
1013
|
+
groups.set(heading, rows);
|
|
1014
|
+
}
|
|
1015
|
+
return [...groups].filter(([, rows]) => rows.length > 0).flatMap(([heading, rows], index) => [...index === 0 ? [] : [""], colors.bold(heading), ...rows]);
|
|
1016
|
+
}
|
|
1017
|
+
function takeOutputFlags(argv) {
|
|
1018
|
+
let index = 0;
|
|
1019
|
+
for (;index < argv.length; index++) {
|
|
1020
|
+
const word = argv[index];
|
|
1021
|
+
if (word === "--plain")
|
|
1022
|
+
applyOutput(undefined, true);
|
|
1023
|
+
else if (word.startsWith("--color="))
|
|
1024
|
+
applyOutput(word.slice("--color=".length), undefined);
|
|
1025
|
+
else if (word === "--color" && argv[index + 1] !== undefined)
|
|
1026
|
+
applyOutput(argv[++index], undefined);
|
|
1027
|
+
else
|
|
1028
|
+
break;
|
|
1029
|
+
}
|
|
1030
|
+
return argv.slice(index);
|
|
1031
|
+
}
|
|
1032
|
+
async function resolveSummary(summary) {
|
|
1033
|
+
return typeof summary === "string" ? summary : summary();
|
|
1034
|
+
}
|
|
1035
|
+
function scopeOf(commands, extra, aliases) {
|
|
1036
|
+
return { commands: typeof commands === "function" ? {} : commands, lazy: [...typeof commands === "function" ? [commands] : [], ...extra === undefined ? [] : [extra]], aliases };
|
|
1037
|
+
}
|
|
1038
|
+
async function expand(scope, words) {
|
|
1039
|
+
if (scope.lazy.length === 0)
|
|
1040
|
+
return scope;
|
|
1041
|
+
const commands = { ...scope.commands };
|
|
1042
|
+
for (const added of await Promise.all(scope.lazy.map(async (lazy) => lazy(words)))) {
|
|
1043
|
+
for (const [name, command] of Object.entries(added))
|
|
1044
|
+
commands[name] ??= command;
|
|
1045
|
+
}
|
|
1046
|
+
return { ...scope, commands, lazy: [] };
|
|
1047
|
+
}
|
|
1048
|
+
async function help({ path, header, summary: lazySummary, commands, defaultCommand, examples, replaces }, stream) {
|
|
1049
|
+
const colors = paint(stream);
|
|
1050
|
+
const prefix = path.join(" ");
|
|
1051
|
+
const summary = await resolveSummary(lazySummary);
|
|
1052
|
+
if (wantsHelpJson())
|
|
1053
|
+
return JSON.stringify(description(`${prefix} <command> [options]: ${summary}`, { examples, replaces }));
|
|
1054
|
+
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1055
|
+
const options = fallback !== undefined && "run" in fallback ? await optionsOf(fallback.run) : undefined;
|
|
1056
|
+
const own = Object.entries(options ?? {}).filter(([name]) => !(name in TOP_OPTIONS));
|
|
1057
|
+
return [
|
|
1058
|
+
header(colors, summary),
|
|
1059
|
+
"",
|
|
1060
|
+
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1061
|
+
...replacesRows(replaces, colors),
|
|
1062
|
+
"",
|
|
1063
|
+
...await commandRows(commands, colors),
|
|
1064
|
+
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
1065
|
+
"",
|
|
1066
|
+
colors.bold("Options:"),
|
|
1067
|
+
...optionRows(path.length === 1 ? TOP_OPTIONS : LEVEL_OPTIONS, colors),
|
|
1068
|
+
...exampleRows(examples ?? [], colors),
|
|
1069
|
+
"",
|
|
1070
|
+
`${colors.dim("Run")} ${prefix} ${colors.cyan("<command>")} --help ${colors.dim("for its options.")}`
|
|
1071
|
+
].join(`
|
|
1072
|
+
`);
|
|
1073
|
+
}
|
|
1074
|
+
function printError(prefix, message, hint, cause) {
|
|
1075
|
+
const colors = paint(process8.stderr);
|
|
1076
|
+
const styled = takesControlCodes(process8.stderr);
|
|
1077
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1078
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1079
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
1080
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1081
|
+
}
|
|
1082
|
+
function runHint(command, effect) {
|
|
1083
|
+
return `run \`${command}\`${effect === undefined ? "" : ` to ${effect}`}`;
|
|
1084
|
+
}
|
|
1085
|
+
function printHint(hint) {
|
|
1086
|
+
const colors = paint(process8.stderr);
|
|
1087
|
+
console.error(` ${takesControlCodes(process8.stderr) ? colors.yellow("hint") : "hint:"} ${hint}`);
|
|
1088
|
+
}
|
|
1089
|
+
function printJsonError(message, hint, cause) {
|
|
1090
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
1091
|
+
}
|
|
1092
|
+
function wantsJson(argv) {
|
|
1093
|
+
const end = argv.indexOf("--");
|
|
1094
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
1095
|
+
}
|
|
1096
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
1097
|
+
if (error instanceof HelpShown)
|
|
1098
|
+
return 0;
|
|
1099
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
1100
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
1101
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
1102
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
1103
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
1104
|
+
return error instanceof Exit ? error.code : 1;
|
|
1105
|
+
}
|
|
1106
|
+
async function dispatch(level, typed, { version, redact }) {
|
|
1107
|
+
const prefix = level.path.join(" ");
|
|
1108
|
+
let argv;
|
|
1109
|
+
try {
|
|
1110
|
+
argv = takeOutputFlags(typed);
|
|
1111
|
+
} catch (error) {
|
|
1112
|
+
return reportThrown(prefix, error);
|
|
1113
|
+
}
|
|
1114
|
+
const [name, ...args] = argv;
|
|
1115
|
+
if (name === undefined && level.path.length > 1) {
|
|
1116
|
+
console.error(await help(await expand(level, [...level.path.slice(1), ...argv]), process8.stderr));
|
|
1117
|
+
return 2;
|
|
1118
|
+
}
|
|
1119
|
+
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1120
|
+
console.log(await help(await expand(level, [...level.path.slice(1), ...argv]), process8.stdout));
|
|
1121
|
+
return 0;
|
|
1122
|
+
}
|
|
1123
|
+
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
1124
|
+
console.log(version);
|
|
1125
|
+
return 0;
|
|
1126
|
+
}
|
|
1127
|
+
let command = level.commands[level.aliases?.[name] ?? name];
|
|
1128
|
+
let rest = args;
|
|
1129
|
+
if (command === undefined && level.lazy.length > 0) {
|
|
1130
|
+
level = await expand(level, [...level.path.slice(1), ...argv]);
|
|
1131
|
+
command = level.commands[level.aliases?.[name] ?? name];
|
|
1132
|
+
}
|
|
1133
|
+
if (command === undefined && level.defaultCommand !== undefined) {
|
|
1134
|
+
command = level.commands[level.defaultCommand];
|
|
1135
|
+
rest = argv;
|
|
1136
|
+
}
|
|
1137
|
+
if (command === undefined) {
|
|
1138
|
+
const meant = closest(name, Object.keys(level.commands));
|
|
1139
|
+
printError(prefix, `no command ${name}`, meant === undefined ? `run ${prefix} --help for its commands` : `did you mean ${meant}?`);
|
|
1140
|
+
return 2;
|
|
1141
|
+
}
|
|
1142
|
+
if ("commands" in command) {
|
|
1143
|
+
const { summary } = command;
|
|
1144
|
+
return dispatch({ path: [...level.path, name], header: (colors, text) => `${colors.bold(`${prefix} ${name}`)} ${text}`, summary, ...scopeOf(command.commands, command.extraCommands, command.aliases), defaultCommand: undefined, examples: command.examples, replaces: undefined }, rest, { version, redact });
|
|
1145
|
+
}
|
|
1146
|
+
try {
|
|
1147
|
+
return await command.run(rest);
|
|
1148
|
+
} catch (error) {
|
|
1149
|
+
return reportThrown(`${prefix} ${name}`, error, redact, wantsJson(rest));
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
var COMPLETE = "__complete";
|
|
1153
|
+
var FILES = "__files__";
|
|
1154
|
+
async function optionsOf(run) {
|
|
1155
|
+
completion.active = true;
|
|
1156
|
+
try {
|
|
1157
|
+
await run([]);
|
|
1158
|
+
} catch (error) {
|
|
1159
|
+
if (error instanceof Completing)
|
|
1160
|
+
return error.options;
|
|
1161
|
+
} finally {
|
|
1162
|
+
completion.active = false;
|
|
1163
|
+
}
|
|
1164
|
+
return {};
|
|
1165
|
+
}
|
|
1166
|
+
async function leafCandidates(run, words) {
|
|
1167
|
+
if (!(words.at(-1) ?? "").startsWith("-"))
|
|
1168
|
+
return [FILES];
|
|
1169
|
+
return Object.entries(await optionsOf(run)).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1170
|
+
}
|
|
1171
|
+
async function candidates(scope, defaultCommand, words, before = []) {
|
|
1172
|
+
const [word = "", ...rest] = words;
|
|
1173
|
+
const listing = rest.length === 0 && !word.startsWith("-");
|
|
1174
|
+
let { commands, aliases } = scope;
|
|
1175
|
+
let command = commands[aliases?.[word] ?? word];
|
|
1176
|
+
if (listing || command === undefined) {
|
|
1177
|
+
({ commands, aliases } = await expand(scope, [...before, ...words]));
|
|
1178
|
+
command = commands[aliases?.[word] ?? word];
|
|
1179
|
+
}
|
|
1180
|
+
if (listing)
|
|
1181
|
+
return Promise.all(Object.entries(commands).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
|
|
1182
|
+
if (command === undefined) {
|
|
1183
|
+
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1184
|
+
return fallback !== undefined && "run" in fallback ? leafCandidates(fallback.run, words) : [];
|
|
1185
|
+
}
|
|
1186
|
+
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1187
|
+
}
|
|
1188
|
+
async function printCandidates(found) {
|
|
1189
|
+
for (const line of await found)
|
|
1190
|
+
console.log(line);
|
|
1191
|
+
return 0;
|
|
1192
|
+
}
|
|
1193
|
+
async function runCli(cli, argv = process8.argv.slice(2)) {
|
|
1194
|
+
if (argv[0] === COMPLETE)
|
|
1195
|
+
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1196
|
+
return dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(cli.version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, examples: cli.examples, replaces: cli.replaces }, argv, { version: cli.version, redact: cli.redact });
|
|
1197
|
+
}
|
|
1198
|
+
// ../kit/src/git.ts
|
|
1199
|
+
import { basename, dirname } from "path";
|
|
1200
|
+
import process9 from "process";
|
|
1201
|
+
var ORIGIN_PREFIX = /^origin\//;
|
|
1202
|
+
var GIT_NETWORK_MS = 60000;
|
|
1203
|
+
async function git(args, timeoutMs) {
|
|
1204
|
+
const result = await runTool(`git ${args.join(" ")}`, ["git", ...args], { timeoutMs });
|
|
1205
|
+
if (result.code !== 0)
|
|
1206
|
+
throw new Error(`git ${args.join(" ")}: ${result.stderr.trim() || `exit ${result.code}`}${cwdGone() ? " (the working directory was removed)" : ""}`);
|
|
1207
|
+
return result.stdout.trim();
|
|
1208
|
+
}
|
|
1209
|
+
async function gitOk(args) {
|
|
1210
|
+
return (await runTool(`git ${args.join(" ")}`, ["git", ...args])).code === 0;
|
|
1211
|
+
}
|
|
1212
|
+
async function resolveCommit(ref) {
|
|
1213
|
+
const sha = (await runTool("git rev-parse", ["git", "rev-parse", "--verify", "-q", "--end-of-options", `${ref}^{commit}`])).stdout.trim();
|
|
1214
|
+
if (sha === "")
|
|
1215
|
+
fail(`no commit ${ref}`);
|
|
1216
|
+
return sha;
|
|
1217
|
+
}
|
|
1218
|
+
async function fetchBranch(branch) {
|
|
1219
|
+
if (branch.startsWith("-") || !await gitOk(["check-ref-format", "--branch", branch]))
|
|
1220
|
+
fail(`${branch} is not a branch name`);
|
|
1221
|
+
await git(["fetch", "-q", "origin", `refs/heads/${branch}`], GIT_NETWORK_MS);
|
|
1222
|
+
}
|
|
1223
|
+
async function defaultBranch() {
|
|
1224
|
+
const head = (await runTool("git symbolic-ref", ["git", "symbolic-ref", "--short", "-q", "refs/remotes/origin/HEAD"])).stdout.trim();
|
|
1225
|
+
return head === "" ? "main" : head.replace(ORIGIN_PREFIX, "");
|
|
1226
|
+
}
|
|
1227
|
+
async function leaveWorktree() {
|
|
1228
|
+
const common = await git(["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
1229
|
+
if (basename(common) === ".git")
|
|
1230
|
+
process9.chdir(dirname(common));
|
|
1231
|
+
}
|
|
1232
|
+
// ../kit/src/limit.ts
|
|
1233
|
+
function limitOptions(fallback) {
|
|
1234
|
+
return {
|
|
1235
|
+
limit: { type: "string", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
1236
|
+
full: { type: "boolean", description: "show every row" }
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
function limitOf(values, fallback) {
|
|
1240
|
+
if (values.full === true && values.limit !== undefined)
|
|
1241
|
+
badUsage("--limit and --full exclude each other");
|
|
1242
|
+
if (values.full === true || values.json === true && values.limit === undefined)
|
|
1243
|
+
return Number.POSITIVE_INFINITY;
|
|
1244
|
+
return wholeNumber(values.limit, "limit", fallback);
|
|
1245
|
+
}
|
|
1246
|
+
function moreFooter(more) {
|
|
1247
|
+
return `${more} more, rerun with --full`;
|
|
1248
|
+
}
|
|
1249
|
+
function capped(rows, limit) {
|
|
1250
|
+
const more = rows.length - limit;
|
|
1251
|
+
return more > 0 ? { shown: rows.slice(0, limit), footer: moreFooter(more) } : { shown: [...rows], footer: undefined };
|
|
1252
|
+
}
|
|
1253
|
+
// ../kit/src/logs.ts
|
|
1254
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1255
|
+
// ../kit/src/secrets.ts
|
|
1256
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1257
|
+
// ../kit/src/sessions.ts
|
|
1258
|
+
import { homedir } from "os";
|
|
1259
|
+
import { join } from "path";
|
|
1260
|
+
import process10 from "process";
|
|
1261
|
+
var {Glob } = globalThis.Bun;
|
|
1262
|
+
var SESSION_FILES = new Glob("*.json");
|
|
1263
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1264
|
+
async function sessionDirs() {
|
|
1265
|
+
const home = homedir();
|
|
1266
|
+
const dirs = new Set([join(home, ".claude", "sessions")]);
|
|
1267
|
+
if (process10.env.CLAUDE_CONFIG_DIR !== undefined)
|
|
1268
|
+
dirs.add(join(process10.env.CLAUDE_CONFIG_DIR, "sessions"));
|
|
1269
|
+
try {
|
|
1270
|
+
for await (const dir of ACCOUNT_DIRS.scan({ cwd: join(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
|
|
1271
|
+
dirs.add(dir);
|
|
1272
|
+
} catch {}
|
|
1273
|
+
return [...dirs];
|
|
1274
|
+
}
|
|
1275
|
+
async function procStat(pid) {
|
|
1276
|
+
try {
|
|
1277
|
+
const stat = await Bun.file(`/proc/${pid}/stat`).text();
|
|
1278
|
+
return stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
1279
|
+
} catch {
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
async function isAlive(pid, procStart) {
|
|
1284
|
+
const stat = await procStat(pid);
|
|
1285
|
+
if (stat === undefined)
|
|
1286
|
+
return false;
|
|
1287
|
+
return procStart === undefined || stat[19] === procStart;
|
|
1288
|
+
}
|
|
1289
|
+
async function liveSessions() {
|
|
1290
|
+
const sessions = new Map;
|
|
1291
|
+
for (const dir of await sessionDirs()) {
|
|
1292
|
+
let files;
|
|
1293
|
+
try {
|
|
1294
|
+
files = await Array.fromAsync(SESSION_FILES.scan({ cwd: dir, absolute: true }));
|
|
1295
|
+
} catch {
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
for (const file of files) {
|
|
1299
|
+
let entry;
|
|
1300
|
+
try {
|
|
1301
|
+
entry = await Bun.file(file).json();
|
|
1302
|
+
} catch {
|
|
1303
|
+
continue;
|
|
1304
|
+
}
|
|
1305
|
+
if (entry.name === undefined || entry.pid === undefined || sessions.has(entry.pid) || !await isAlive(entry.pid, entry.procStart))
|
|
1306
|
+
continue;
|
|
1307
|
+
sessions.set(entry.pid, { name: entry.name, pid: entry.pid, status: entry.status ?? "unknown", cwd: entry.cwd ?? "" });
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
return [...sessions.values()];
|
|
1311
|
+
}
|
|
1312
|
+
async function currentSession(sessions) {
|
|
1313
|
+
const byPid = new Map(sessions.map((session) => [session.pid, session]));
|
|
1314
|
+
let pid = process10.ppid;
|
|
1315
|
+
for (let depth = 0;depth < 32 && pid > 1; depth++) {
|
|
1316
|
+
const session = byPid.get(pid);
|
|
1317
|
+
if (session !== undefined)
|
|
1318
|
+
return session;
|
|
1319
|
+
const parent = Number((await procStat(pid))?.[1]);
|
|
1320
|
+
if (!Number.isInteger(parent))
|
|
1321
|
+
return;
|
|
1322
|
+
pid = parent;
|
|
1323
|
+
}
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
// package.json
|
|
1327
|
+
var version = "0.10.0";
|
|
1328
|
+
|
|
1329
|
+
// src/args.ts
|
|
1330
|
+
var repoOption = {
|
|
1331
|
+
repo: { type: "string", short: "r", description: "owner/name of the repository, instead of the one origin points at" }
|
|
1332
|
+
};
|
|
1333
|
+
var ISSUE_HASH = /^#/;
|
|
1334
|
+
function issueNumber(value, usage) {
|
|
1335
|
+
if (value === undefined)
|
|
1336
|
+
fail(`an issue number is needed
|
|
1337
|
+
|
|
1338
|
+
${usage}`);
|
|
1339
|
+
return wholeNumber(value.replace(ISSUE_HASH, ""), "<issue>", 0);
|
|
1340
|
+
}
|
|
1341
|
+
function issueNumbers(values, usage) {
|
|
1342
|
+
return values.length === 0 ? [issueNumber(undefined, usage)] : values.map((value) => issueNumber(value, usage));
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// src/checklist.ts
|
|
1346
|
+
var BOX = /^(\s*[-*+] \[)([ x])(\]\s)(.*?)\r?$/is;
|
|
1347
|
+
var FENCE = /^\s*(`{3,}|~{3,})/;
|
|
1348
|
+
var LIST_ITEM = /^\s*(?:[-*+]|\d+[.)])\s/;
|
|
1349
|
+
var INDENT_CODE = /^(?: {4}|\t)/;
|
|
1350
|
+
function boxes(body) {
|
|
1351
|
+
const found = [];
|
|
1352
|
+
let fence;
|
|
1353
|
+
let inList = false;
|
|
1354
|
+
for (const [line, text] of body.split(`
|
|
1355
|
+
`).entries()) {
|
|
1356
|
+
const marker = FENCE.exec(text)?.[1];
|
|
1357
|
+
if (fence !== undefined) {
|
|
1358
|
+
if (marker?.startsWith(fence[0] ?? "") === true && marker.length >= fence.length && text.trim() === marker)
|
|
1359
|
+
fence = undefined;
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
if (marker !== undefined) {
|
|
1363
|
+
fence = marker;
|
|
1364
|
+
continue;
|
|
1365
|
+
}
|
|
1366
|
+
const blank = text.trim() === "";
|
|
1367
|
+
const match = INDENT_CODE.test(text) && !inList ? null : BOX.exec(text);
|
|
1368
|
+
if (match !== null)
|
|
1369
|
+
found.push({ number: found.length + 1, line, done: match[2] !== " ", text: match[4] ?? "" });
|
|
1370
|
+
if (LIST_ITEM.test(text))
|
|
1371
|
+
inList = true;
|
|
1372
|
+
else if (!blank && !text.startsWith(" ") && !text.startsWith("\t"))
|
|
1373
|
+
inList = false;
|
|
1374
|
+
}
|
|
1375
|
+
return found;
|
|
1376
|
+
}
|
|
1377
|
+
var INDENT = /^\s*/;
|
|
1378
|
+
function appendBoxes(body, texts) {
|
|
1379
|
+
const end = body.includes(`\r
|
|
1380
|
+
`) ? "\r" : "";
|
|
1381
|
+
const last = boxes(body).at(-1);
|
|
1382
|
+
const lines = body.split(`
|
|
1383
|
+
`);
|
|
1384
|
+
const indent = last === undefined ? "" : INDENT.exec(lines[last.line] ?? "")?.[0] ?? "";
|
|
1385
|
+
const added = texts.map((text) => `${indent}- [ ] ${text}${end}`);
|
|
1386
|
+
if (last === undefined)
|
|
1387
|
+
return body.trim() === "" ? added.join(`
|
|
1388
|
+
`) : `${body.trimEnd()}${end}
|
|
1389
|
+
${end}
|
|
1390
|
+
${added.join(`
|
|
1391
|
+
`)}`;
|
|
1392
|
+
lines.splice(last.line + 1, 0, ...added);
|
|
1393
|
+
return lines.join(`
|
|
1394
|
+
`);
|
|
1395
|
+
}
|
|
1396
|
+
function numberedBody(body) {
|
|
1397
|
+
const lines = body.replaceAll(`\r
|
|
1398
|
+
`, `
|
|
1399
|
+
`).split(`
|
|
1400
|
+
`);
|
|
1401
|
+
for (const box of boxes(body))
|
|
1402
|
+
lines[box.line] = `${INDENT.exec(lines[box.line] ?? "")?.[0] ?? ""}${box.number} [${box.done ? "x" : " "}] ${box.text}`;
|
|
1403
|
+
return lines.join(`
|
|
1404
|
+
`).trim();
|
|
1405
|
+
}
|
|
1406
|
+
var NUMBERED_PICK = /^(\d+):(.+)$/s;
|
|
1407
|
+
var WHOLE_PICK = /^\d+$/;
|
|
1408
|
+
function setBoxes(body, picks, done) {
|
|
1409
|
+
const all = boxes(body);
|
|
1410
|
+
const chosen = new Map;
|
|
1411
|
+
for (const pick of picks) {
|
|
1412
|
+
if (pick.trim() === "")
|
|
1413
|
+
throw new Error("an empty box pick matches every box");
|
|
1414
|
+
const guarded = NUMBERED_PICK.exec(pick);
|
|
1415
|
+
const needle = (guarded?.[2] ?? pick).trim().toLowerCase();
|
|
1416
|
+
const matches = guarded === null && !WHOLE_PICK.test(pick) ? all.filter((box) => box.text.toLowerCase().includes(needle)) : all.filter((box) => box.number === Number(guarded?.[1] ?? pick) && (guarded === null || box.text.toLowerCase().startsWith(needle)));
|
|
1417
|
+
if (matches.length === 0)
|
|
1418
|
+
throw new Error(`no box matches ${pick}`);
|
|
1419
|
+
if (matches.length > 1)
|
|
1420
|
+
throw new Error(`${pick} matches ${matches.length} boxes: ${matches.map((box) => box.number).join(", ")}`);
|
|
1421
|
+
const [box] = matches;
|
|
1422
|
+
if (box !== undefined)
|
|
1423
|
+
chosen.set(box.number, box);
|
|
1424
|
+
}
|
|
1425
|
+
const lines = body.split(`
|
|
1426
|
+
`);
|
|
1427
|
+
const changed = [];
|
|
1428
|
+
for (const box of chosen.values()) {
|
|
1429
|
+
if (box.done === done)
|
|
1430
|
+
continue;
|
|
1431
|
+
const line = lines[box.line] ?? "";
|
|
1432
|
+
lines[box.line] = line.replace(BOX, `$1${done ? "x" : " "}$3$4`) + (line.endsWith("\r") ? "\r" : "");
|
|
1433
|
+
changed.push({ ...box, done });
|
|
1434
|
+
}
|
|
1435
|
+
return { body: lines.join(`
|
|
1436
|
+
`), changed };
|
|
1437
|
+
}
|
|
1438
|
+
var REFERENCE = /^#(\d+)(?!\d)/;
|
|
1439
|
+
function referencedBoxes(body) {
|
|
1440
|
+
const found = [];
|
|
1441
|
+
for (const box of boxes(body)) {
|
|
1442
|
+
const match = REFERENCE.exec(box.text);
|
|
1443
|
+
if (match?.[1] !== undefined)
|
|
1444
|
+
found.push({ box, issue: Number(match[1]) });
|
|
1445
|
+
}
|
|
1446
|
+
return found;
|
|
1447
|
+
}
|
|
1448
|
+
function tickReferences(body, wanted) {
|
|
1449
|
+
const picks = referencedBoxes(body).filter(({ box, issue }) => !box.done && wanted(issue)).map(({ box }) => String(box.number));
|
|
1450
|
+
return setBoxes(body, picks, true);
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
// src/claims.ts
|
|
1454
|
+
var TAKEN = /^\s*taken by session ([\w.@:-]+?)\.?\s*$/i;
|
|
1455
|
+
var RELEASED = /^\s*released by session ([\w.@:-]+?)\.?\s*$/i;
|
|
1456
|
+
var LANE = /^lane-([^-]+)-/;
|
|
1457
|
+
function takenComment(name) {
|
|
1458
|
+
return `Taken by session ${name}.`;
|
|
1459
|
+
}
|
|
1460
|
+
function releasedComment(name) {
|
|
1461
|
+
return `Released by session ${name}.`;
|
|
1462
|
+
}
|
|
1463
|
+
function isClaimant(comment, author) {
|
|
1464
|
+
return author === undefined || comment.user === undefined || comment.user.login === author;
|
|
1465
|
+
}
|
|
1466
|
+
function latestClaim(comments, author) {
|
|
1467
|
+
let claim;
|
|
1468
|
+
for (const comment of comments.filter((each) => isClaimant(each, author)).sort((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at))) {
|
|
1469
|
+
const taken = TAKEN.exec(comment.body)?.[1];
|
|
1470
|
+
if (taken !== undefined) {
|
|
1471
|
+
claim = { holder: taken, at: comment.created_at };
|
|
1472
|
+
continue;
|
|
1473
|
+
}
|
|
1474
|
+
if (claim !== undefined && RELEASED.exec(comment.body)?.[1] === claim.holder)
|
|
1475
|
+
claim = undefined;
|
|
1476
|
+
}
|
|
1477
|
+
return claim;
|
|
1478
|
+
}
|
|
1479
|
+
function laneSuffix(session) {
|
|
1480
|
+
const suffix = session.slice(session.lastIndexOf("-") + 1);
|
|
1481
|
+
return session.includes("-") && suffix !== "" ? suffix : undefined;
|
|
1482
|
+
}
|
|
1483
|
+
function latestNote(comments) {
|
|
1484
|
+
return comments.filter((comment) => !TAKEN.test(comment.body) && !RELEASED.test(comment.body)).sort((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at)).at(-1);
|
|
1485
|
+
}
|
|
1486
|
+
function holderSession(holder, sessions) {
|
|
1487
|
+
const own = sessions.find((session) => session.name === holder);
|
|
1488
|
+
if (own !== undefined)
|
|
1489
|
+
return own;
|
|
1490
|
+
const lane = LANE.exec(holder)?.[1];
|
|
1491
|
+
return lane === undefined ? undefined : sessions.find((session) => session.name.endsWith(`-${lane}`));
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
// src/tea.ts
|
|
1495
|
+
var TEA_MS = 60000;
|
|
1496
|
+
function repoFlag(repo) {
|
|
1497
|
+
return repo === undefined ? [] : ["--repo", repo];
|
|
1498
|
+
}
|
|
1499
|
+
async function request(path, repo) {
|
|
1500
|
+
const result = await runTool(`tea api ${path}`, ["tea", "api", ...repoFlag(repo), path], { timeoutMs: TEA_MS });
|
|
1501
|
+
if (result.code !== 0)
|
|
1502
|
+
throw new Error(`tea api ${path}: ${result.stderr.trim() || `exit ${result.code}`}`);
|
|
1503
|
+
return result.stdout;
|
|
1504
|
+
}
|
|
1505
|
+
function parseJson(path, text) {
|
|
1506
|
+
let value;
|
|
1507
|
+
try {
|
|
1508
|
+
value = JSON.parse(text);
|
|
1509
|
+
} catch {
|
|
1510
|
+
throw new Error(`tea api ${path}: ${upTo(text.trim(), `
|
|
1511
|
+
`) || "empty answer"}`);
|
|
1512
|
+
}
|
|
1513
|
+
const failure = apiError(value);
|
|
1514
|
+
if (failure !== undefined)
|
|
1515
|
+
throw new Error(`tea api ${path}: ${failure}`);
|
|
1516
|
+
return value;
|
|
1517
|
+
}
|
|
1518
|
+
function apiError(value) {
|
|
1519
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value) && "message" in value && typeof value.message === "string" && "url" in value)
|
|
1520
|
+
return value.message;
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1523
|
+
async function api(path, repo) {
|
|
1524
|
+
return parseJson(path, await request(path, repo));
|
|
1525
|
+
}
|
|
1526
|
+
async function repoApi(path, repo) {
|
|
1527
|
+
return api(`repos/{owner}/{repo}/${path}`, repo);
|
|
1528
|
+
}
|
|
1529
|
+
async function repoWrite(method, path, fields, repo) {
|
|
1530
|
+
const full = `repos/{owner}/{repo}/${path}`;
|
|
1531
|
+
const flags = Object.entries(fields).flatMap(([name, value]) => ["-f", `${name}=${value}`]);
|
|
1532
|
+
const result = await runTool(`tea api ${full}`, ["tea", "api", ...repoFlag(repo), "-X", method, ...flags, full], { timeoutMs: TEA_MS });
|
|
1533
|
+
if (result.code !== 0)
|
|
1534
|
+
throw new Error(`tea api ${full}: ${result.stderr.trim() || `exit ${result.code}`}`);
|
|
1535
|
+
return parseJson(full, result.stdout);
|
|
1536
|
+
}
|
|
1537
|
+
async function repoApiText(path, repo) {
|
|
1538
|
+
const full = `repos/{owner}/{repo}/${path}`;
|
|
1539
|
+
const text = await request(full, repo);
|
|
1540
|
+
let value;
|
|
1541
|
+
try {
|
|
1542
|
+
value = JSON.parse(text);
|
|
1543
|
+
} catch {
|
|
1544
|
+
return text;
|
|
1545
|
+
}
|
|
1546
|
+
const failure = apiError(value);
|
|
1547
|
+
if (failure !== undefined)
|
|
1548
|
+
throw new Error(`tea api ${full}: ${failure}`);
|
|
1549
|
+
return text;
|
|
1550
|
+
}
|
|
1551
|
+
async function tea(command, args, repo) {
|
|
1552
|
+
const result = await runTool(`tea ${command.join(" ")}`, ["tea", ...command, ...repoFlag(repo), ...args], { timeoutMs: TEA_MS });
|
|
1553
|
+
if (result.code !== 0)
|
|
1554
|
+
throw new Error(`tea ${command.join(" ")}: ${result.stderr.trim() || result.stdout.trim() || `exit ${result.code}`}`);
|
|
1555
|
+
return result.stdout;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
// src/issues.ts
|
|
1559
|
+
var PAGE = 50;
|
|
1560
|
+
var CONCURRENCY = 8;
|
|
1561
|
+
async function getIssue(number, repo) {
|
|
1562
|
+
return repoApi(`issues/${number}`, repo);
|
|
1563
|
+
}
|
|
1564
|
+
async function listIssues(state, filter, repo) {
|
|
1565
|
+
const issues = [];
|
|
1566
|
+
for (let page = 1;; page++) {
|
|
1567
|
+
const batch = await repoApi(`issues?state=${state}&type=issues&page=${page}&limit=${PAGE}${filter}`, repo);
|
|
1568
|
+
issues.push(...batch);
|
|
1569
|
+
if (batch.length < PAGE)
|
|
1570
|
+
return issues;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
async function openIssues(labels, repo, milestone) {
|
|
1574
|
+
return listIssues("open", `${labels === undefined ? "" : `&labels=${encodeURIComponent(labels)}`}${milestone === undefined ? "" : `&milestones=${milestone}`}`, repo);
|
|
1575
|
+
}
|
|
1576
|
+
async function closedIssues(milestone, repo) {
|
|
1577
|
+
return listIssues("closed", `&milestones=${milestone}`, repo);
|
|
1578
|
+
}
|
|
1579
|
+
async function commentsOf(number, repo) {
|
|
1580
|
+
return repoApi(`issues/${number}/comments`, repo);
|
|
1581
|
+
}
|
|
1582
|
+
async function commentsOfAll(issues, repo) {
|
|
1583
|
+
const result = new Map;
|
|
1584
|
+
const queue = issues.filter((issue) => issue.comments > 0);
|
|
1585
|
+
async function worker() {
|
|
1586
|
+
for (let issue = queue.shift();issue !== undefined; issue = queue.shift())
|
|
1587
|
+
result.set(issue.number, await commentsOf(issue.number, repo));
|
|
1588
|
+
}
|
|
1589
|
+
await Promise.all(Array.from({ length: CONCURRENCY }, worker));
|
|
1590
|
+
return result;
|
|
1591
|
+
}
|
|
1592
|
+
async function editIssue(number, change, repo) {
|
|
1593
|
+
const args = [String(number)];
|
|
1594
|
+
if (change.title !== undefined)
|
|
1595
|
+
args.push("-t", change.title);
|
|
1596
|
+
if (change.body !== undefined)
|
|
1597
|
+
args.push("-d", change.body);
|
|
1598
|
+
if (change.milestone !== undefined)
|
|
1599
|
+
args.push("-m", change.milestone);
|
|
1600
|
+
await tea(["issues", "edit"], args, repo);
|
|
1601
|
+
}
|
|
1602
|
+
async function setBody(number, body, repo) {
|
|
1603
|
+
await editIssue(number, { body }, repo);
|
|
1604
|
+
}
|
|
1605
|
+
async function createIssue(title, body, labels, milestone, repo) {
|
|
1606
|
+
const args = ["-t", title, "-d", body];
|
|
1607
|
+
const same = (found) => found.title === title && sameText(found.body, body);
|
|
1608
|
+
const known = new Set((await openIssues(undefined, repo)).filter(same).map((found) => found.number));
|
|
1609
|
+
if (labels !== undefined)
|
|
1610
|
+
args.push("-L", labels);
|
|
1611
|
+
if (milestone !== undefined)
|
|
1612
|
+
args.push("-m", milestone);
|
|
1613
|
+
await tea(["issues", "create"], args, repo);
|
|
1614
|
+
const created = (await openIssues(undefined, repo)).filter((found) => same(found) && !known.has(found.number));
|
|
1615
|
+
if (created.length > 1)
|
|
1616
|
+
throw new Error(`created "${title}" but ${created.map((found) => `#${found.number}`).join(" and ")} both match: another session created the same issue at once`);
|
|
1617
|
+
if (created[0] === undefined)
|
|
1618
|
+
throw new Error(`created "${title}" but cannot find it among the open issues`);
|
|
1619
|
+
return created[0];
|
|
1620
|
+
}
|
|
1621
|
+
function sameText(a, b) {
|
|
1622
|
+
return a.replaceAll(`\r
|
|
1623
|
+
`, `
|
|
1624
|
+
`).trimEnd() === b.replaceAll(`\r
|
|
1625
|
+
`, `
|
|
1626
|
+
`).trimEnd();
|
|
1627
|
+
}
|
|
1628
|
+
var EDIT_TRIES = 3;
|
|
1629
|
+
async function editBody(number, change, repo) {
|
|
1630
|
+
let wrote = false;
|
|
1631
|
+
for (let attempt = 0;attempt < EDIT_TRIES; attempt++) {
|
|
1632
|
+
const { body } = await getIssue(number, repo);
|
|
1633
|
+
const next = change(body);
|
|
1634
|
+
if (next === body)
|
|
1635
|
+
return wrote;
|
|
1636
|
+
await setBody(number, next, repo);
|
|
1637
|
+
wrote = true;
|
|
1638
|
+
if (sameText((await getIssue(number, repo)).body, next))
|
|
1639
|
+
return true;
|
|
1640
|
+
}
|
|
1641
|
+
throw new Error(`#${number}: its description keeps changing under the edit, so it was not written reliably`);
|
|
1642
|
+
}
|
|
1643
|
+
var login;
|
|
1644
|
+
async function sessionAuthor() {
|
|
1645
|
+
if (login !== undefined)
|
|
1646
|
+
return login;
|
|
1647
|
+
try {
|
|
1648
|
+
login = (await api("user")).login;
|
|
1649
|
+
} catch {
|
|
1650
|
+
return;
|
|
1651
|
+
}
|
|
1652
|
+
return login;
|
|
1653
|
+
}
|
|
1654
|
+
async function comment(number, body, repo) {
|
|
1655
|
+
await repoWrite("POST", `issues/${number}/comments`, { body }, repo);
|
|
1656
|
+
}
|
|
1657
|
+
async function close(number, repo) {
|
|
1658
|
+
await tea(["issues", "close"], [String(number)], repo);
|
|
1659
|
+
}
|
|
1660
|
+
async function reopen(number, repo) {
|
|
1661
|
+
await tea(["issues", "reopen"], [String(number)], repo);
|
|
1662
|
+
}
|
|
1663
|
+
async function repoLabels(repo) {
|
|
1664
|
+
const names = [];
|
|
1665
|
+
for (let page = 1;; page++) {
|
|
1666
|
+
const batch = await repoApi(`labels?page=${page}&limit=${PAGE}`, repo);
|
|
1667
|
+
names.push(...batch.map((each) => each.name));
|
|
1668
|
+
if (batch.length < PAGE)
|
|
1669
|
+
return names;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
async function editLabels(number, add, remove, repo) {
|
|
1673
|
+
const args = [String(number)];
|
|
1674
|
+
if (add.length > 0)
|
|
1675
|
+
args.push("--add-labels", add.join(","));
|
|
1676
|
+
if (remove.length > 0)
|
|
1677
|
+
args.push("--remove-labels", remove.join(","));
|
|
1678
|
+
await tea(["issues", "edit"], args, repo);
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
// src/milestones.ts
|
|
1682
|
+
var PAGE2 = 50;
|
|
1683
|
+
var DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
1684
|
+
var NO_DUE_YEAR = 9999;
|
|
1685
|
+
async function listMilestones(state, repo) {
|
|
1686
|
+
const found = [];
|
|
1687
|
+
for (let page = 1;; page++) {
|
|
1688
|
+
const batch = await repoApi(`milestones?state=${state}&page=${page}&limit=${PAGE2}`, repo);
|
|
1689
|
+
found.push(...batch);
|
|
1690
|
+
if (batch.length < PAGE2)
|
|
1691
|
+
return found;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
async function findMilestone(reference, repo) {
|
|
1695
|
+
const all = await listMilestones("all", repo);
|
|
1696
|
+
const found = all.find((each) => each.title === reference) ?? all.find((each) => String(each.id) === reference);
|
|
1697
|
+
if (found === undefined)
|
|
1698
|
+
fail(`no milestone ${reference}, ${all.length === 0 ? "the repository has none" : `it has: ${all.map((each) => each.title).join(", ")}`}`, 2, runHint(`ft milestone new ${reference}`, "create it"));
|
|
1699
|
+
return found;
|
|
1700
|
+
}
|
|
1701
|
+
function dueOn(value) {
|
|
1702
|
+
const match = DATE.exec(value);
|
|
1703
|
+
const date = new Date(`${value}T00:00:00Z`);
|
|
1704
|
+
if (match === null || Number.isNaN(date.getTime()) || date.toISOString().slice(0, 10) !== value || date.getUTCFullYear() < 2000)
|
|
1705
|
+
fail(`--due takes a date as YYYY-MM-DD, not ${value}`);
|
|
1706
|
+
return date.toISOString();
|
|
1707
|
+
}
|
|
1708
|
+
function dueDate(milestone) {
|
|
1709
|
+
if (milestone.due_on === null || new Date(milestone.due_on).getUTCFullYear() >= NO_DUE_YEAR)
|
|
1710
|
+
return "";
|
|
1711
|
+
return milestone.due_on.slice(0, 10);
|
|
1712
|
+
}
|
|
1713
|
+
function progress(milestone) {
|
|
1714
|
+
const total = milestone.open_issues + milestone.closed_issues;
|
|
1715
|
+
return total === 0 ? "" : `${Math.round(milestone.closed_issues / total * 100)}%`;
|
|
1716
|
+
}
|
|
1717
|
+
async function createMilestone(title, description, due, repo) {
|
|
1718
|
+
const fields = { title };
|
|
1719
|
+
if (description !== undefined)
|
|
1720
|
+
fields.description = description;
|
|
1721
|
+
if (due !== undefined)
|
|
1722
|
+
fields.due_on = due;
|
|
1723
|
+
return repoWrite("POST", "milestones", fields, repo);
|
|
1724
|
+
}
|
|
1725
|
+
async function closeMilestone(id, repo) {
|
|
1726
|
+
await repoWrite("PATCH", `milestones/${id}`, { state: "closed" }, repo);
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
// src/commands/board.ts
|
|
1730
|
+
var LINE_START = /^/gm;
|
|
1731
|
+
var TITLE_WIDTH = 80;
|
|
1732
|
+
function standing(claim, sessions) {
|
|
1733
|
+
if (claim === undefined)
|
|
1734
|
+
return { state: "available" };
|
|
1735
|
+
const session = holderSession(claim.holder, sessions);
|
|
1736
|
+
return session === undefined ? { state: "away", claim } : { state: "taken", claim, session };
|
|
1737
|
+
}
|
|
1738
|
+
var NOTE_WIDTH = 100;
|
|
1739
|
+
var STATES = new Set(["available", "taken", "away"]);
|
|
1740
|
+
function boxesLeft(issue) {
|
|
1741
|
+
const list = boxes(issue.body);
|
|
1742
|
+
return list.length === 0 ? "" : `${list.filter((box) => !box.done).length}/${list.length} left`;
|
|
1743
|
+
}
|
|
1744
|
+
function claimRow(issue, row, now) {
|
|
1745
|
+
const holder = row.state === "taken" && row.session.name !== row.claim.holder ? `${row.claim.holder} via ${row.session.name}` : row.claim.holder;
|
|
1746
|
+
const status = row.state === "taken" ? ` (${row.session.status})` : "";
|
|
1747
|
+
return [`#${issue.number}`, `${holder}${status}`, formatAge(row.claim.at, now), boxesLeft(issue), truncate(issue.title, TITLE_WIDTH)];
|
|
1748
|
+
}
|
|
1749
|
+
function noteLine(comments, now) {
|
|
1750
|
+
const note = latestNote(comments);
|
|
1751
|
+
const first = note?.body.split(`
|
|
1752
|
+
`).map((line) => line.trim()).find((line) => line !== "");
|
|
1753
|
+
return note === undefined || first === undefined ? [] : [` ${note.user.login} ${formatAge(note.created_at, now)}: ${truncate(first, NOTE_WIDTH)}`];
|
|
1754
|
+
}
|
|
1755
|
+
function within(rows, limit, cells, decorate = (line) => [line]) {
|
|
1756
|
+
const { shown, footer } = capped(rows, limit);
|
|
1757
|
+
return { lines: [...table(shown.map(cells)).split(`
|
|
1758
|
+
`).flatMap(decorate), ...footer === undefined ? [] : [footer]] };
|
|
1759
|
+
}
|
|
1760
|
+
function renderBoard(rows, now = Date.now(), limit = Number.POSITIVE_INFINITY) {
|
|
1761
|
+
const available = rows.filter((row) => row.standing.state === "available");
|
|
1762
|
+
const claimed = (state) => rows.flatMap(({ issue, standing: row, comments }) => row.state === state ? [{ issue, row, comments }] : []);
|
|
1763
|
+
const taken = claimed("taken");
|
|
1764
|
+
const away = claimed("away");
|
|
1765
|
+
const sections = [
|
|
1766
|
+
{ heading: "available", count: available.length, ...within(available, limit, ({ issue }) => [`#${issue.number}`, truncate(issue.title, TITLE_WIDTH), issue.labels.map((label) => label.name).join(", ")]) },
|
|
1767
|
+
{ heading: "taken", count: taken.length, ...within(taken, limit, ({ issue, row }) => claimRow(issue, row, now)) },
|
|
1768
|
+
{ heading: "claimed, no live session here", count: away.length, ...within(away, limit, ({ issue, row }) => claimRow(issue, row, now), (line, index) => [line, ...noteLine(away[index]?.comments ?? [], now)]) }
|
|
1769
|
+
].filter((section) => section.count > 0);
|
|
1770
|
+
return sections.length === 0 ? "no open issue" : sections.map(({ heading, count, lines }) => `${heading} (${count})
|
|
1771
|
+
${lines.join(`
|
|
1772
|
+
`).replace(LINE_START, " ")}`).join(`
|
|
1773
|
+
|
|
1774
|
+
`);
|
|
1775
|
+
}
|
|
1776
|
+
async function boardRows(issues, sessions, repo) {
|
|
1777
|
+
const comments = await commentsOfAll(issues, repo);
|
|
1778
|
+
const author = await sessionAuthor();
|
|
1779
|
+
return issues.map((issue) => {
|
|
1780
|
+
const own = comments.get(issue.number) ?? [];
|
|
1781
|
+
return { issue, standing: standing(latestClaim(own, author), sessions), comments: own };
|
|
1782
|
+
});
|
|
1783
|
+
}
|
|
1784
|
+
function boardJson(rows) {
|
|
1785
|
+
return rows.map(({ issue, standing: { state, ...rest }, comments: own }) => {
|
|
1786
|
+
const list = boxes(issue.body);
|
|
1787
|
+
const note = latestNote(own);
|
|
1788
|
+
return {
|
|
1789
|
+
number: issue.number,
|
|
1790
|
+
title: issue.title,
|
|
1791
|
+
labels: issue.labels.map((label) => label.name),
|
|
1792
|
+
state,
|
|
1793
|
+
holder: "claim" in rest ? rest.claim.holder : undefined,
|
|
1794
|
+
since: "claim" in rest ? rest.claim.at : undefined,
|
|
1795
|
+
session: "session" in rest ? rest.session.name : undefined,
|
|
1796
|
+
boxesTotal: list.length,
|
|
1797
|
+
boxesLeft: list.filter((box) => !box.done).length,
|
|
1798
|
+
note: note === undefined ? undefined : { author: note.user.login, at: note.created_at, body: note.body }
|
|
1799
|
+
};
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
var boardUsage = `ft board
|
|
1803
|
+
|
|
1804
|
+
Lists open issues, at most 30 of each kind (--full for all), as available, taken by a session running here, or claimed by a session no session here answers to, from their latest "Taken by session <name>." comment.
|
|
1805
|
+
A claim shows its boxes left, and one no live session holds also the latest comment that is not a claim.
|
|
1806
|
+
A lane's claim (lane-<n>-<issue>) is held while the session whose name ends in -<n> runs.
|
|
1807
|
+
|
|
1808
|
+
Exits 0 when it listed them, 1 when the issues cannot be read, 2 on a usage error.`;
|
|
1809
|
+
var BOARD_LIMIT = 30;
|
|
1810
|
+
var boardOptions = {
|
|
1811
|
+
labels: { type: "string", short: "L", description: "only issues with these labels, comma separated" },
|
|
1812
|
+
milestone: { type: "string", short: "m", description: "only issues of this milestone, a title or an id" },
|
|
1813
|
+
query: { type: "string", short: "q", description: "only issues whose title matches this, a case-insensitive regex such as dom|eager" },
|
|
1814
|
+
state: { type: "string", description: "only issues in this state: available, taken or away (claimed, no live session here)" },
|
|
1815
|
+
...limitOptions(BOARD_LIMIT),
|
|
1816
|
+
json: jsonOption("number, title, labels, state, holder, since, session, boxesTotal, boxesLeft and note (author, at, body of the latest comment that is not a claim)"),
|
|
1817
|
+
...repoOption
|
|
1818
|
+
};
|
|
1819
|
+
async function board(args) {
|
|
1820
|
+
const parsed = parse(args, boardUsage, boardOptions);
|
|
1821
|
+
const { values } = parsed;
|
|
1822
|
+
const state = values.state;
|
|
1823
|
+
const limit = limitOf(values, BOARD_LIMIT);
|
|
1824
|
+
if (state !== undefined && !STATES.has(state))
|
|
1825
|
+
fail(`--state takes available, taken or away, not ${state}`);
|
|
1826
|
+
let query;
|
|
1827
|
+
try {
|
|
1828
|
+
query = values.query === undefined ? undefined : new RegExp(values.query, "i");
|
|
1829
|
+
} catch (error) {
|
|
1830
|
+
fail(`--query: ${error instanceof Error ? error.message : String(error)}`);
|
|
1831
|
+
}
|
|
1832
|
+
const milestone = values.milestone === undefined ? undefined : (await findMilestone(values.milestone, values.repo)).id;
|
|
1833
|
+
const [open, sessions] = await Promise.all([openIssues(values.labels, values.repo, milestone), liveSessions()]);
|
|
1834
|
+
const issues = query === undefined ? open : open.filter((issue) => query.test(issue.title));
|
|
1835
|
+
const rows = (await boardRows(issues, sessions, values.repo)).filter((row) => state === undefined || row.standing.state === state);
|
|
1836
|
+
if (values.json === true) {
|
|
1837
|
+
printJson(boardJson(rows));
|
|
1838
|
+
return 0;
|
|
1839
|
+
}
|
|
1840
|
+
console.log(rows.length === 0 && (query !== undefined || state !== undefined) ? "no open issue matches" : renderBoard(rows, Date.now(), limit));
|
|
1841
|
+
return 0;
|
|
1842
|
+
}
|
|
1843
|
+
async function me(as, sessions) {
|
|
1844
|
+
if (as !== undefined)
|
|
1845
|
+
return as;
|
|
1846
|
+
const session = await currentSession(sessions);
|
|
1847
|
+
if (session === undefined)
|
|
1848
|
+
fail("not run from a Claude Code session: pass --as <name>");
|
|
1849
|
+
return session.name;
|
|
1850
|
+
}
|
|
1851
|
+
var takeUsage = `ft take <n>...
|
|
1852
|
+
|
|
1853
|
+
Claims each issue for this Claude Code session with a "Taken by session <name>." comment.
|
|
1854
|
+
An issue another live session holds is refused, one this session or its lanes hold passes to the new name, and one claimed by a session no session here answers to needs --take-stale; a refusal leaves the other issues taken.
|
|
1855
|
+
|
|
1856
|
+
Exits 0 when every issue is taken, 1 when one is refused, 2 on a usage error.`;
|
|
1857
|
+
var laneOption = {
|
|
1858
|
+
lane: { type: "boolean", description: "claim each as lane-<s>-<n>, <s> ending this session's name, so the claim stays live while it runs" }
|
|
1859
|
+
};
|
|
1860
|
+
var takeOptions = {
|
|
1861
|
+
as: { type: "string", description: "the name to claim as, instead of this session's" },
|
|
1862
|
+
...laneOption,
|
|
1863
|
+
"take-stale": { type: "boolean", description: "take it over from a claim no live session here answers to" },
|
|
1864
|
+
...repoOption
|
|
1865
|
+
};
|
|
1866
|
+
async function claimant(values, sessions) {
|
|
1867
|
+
const name = await me(values.as, sessions);
|
|
1868
|
+
if (values.lane !== true)
|
|
1869
|
+
return () => name;
|
|
1870
|
+
const suffix = laneSuffix(name);
|
|
1871
|
+
if (suffix === undefined)
|
|
1872
|
+
fail(`a lane is named after a session whose name ends in -<n>, not ${name}: pass --as`);
|
|
1873
|
+
return (number) => `lane-${suffix}-${number}`;
|
|
1874
|
+
}
|
|
1875
|
+
async function eachIssue(command, numbers, step) {
|
|
1876
|
+
let code = 0;
|
|
1877
|
+
for (const number of numbers) {
|
|
1878
|
+
try {
|
|
1879
|
+
await step(number);
|
|
1880
|
+
} catch (error) {
|
|
1881
|
+
if (!(error instanceof Exit) || numbers.length === 1)
|
|
1882
|
+
throw error;
|
|
1883
|
+
console.error(`ft ${command}: ${error.message}`);
|
|
1884
|
+
if (error.hint !== undefined)
|
|
1885
|
+
printHint(error.hint);
|
|
1886
|
+
code = Math.max(code, error.code);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
return code;
|
|
1890
|
+
}
|
|
1891
|
+
async function take(args) {
|
|
1892
|
+
const parsed = parse(args, takeUsage, takeOptions);
|
|
1893
|
+
const { values, positionals } = parsed;
|
|
1894
|
+
const numbers = issueNumbers(positionals, takeUsage);
|
|
1895
|
+
const sessions = await liveSessions();
|
|
1896
|
+
const nameFor = await claimant(values, sessions);
|
|
1897
|
+
const author = await sessionAuthor();
|
|
1898
|
+
return eachIssue("take", numbers, async (number) => {
|
|
1899
|
+
const name = nameFor(number);
|
|
1900
|
+
const [found, comments] = await Promise.all([getIssue(number, values.repo), commentsOf(number, values.repo)]);
|
|
1901
|
+
if (found.state === "closed")
|
|
1902
|
+
fail(`#${number} is closed`, 1, runHint(`ft reopen ${number}`, "reopen it"));
|
|
1903
|
+
const claim = latestClaim(comments, author);
|
|
1904
|
+
const current = standing(claim, sessions);
|
|
1905
|
+
if (claim?.holder === name) {
|
|
1906
|
+
console.log(`#${number} is already taken by ${name}`);
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
if (current.state === "taken" && holderSession(name, sessions)?.pid !== current.session.pid)
|
|
1910
|
+
fail(`#${number} is taken by ${current.claim.holder}${current.session.name === current.claim.holder ? "" : ` in ${current.session.name}`}, which still runs (${current.session.status})`, 1);
|
|
1911
|
+
if (current.state === "away" && values["take-stale"] !== true)
|
|
1912
|
+
fail(`#${number} was taken by ${current.claim.holder} ${formatAge(current.claim.at)}, which no session here answers to: it may run on another machine`, 1, runHint(`ft take ${number} --take-stale`, "take it over"));
|
|
1913
|
+
await comment(number, takenComment(name), values.repo);
|
|
1914
|
+
const standingNow = latestClaim(await commentsOf(number, values.repo), author);
|
|
1915
|
+
if (standingNow?.holder !== name)
|
|
1916
|
+
fail(`#${number} was taken by ${standingNow?.holder ?? "another session"} at the same moment`, 1);
|
|
1917
|
+
console.log(`took #${number} as ${name}: ${found.title}`);
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1920
|
+
var dropUsage = `ft drop <n>...
|
|
1921
|
+
|
|
1922
|
+
Gives each issue back with a "Released by session <name>." comment, when this session holds it.
|
|
1923
|
+
|
|
1924
|
+
Exits 0 when every issue is given back, 1 when one is not held by this session, 2 on a usage error.`;
|
|
1925
|
+
var dropOptions = {
|
|
1926
|
+
as: { type: "string", description: "the name it was taken as, instead of this session's" },
|
|
1927
|
+
...laneOption,
|
|
1928
|
+
...repoOption
|
|
1929
|
+
};
|
|
1930
|
+
async function drop(args) {
|
|
1931
|
+
const parsed = parse(args, dropUsage, dropOptions);
|
|
1932
|
+
const { values, positionals } = parsed;
|
|
1933
|
+
const numbers = issueNumbers(positionals, dropUsage);
|
|
1934
|
+
const nameFor = await claimant(values, await liveSessions());
|
|
1935
|
+
const author = await sessionAuthor();
|
|
1936
|
+
return eachIssue("drop", numbers, async (number) => {
|
|
1937
|
+
const name = nameFor(number);
|
|
1938
|
+
const claim = latestClaim(await commentsOf(number, values.repo), author);
|
|
1939
|
+
if (claim?.holder !== name)
|
|
1940
|
+
fail(`#${number} is ${claim === undefined ? "not taken" : `taken by ${claim.holder}, not ${name}`}`, 1);
|
|
1941
|
+
await comment(number, releasedComment(name), values.repo);
|
|
1942
|
+
console.log(`released #${number}`);
|
|
1943
|
+
});
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
// src/commands/ci.ts
|
|
1947
|
+
import process12 from "process";
|
|
1948
|
+
|
|
1949
|
+
// src/git.ts
|
|
1950
|
+
async function tagsAt(commit) {
|
|
1951
|
+
return (await git(["tag", "--points-at", commit])).split(`
|
|
1952
|
+
`).filter(Boolean);
|
|
1953
|
+
}
|
|
1954
|
+
async function commitsNaming(issue, ref) {
|
|
1955
|
+
const out = await git(["log", ref, "--reverse", "--extended-regexp", `--grep=#${issue}([^0-9]|$)`, "--format=%H %s"]);
|
|
1956
|
+
return out.split(`
|
|
1957
|
+
`).filter(Boolean).map((line) => {
|
|
1958
|
+
const space = line.indexOf(" ");
|
|
1959
|
+
return { sha: line.slice(0, space), subject: line.slice(space + 1) };
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
// src/log.ts
|
|
1964
|
+
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |::(?:end)?group::|\S+\.test\.[jt]sx?:$)/;
|
|
1965
|
+
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
1966
|
+
var FAIL = "(fail) ";
|
|
1967
|
+
var PASS = "(pass) ";
|
|
1968
|
+
var MAX_TESTS = 10;
|
|
1969
|
+
var STAMP = /^\S+Z /;
|
|
1970
|
+
var FAILED_STEP = /\u274C\s+Failure - Main /;
|
|
1971
|
+
var STEP_TAIL = 30;
|
|
1972
|
+
var TAIL = 40;
|
|
1973
|
+
function logLines(log) {
|
|
1974
|
+
return log.split(`
|
|
1975
|
+
`).map((line) => line.replace(STAMP, ""));
|
|
1976
|
+
}
|
|
1977
|
+
function failedTests(lines) {
|
|
1978
|
+
const seen = new Set;
|
|
1979
|
+
const blocks = [];
|
|
1980
|
+
for (const [index, line] of lines.entries()) {
|
|
1981
|
+
const name = line.replace(DURATION2, "");
|
|
1982
|
+
if (!line.startsWith(FAIL) || seen.has(name))
|
|
1983
|
+
continue;
|
|
1984
|
+
seen.add(name);
|
|
1985
|
+
if (blocks.length < MAX_TESTS)
|
|
1986
|
+
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).filter((text) => !text.startsWith("::")).join(`
|
|
1987
|
+
`).trim());
|
|
1988
|
+
}
|
|
1989
|
+
if (seen.size > MAX_TESTS)
|
|
1990
|
+
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
1991
|
+
return blocks;
|
|
1992
|
+
}
|
|
1993
|
+
function excerpt(log) {
|
|
1994
|
+
const lines = logLines(log);
|
|
1995
|
+
const parts = failedTests(lines);
|
|
1996
|
+
for (const [index, line] of lines.entries()) {
|
|
1997
|
+
if (FAILED_STEP.test(line))
|
|
1998
|
+
parts.push(lines.slice(Math.max(0, index - STEP_TAIL), index + 1).filter((text) => text.trim() !== "" && !text.startsWith(PASS) && !text.startsWith("::")).join(`
|
|
1999
|
+
`));
|
|
2000
|
+
}
|
|
2001
|
+
return parts.length === 0 ? lines.slice(-TAIL).join(`
|
|
2002
|
+
`).trim() : parts.join(`
|
|
2003
|
+
|
|
2004
|
+
`);
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
// src/runs.ts
|
|
2008
|
+
var FINISHED = new Set(["success", "failure", "skipped", "cancelled"]);
|
|
2009
|
+
var QUEUED = new Set(["waiting", "blocked"]);
|
|
2010
|
+
var NANOSECONDS = 1e9;
|
|
2011
|
+
var EPOCH = Date.parse("2000-01-01T00:00:00Z");
|
|
2012
|
+
function runSeconds(run) {
|
|
2013
|
+
return run.duration / NANOSECONDS;
|
|
2014
|
+
}
|
|
2015
|
+
function startedAt(run) {
|
|
2016
|
+
const at = Date.parse(run.started);
|
|
2017
|
+
return Number.isNaN(at) || at < EPOCH ? undefined : at;
|
|
2018
|
+
}
|
|
2019
|
+
function startedAge(run, now = Date.now()) {
|
|
2020
|
+
return startedAt(run) === undefined ? "-" : formatAge(run.started, now);
|
|
2021
|
+
}
|
|
2022
|
+
var RUNS_PAGE = 50;
|
|
2023
|
+
async function runsListing(limit, repo, workflow) {
|
|
2024
|
+
const filter = workflow === undefined ? "" : `&workflow_id=${encodeURIComponent(workflow)}`;
|
|
2025
|
+
const runs = [];
|
|
2026
|
+
let total = 0;
|
|
2027
|
+
for (let page = 1;runs.length < limit; page++) {
|
|
2028
|
+
const found = await repoApi(`actions/runs?page=${page}&limit=${RUNS_PAGE}${filter}`, repo);
|
|
2029
|
+
const list = found.workflow_runs ?? [];
|
|
2030
|
+
runs.push(...list);
|
|
2031
|
+
total = found.total_count ?? 0;
|
|
2032
|
+
if (list.length < RUNS_PAGE)
|
|
2033
|
+
break;
|
|
2034
|
+
}
|
|
2035
|
+
return { runs: runs.slice(0, limit), total: Math.max(total, runs.length) };
|
|
2036
|
+
}
|
|
2037
|
+
async function recentRuns(limit, repo, workflow) {
|
|
2038
|
+
return (await runsListing(limit, repo, workflow)).runs;
|
|
2039
|
+
}
|
|
2040
|
+
async function runsOn(sha, repo) {
|
|
2041
|
+
const runs = [];
|
|
2042
|
+
for (let page = 1;; page++) {
|
|
2043
|
+
const list = (await repoApi(`actions/runs?head_sha=${sha}&page=${page}&limit=${RUNS_PAGE}`, repo)).workflow_runs ?? [];
|
|
2044
|
+
runs.push(...list);
|
|
2045
|
+
if (list.length < RUNS_PAGE)
|
|
2046
|
+
return runs;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
async function runById(id, repo) {
|
|
2050
|
+
return repoApi(`actions/runs/${id}`, repo);
|
|
2051
|
+
}
|
|
2052
|
+
async function jobsOf(run, repo) {
|
|
2053
|
+
return repoApi(`actions/runs/${run}/jobs`, repo);
|
|
2054
|
+
}
|
|
2055
|
+
async function jobLog(job, repo) {
|
|
2056
|
+
return repoApiText(`actions/jobs/${job}/logs`, repo);
|
|
2057
|
+
}
|
|
2058
|
+
async function refreshed(runs, repo) {
|
|
2059
|
+
try {
|
|
2060
|
+
return await Promise.all(runs.map(async (run) => runById(run.id, repo)));
|
|
2061
|
+
} catch {
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
function newestPerWorkflow(runs, workflow) {
|
|
2066
|
+
const newest = new Map;
|
|
2067
|
+
for (const run of runs) {
|
|
2068
|
+
if (run.event !== "push" || workflow !== undefined && run.workflow_id !== workflow)
|
|
2069
|
+
continue;
|
|
2070
|
+
const kept = newest.get(run.workflow_id);
|
|
2071
|
+
if (kept === undefined || run.id > kept.id)
|
|
2072
|
+
newest.set(run.workflow_id, run);
|
|
2073
|
+
}
|
|
2074
|
+
return [...newest.values()].sort((a, b) => a.workflow_id.localeCompare(b.workflow_id));
|
|
2075
|
+
}
|
|
2076
|
+
function overall(runs) {
|
|
2077
|
+
const statuses = new Set(runs.map((run) => run.status));
|
|
2078
|
+
for (const status of ["failure", "cancelled"]) {
|
|
2079
|
+
if (statuses.has(status))
|
|
2080
|
+
return status;
|
|
2081
|
+
}
|
|
2082
|
+
const pending = runs.find((run) => !FINISHED.has(run.status));
|
|
2083
|
+
if (pending !== undefined)
|
|
2084
|
+
return pending.status;
|
|
2085
|
+
return statuses.has("success") ? "success" : "skipped";
|
|
2086
|
+
}
|
|
2087
|
+
async function stallReason(runs, repo) {
|
|
2088
|
+
const queued = runs.filter((run) => QUEUED.has(run.status));
|
|
2089
|
+
if (queued.length === 0)
|
|
2090
|
+
return;
|
|
2091
|
+
let runners;
|
|
2092
|
+
try {
|
|
2093
|
+
runners = await api("admin/actions/runners");
|
|
2094
|
+
} catch {
|
|
2095
|
+
return;
|
|
2096
|
+
}
|
|
2097
|
+
const online = runners.filter((runner) => runner.status !== "offline");
|
|
2098
|
+
if (online.length === 0)
|
|
2099
|
+
return { reason: runners.length === 0 ? "no runner is registered" : `every runner is offline (${runners.map((runner) => runner.name).join(", ")})`, certain: false };
|
|
2100
|
+
for (const run of queued) {
|
|
2101
|
+
for (const job of await jobsOf(run.id, repo)) {
|
|
2102
|
+
const labels = job.runs_on ?? [];
|
|
2103
|
+
if (QUEUED.has(job.status) && !online.some((runner) => labels.every((label) => (runner.labels ?? []).includes(label))))
|
|
2104
|
+
return { reason: `job ${job.name} of ${run.workflow_id} runs on ${labels.join(", ")}, which no online runner carries (${online.map((runner) => `${runner.name}: ${(runner.labels ?? []).join(", ")}`).join("; ")})`, certain: true };
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
return online.some((runner) => runner.status === "active") ? undefined : { reason: "no runner is working on anything: is it up?", certain: false };
|
|
2108
|
+
}
|
|
2109
|
+
async function failureReport(run, repo) {
|
|
2110
|
+
const parts = [];
|
|
2111
|
+
for (const job of await jobsOf(run.id, repo)) {
|
|
2112
|
+
if (job.status === "failure")
|
|
2113
|
+
parts.push(`job ${job.name} of ${run.workflow_id} failed:
|
|
2114
|
+
${excerpt(await jobLog(job.id, repo))}`);
|
|
2115
|
+
}
|
|
2116
|
+
return parts.join(`
|
|
2117
|
+
|
|
2118
|
+
`);
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
// src/commands/ci.ts
|
|
2122
|
+
var usage = `ft ci [ref]
|
|
2123
|
+
|
|
2124
|
+
Waits for the push runs covering a commit on the branch, by default origin's tip, and prints what each failed job's log says.
|
|
2125
|
+
A push's run tests every commit since the previous push, so a commit whose own run was cancelled, or whose --job was skipped, is covered by the next commit's runs.
|
|
2126
|
+
Exits 0 when they pass, 1 when one fails, 2 on a timeout, a stalled queue or a commit not on the branch.`;
|
|
2127
|
+
var options = {
|
|
2128
|
+
branch: { type: "string", short: "b", description: "branch the commit is on, by default the one origin/HEAD names" },
|
|
2129
|
+
workflow: { type: "string", short: "w", description: "only this workflow file, e.g. test.yml; by default every workflow a push starts" },
|
|
2130
|
+
job: { type: "string", short: "j", description: "a job whose skipping means the run left its work to a newer push" },
|
|
2131
|
+
timeout: { type: "string", short: "t", description: "how long before giving up (30m), a bare number in minutes" }
|
|
2132
|
+
};
|
|
2133
|
+
var NO_RUN = 3 * 60000;
|
|
2134
|
+
var STALLED = 3 * 60000;
|
|
2135
|
+
var MAX_LOOKUPS = 20;
|
|
2136
|
+
function judge(runs, jobSkipped, tagged) {
|
|
2137
|
+
if (runs.length === 0)
|
|
2138
|
+
return { kind: "none" };
|
|
2139
|
+
if (runs.some((run) => !FINISHED.has(run.status)))
|
|
2140
|
+
return { kind: "runs", runs };
|
|
2141
|
+
if (runs.some((run) => run.status === "cancelled"))
|
|
2142
|
+
return { kind: "passed-over" };
|
|
2143
|
+
if (!jobSkipped)
|
|
2144
|
+
return { kind: "runs", runs };
|
|
2145
|
+
return tagged ? { kind: "runs", runs: runs.map((run) => ({ ...run, status: "skipped" })) } : { kind: "passed-over" };
|
|
2146
|
+
}
|
|
2147
|
+
function commitsToAsk(commits, passedOver, max = MAX_LOOKUPS) {
|
|
2148
|
+
return commits.filter((commit) => !passedOver.has(commit)).slice(0, max);
|
|
2149
|
+
}
|
|
2150
|
+
function settled(latest) {
|
|
2151
|
+
return latest !== undefined && latest.every((run) => FINISHED.has(run.status)) && judge(latest, false, false).kind === "runs" ? latest : undefined;
|
|
2152
|
+
}
|
|
2153
|
+
async function ci2(args) {
|
|
2154
|
+
const parsed = parse(args, usage, options);
|
|
2155
|
+
const { values, positionals } = parsed;
|
|
2156
|
+
const branch = values.branch ?? await defaultBranch();
|
|
2157
|
+
const giveUp = duration(values.timeout, "timeout", 30 * 60000, "m");
|
|
2158
|
+
const sha = await resolveCommit(positionals[0] ?? `origin/${branch}`);
|
|
2159
|
+
const short = sha.slice(0, 7);
|
|
2160
|
+
await leaveWorktree();
|
|
2161
|
+
const passedOver = new Set;
|
|
2162
|
+
async function coverageOf(commit) {
|
|
2163
|
+
if (passedOver.has(commit))
|
|
2164
|
+
return { kind: "passed-over" };
|
|
2165
|
+
const runs = newestPerWorkflow(await runsOn(commit), values.workflow);
|
|
2166
|
+
let jobSkipped = false;
|
|
2167
|
+
if (values.job !== undefined && runs.every((run) => FINISHED.has(run.status))) {
|
|
2168
|
+
for (const run of runs)
|
|
2169
|
+
jobSkipped ||= (await jobsOf(run.id)).some((job) => job.name === values.job && job.status === "skipped");
|
|
2170
|
+
}
|
|
2171
|
+
const coverage = judge(runs, jobSkipped, jobSkipped && (await tagsAt(commit)).length > 0);
|
|
2172
|
+
if (coverage.kind === "passed-over")
|
|
2173
|
+
passedOver.add(commit);
|
|
2174
|
+
return coverage;
|
|
2175
|
+
}
|
|
2176
|
+
async function covering() {
|
|
2177
|
+
await fetchBranch(branch);
|
|
2178
|
+
if (!await gitOk(["merge-base", "--is-ancestor", sha, `origin/${branch}`]))
|
|
2179
|
+
fail(`${short} is not on origin/${branch}`, 2, runHint(`git push origin ${branch}`));
|
|
2180
|
+
const later = (await git(["rev-list", "--reverse", "--first-parent", `${sha}..origin/${branch}`])).split(`
|
|
2181
|
+
`).filter(Boolean);
|
|
2182
|
+
for (const commit of commitsToAsk([sha, ...later], passedOver)) {
|
|
2183
|
+
const coverage = await coverageOf(commit);
|
|
2184
|
+
if (coverage.kind === "runs")
|
|
2185
|
+
return coverage.runs;
|
|
2186
|
+
}
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
const { dim } = paint(process12.stderr);
|
|
2190
|
+
const runs = await waitForCi({
|
|
2191
|
+
tool: "ft ci",
|
|
2192
|
+
short,
|
|
2193
|
+
giveUpMs: giveUp,
|
|
2194
|
+
noneMs: NO_RUN,
|
|
2195
|
+
stalledMs: STALLED,
|
|
2196
|
+
noneMessage: `no run covers ${short} yet: its own was cancelled by a later push or never started, so the next push's will`,
|
|
2197
|
+
covering,
|
|
2198
|
+
finished: (found) => found.every((run) => FINISHED.has(run.status)),
|
|
2199
|
+
key: (found) => found.map((run) => run.id).join(","),
|
|
2200
|
+
announce: (found) => {
|
|
2201
|
+
for (const run of found)
|
|
2202
|
+
console.log(`following ${run.workflow_id} run ${run.id} on ${run.commit_sha.slice(0, 7)}${run.commit_sha === sha ? "" : `, which covers ${short}`}: ${run.html_url}`);
|
|
2203
|
+
},
|
|
2204
|
+
links: (found) => found.map((run) => run.html_url).join(" "),
|
|
2205
|
+
settle: async (found) => settled(await refreshed(found)),
|
|
2206
|
+
stall: async (found) => {
|
|
2207
|
+
const stall = await stallReason(found);
|
|
2208
|
+
return stall === undefined ? undefined : { message: `runs queued on ${short} are not moving: ${stall.reason}`, certain: stall.certain };
|
|
2209
|
+
},
|
|
2210
|
+
lines: (spinner, found, started) => [
|
|
2211
|
+
`${spinner} CI on ${short} ${dim(formatElapsed(Date.now() - started))}`,
|
|
2212
|
+
...(found ?? []).map((run) => ` ${badge(run.status, process12.stderr)} ${run.workflow_id} ${dim(`run ${run.id}`)}`)
|
|
2213
|
+
]
|
|
2214
|
+
});
|
|
2215
|
+
const status = overall(runs);
|
|
2216
|
+
if (status !== "failure") {
|
|
2217
|
+
console.log(`CI ${status === "success" ? "passed" : "skipped its tests, a release tag's workflow testing them"} on ${short}`);
|
|
2218
|
+
return 0;
|
|
2219
|
+
}
|
|
2220
|
+
for (const run of runs) {
|
|
2221
|
+
if (run.status === "failure")
|
|
2222
|
+
console.error(`
|
|
2223
|
+
${await failureReport(run)}
|
|
2224
|
+
|
|
2225
|
+
run ${run.id} failed${run.commit_sha === sha ? "" : `, testing every commit from ${short} to ${run.commit_sha.slice(0, 7)}`}: ${run.html_url}`);
|
|
2226
|
+
}
|
|
2227
|
+
return 1;
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
// src/commands/digest.ts
|
|
2231
|
+
import process13 from "process";
|
|
2232
|
+
var RUNS_SCANNED = 50;
|
|
2233
|
+
var TITLE_WIDTH2 = 70;
|
|
2234
|
+
var SHOWN = 8;
|
|
2235
|
+
var LINE_START2 = /^/gm;
|
|
2236
|
+
function claimed(issue, claim) {
|
|
2237
|
+
const list = boxes(issue.body);
|
|
2238
|
+
return { number: issue.number, title: issue.title, holder: claim.holder, since: claim.at, boxesLeft: list.filter((box) => !box.done).length, boxesTotal: list.length };
|
|
2239
|
+
}
|
|
2240
|
+
function claims(rows, sessions, me) {
|
|
2241
|
+
const held = [];
|
|
2242
|
+
const away = [];
|
|
2243
|
+
for (const { issue, claim } of rows) {
|
|
2244
|
+
const row = standing(claim, sessions);
|
|
2245
|
+
if (row.state === "taken" && me !== undefined && row.session.pid === me.pid)
|
|
2246
|
+
held.push(claimed(issue, row.claim));
|
|
2247
|
+
else if (row.state === "away")
|
|
2248
|
+
away.push(claimed(issue, row.claim));
|
|
2249
|
+
}
|
|
2250
|
+
return { held, away };
|
|
2251
|
+
}
|
|
2252
|
+
function unsettled(runs, branch) {
|
|
2253
|
+
return newestPerWorkflow(runs.filter((run) => run.prettyref === branch)).filter((run) => run.status === "failure" || !FINISHED.has(run.status)).map((run) => ({ id: run.id, status: run.status, workflow: run.workflow_id, started: run.started, title: run.title }));
|
|
2254
|
+
}
|
|
2255
|
+
function dirtyFiles(porcelain) {
|
|
2256
|
+
return porcelain.split(`
|
|
2257
|
+
`).flatMap((line) => {
|
|
2258
|
+
const trimmed = line.trim();
|
|
2259
|
+
const space = trimmed.indexOf(" ");
|
|
2260
|
+
return space === -1 ? [] : [{ status: trimmed.slice(0, space), path: trimmed.slice(space + 1).trim() }];
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
async function unpushedCommits() {
|
|
2264
|
+
const base = await gitOk(["rev-parse", "--verify", "-q", "@{upstream}"]) ? "@{upstream}" : `origin/${await defaultBranch()}`;
|
|
2265
|
+
if (!await gitOk(["rev-parse", "--verify", "-q", base]))
|
|
2266
|
+
return [];
|
|
2267
|
+
return (await git(["log", `${base}..HEAD`, "--format=%h %s"])).split(`
|
|
2268
|
+
`).filter(Boolean);
|
|
2269
|
+
}
|
|
2270
|
+
async function dirtyTree() {
|
|
2271
|
+
return dirtyFiles(await git(["status", "--porcelain"]));
|
|
2272
|
+
}
|
|
2273
|
+
async function quietly(read) {
|
|
2274
|
+
try {
|
|
2275
|
+
return await read();
|
|
2276
|
+
} catch {
|
|
2277
|
+
return [];
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
async function staleTodos() {
|
|
2281
|
+
const bin = Bun.which("todo-scan", { PATH: process13.env.PATH ?? "" });
|
|
2282
|
+
if (bin === null)
|
|
2283
|
+
return [];
|
|
2284
|
+
let found;
|
|
2285
|
+
try {
|
|
2286
|
+
const ran = await runCommand([bin, "--stale", "--json"]);
|
|
2287
|
+
found = JSON.parse(Buffer.concat(ran.chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString());
|
|
2288
|
+
} catch {
|
|
2289
|
+
return [];
|
|
2290
|
+
}
|
|
2291
|
+
const byIssue = new Map;
|
|
2292
|
+
for (const mark of found) {
|
|
2293
|
+
for (const ref of mark.refs.filter((each) => each.state === "closed")) {
|
|
2294
|
+
const key = `${ref.repo}#${ref.number}`;
|
|
2295
|
+
const entry = byIssue.get(key) ?? { issue: key, comments: [] };
|
|
2296
|
+
entry.comments.push({ path: mark.path, line: mark.line });
|
|
2297
|
+
byIssue.set(key, entry);
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
return [...byIssue.values()];
|
|
2301
|
+
}
|
|
2302
|
+
function claimLine(row, now) {
|
|
2303
|
+
return [`#${row.number}`, row.holder, formatAge(row.since, now), row.boxesTotal === 0 ? "" : `${row.boxesLeft}/${row.boxesTotal} left`, truncate(row.title, TITLE_WIDTH2)];
|
|
2304
|
+
}
|
|
2305
|
+
function capped2(lines) {
|
|
2306
|
+
return lines.length > SHOWN ? [...lines.slice(0, SHOWN), `... ${lines.length - SHOWN} more`] : lines;
|
|
2307
|
+
}
|
|
2308
|
+
function renderDigest(digest, now = Date.now()) {
|
|
2309
|
+
const sections = [
|
|
2310
|
+
{ heading: "held by this session", count: digest.held.length, lines: table(digest.held.map((row) => claimLine(row, now))).split(`
|
|
2311
|
+
`) },
|
|
2312
|
+
{ heading: "claimed, no live session here", count: digest.away.length, lines: table(digest.away.map((row) => claimLine(row, now))).split(`
|
|
2313
|
+
`) },
|
|
2314
|
+
{ heading: "CI on the default branch", count: digest.ci.length, lines: digest.ci.map((run) => `${run.workflow} ${run.status} (run ${run.id}) ${truncate(upTo(run.title, `
|
|
2315
|
+
`), TITLE_WIDTH2)}`) },
|
|
2316
|
+
{ heading: "unpushed commits", count: digest.unpushed.length, lines: capped2(digest.unpushed) },
|
|
2317
|
+
{ heading: "dirty files", count: digest.dirty.length, lines: capped2(digest.dirty.map((file) => `${file.status} ${file.path}`)) },
|
|
2318
|
+
{ heading: "stale TODO comments", count: digest.stale.length, lines: capped2(digest.stale.map((todo) => `${todo.issue} closed: ${todo.comments.map((each) => `${each.path}:${each.line}`).join(", ")}`)) }
|
|
2319
|
+
].filter((section) => section.count > 0);
|
|
2320
|
+
return sections.length === 0 ? "nothing to pick up" : sections.map(({ heading, count, lines }) => `${heading} (${count})
|
|
2321
|
+
${lines.join(`
|
|
2322
|
+
`).replace(LINE_START2, " ")}`).join(`
|
|
2323
|
+
|
|
2324
|
+
`);
|
|
2325
|
+
}
|
|
2326
|
+
var usage2 = `ft digest
|
|
2327
|
+
|
|
2328
|
+
Summarises the repository for a session starting cold: the issues this session holds with their boxes left, the claims no live session here answers to, red or running CI on the default branch, unpushed commits, dirty files and TODO comments naming a closed issue.
|
|
2329
|
+
A section with nothing in it is left out, and the stale TODO comments need todo-scan on the PATH.
|
|
2330
|
+
|
|
2331
|
+
Exits 0 when it summarised the repository, 1 when Forgejo cannot be read, 2 on a usage error.`;
|
|
2332
|
+
var options2 = {
|
|
2333
|
+
json: jsonOption("held and away (number, title, holder, since, boxesLeft, boxesTotal), ci (id, status, workflow, started, title), unpushed, dirty (status, path) and stale (issue, comments: path, line)"),
|
|
2334
|
+
...repoOption
|
|
2335
|
+
};
|
|
2336
|
+
async function digest(args) {
|
|
2337
|
+
const parsed = parse(args, usage2, options2);
|
|
2338
|
+
const { values } = parsed;
|
|
2339
|
+
const [issues, sessions, branch, runs] = await Promise.all([openIssues(undefined, values.repo), liveSessions(), defaultBranch(), recentRuns(RUNS_SCANNED, values.repo)]);
|
|
2340
|
+
const comments = await commentsOfAll(issues, values.repo);
|
|
2341
|
+
const me = await currentSession(sessions);
|
|
2342
|
+
const author = await sessionAuthor();
|
|
2343
|
+
const rows = issues.map((issue) => ({ issue, claim: latestClaim(comments.get(issue.number) ?? [], author) }));
|
|
2344
|
+
const [unpushed, dirty, stale] = await Promise.all([quietly(unpushedCommits), quietly(dirtyTree), staleTodos()]);
|
|
2345
|
+
const summary = { ...claims(rows, sessions, me), ci: unsettled(runs, branch), unpushed, dirty, stale };
|
|
2346
|
+
if (values.json === true)
|
|
2347
|
+
printJson(summary);
|
|
2348
|
+
else
|
|
2349
|
+
console.log(renderDigest(summary));
|
|
2350
|
+
return 0;
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
// src/commands/triage.ts
|
|
2354
|
+
async function checkLabels(names, repo) {
|
|
2355
|
+
if (names.length === 0)
|
|
2356
|
+
return;
|
|
2357
|
+
const known = await repoLabels(repo);
|
|
2358
|
+
const missing = names.filter((name) => !known.includes(name));
|
|
2359
|
+
if (missing.length > 0)
|
|
2360
|
+
fail(`no label ${missing.join(", ")} in this repository, ${known.length === 0 ? "which has none" : `it has: ${known.join(", ")}`}`);
|
|
2361
|
+
}
|
|
2362
|
+
var stateOptions = {
|
|
2363
|
+
message: { type: "string", short: "m", description: "a comment posted first, saying why" },
|
|
2364
|
+
...repoOption
|
|
2365
|
+
};
|
|
2366
|
+
async function setState(args, usage, wanted) {
|
|
2367
|
+
const parsed = parse(args, usage, stateOptions);
|
|
2368
|
+
const { values, positionals } = parsed;
|
|
2369
|
+
for (const number of issueNumbers(positionals, usage)) {
|
|
2370
|
+
if ((await getIssue(number, values.repo)).state === wanted) {
|
|
2371
|
+
console.log(`#${number} is already ${wanted}`);
|
|
2372
|
+
continue;
|
|
2373
|
+
}
|
|
2374
|
+
if (values.message !== undefined && values.message.trim() !== "")
|
|
2375
|
+
await comment(number, values.message.trim(), values.repo);
|
|
2376
|
+
if (wanted === "closed")
|
|
2377
|
+
await close(number, values.repo);
|
|
2378
|
+
else
|
|
2379
|
+
await reopen(number, values.repo);
|
|
2380
|
+
console.log(`${wanted === "closed" ? "closed" : "reopened"} #${number}`);
|
|
2381
|
+
}
|
|
2382
|
+
return 0;
|
|
2383
|
+
}
|
|
2384
|
+
var closeUsage = `ft close <n>... [-m <reason>]
|
|
2385
|
+
|
|
2386
|
+
Closes issues without a fix, a duplicate or one dropped, posting the -m reason first. \`ft fixed\` closes one a commit fixed.
|
|
2387
|
+
|
|
2388
|
+
Exits 0 when every issue is closed, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
2389
|
+
async function closeIssues(args) {
|
|
2390
|
+
return setState(args, closeUsage, "closed");
|
|
2391
|
+
}
|
|
2392
|
+
var reopenUsage = `ft reopen <n>... [-m <reason>]
|
|
2393
|
+
|
|
2394
|
+
Reopens closed issues, posting the -m reason first.
|
|
2395
|
+
|
|
2396
|
+
Exits 0 when every issue is open, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
2397
|
+
async function reopenIssues(args) {
|
|
2398
|
+
return setState(args, reopenUsage, "open");
|
|
2399
|
+
}
|
|
2400
|
+
var LABEL_FLAGS = new Set(["-h", "--help"]);
|
|
2401
|
+
var REPO_FLAGS = new Set(["-r", "--repo"]);
|
|
2402
|
+
function labelChanges(args) {
|
|
2403
|
+
const rest = [];
|
|
2404
|
+
const add = [];
|
|
2405
|
+
const remove = [];
|
|
2406
|
+
for (let at = 0;at < args.length; at++) {
|
|
2407
|
+
const arg = args[at] ?? "";
|
|
2408
|
+
if (REPO_FLAGS.has(arg) && at + 1 < args.length)
|
|
2409
|
+
rest.push(arg, args[++at] ?? "");
|
|
2410
|
+
else if (arg.startsWith("+") && arg.length > 1)
|
|
2411
|
+
add.push(arg.slice(1));
|
|
2412
|
+
else if (arg.startsWith("-") && !arg.startsWith("--") && arg.length > 1 && !LABEL_FLAGS.has(arg) && !REPO_FLAGS.has(arg))
|
|
2413
|
+
remove.push(arg.slice(1));
|
|
2414
|
+
else
|
|
2415
|
+
rest.push(arg);
|
|
2416
|
+
}
|
|
2417
|
+
return { rest, add, remove };
|
|
2418
|
+
}
|
|
2419
|
+
var labelUsage = `ft label <n> [+]<label>... -<label>...
|
|
2420
|
+
|
|
2421
|
+
Adds the labels named bare or with +, removes those named with -, then prints the issue's labels. A label the repository lacks is refused.
|
|
2422
|
+
|
|
2423
|
+
Exits 0 when it changed the labels, 1 when Forgejo refuses, 2 on a usage error or a label the repository lacks.`;
|
|
2424
|
+
async function label(args) {
|
|
2425
|
+
const changes = labelChanges(args);
|
|
2426
|
+
const parsed = parse(changes.rest, labelUsage, repoOption);
|
|
2427
|
+
const { values, positionals } = parsed;
|
|
2428
|
+
const number = issueNumber(positionals[0], labelUsage);
|
|
2429
|
+
const add = [...positionals.slice(1), ...changes.add];
|
|
2430
|
+
const { remove } = changes;
|
|
2431
|
+
if (add.length === 0 && remove.length === 0)
|
|
2432
|
+
fail(`name labels to add or remove
|
|
2433
|
+
|
|
2434
|
+
${labelUsage}`);
|
|
2435
|
+
const both = add.filter((name) => remove.includes(name));
|
|
2436
|
+
if (both.length > 0)
|
|
2437
|
+
fail(`${both.join(", ")} is both added and removed`);
|
|
2438
|
+
await checkLabels(add, values.repo);
|
|
2439
|
+
await editLabels(number, add, remove, values.repo);
|
|
2440
|
+
const labels = (await getIssue(number, values.repo)).labels.map((each) => each.name);
|
|
2441
|
+
console.log(`#${number} labels: ${labels.length === 0 ? "none" : labels.join(", ")}`);
|
|
2442
|
+
return 0;
|
|
2443
|
+
}
|
|
2444
|
+
|
|
2445
|
+
// src/commands/issue.ts
|
|
2446
|
+
var issueUsage = `ft issue <n>...
|
|
2447
|
+
|
|
2448
|
+
Prints each issue: its title, state, boxes left and claim, then its description with each checklist box numbered as \`ft tick\` takes it.
|
|
2449
|
+
With --body, prints only the raw description, to edit and give back to \`ft edit -F\`.
|
|
2450
|
+
|
|
2451
|
+
Exits 0 when it printed them, 1 when an issue cannot be read, 2 on a usage error.`;
|
|
2452
|
+
var issueOptions = {
|
|
2453
|
+
todo: { type: "boolean", short: "t", description: "only the header and the boxes left to tick" },
|
|
2454
|
+
comments: { type: "boolean", short: "c", description: "add the comments, each with its author and age" },
|
|
2455
|
+
body: { type: "boolean", short: "b", description: "only the raw description, without numbered boxes" },
|
|
2456
|
+
json: jsonOption("number, title, state, url, labels, claim, boxes, body and comments, an array for several issues"),
|
|
2457
|
+
...repoOption
|
|
2458
|
+
};
|
|
2459
|
+
function renderIssue(found, comments, view, now = Date.now()) {
|
|
2460
|
+
const claim = latestClaim(comments, view.author);
|
|
2461
|
+
const list = boxes(found.body);
|
|
2462
|
+
const left = list.filter((box) => !box.done);
|
|
2463
|
+
const facts = [found.state];
|
|
2464
|
+
if (list.length > 0)
|
|
2465
|
+
facts.push(`${left.length} of ${list.length} boxes left`);
|
|
2466
|
+
if (claim !== undefined)
|
|
2467
|
+
facts.push(`taken by ${claim.holder} ${formatAge(claim.at, now)}`);
|
|
2468
|
+
const header = `#${found.number} ${found.title} (${facts.join(", ")})`;
|
|
2469
|
+
if (view.todo)
|
|
2470
|
+
return [header, ...left.map((box) => `${String(box.number).padStart(3)} [ ] ${box.text}`)].join(`
|
|
2471
|
+
`);
|
|
2472
|
+
const parts = [`${header}
|
|
2473
|
+
${found.html_url}`];
|
|
2474
|
+
const body = numberedBody(found.body);
|
|
2475
|
+
if (body !== "")
|
|
2476
|
+
parts.push(body);
|
|
2477
|
+
if (view.comments) {
|
|
2478
|
+
for (const each of comments)
|
|
2479
|
+
parts.push(`--- ${each.user.login}, ${formatAge(each.created_at, now)}
|
|
2480
|
+
${each.body.replaceAll(`\r
|
|
2481
|
+
`, `
|
|
2482
|
+
`).trim()}`);
|
|
2483
|
+
}
|
|
2484
|
+
return parts.join(`
|
|
2485
|
+
|
|
2486
|
+
`);
|
|
2487
|
+
}
|
|
2488
|
+
function issueJson(found, comments, author) {
|
|
2489
|
+
return {
|
|
2490
|
+
number: found.number,
|
|
2491
|
+
title: found.title,
|
|
2492
|
+
state: found.state,
|
|
2493
|
+
url: found.html_url,
|
|
2494
|
+
labels: found.labels.map((label) => label.name),
|
|
2495
|
+
claim: latestClaim(comments, author) ?? null,
|
|
2496
|
+
boxes: boxes(found.body).map(({ number, done, text }) => ({ number, done, text })),
|
|
2497
|
+
body: found.body,
|
|
2498
|
+
comments: comments.map((each) => ({ author: each.user.login, at: each.created_at, body: each.body }))
|
|
2499
|
+
};
|
|
2500
|
+
}
|
|
2501
|
+
async function issue(args) {
|
|
2502
|
+
const parsed = parse(args, issueUsage, issueOptions);
|
|
2503
|
+
const { values, positionals } = parsed;
|
|
2504
|
+
const numbers = issueNumbers(positionals, issueUsage);
|
|
2505
|
+
if (values.body === true) {
|
|
2506
|
+
const bodies = await Promise.all(numbers.map(async (number) => (await getIssue(number, values.repo)).body.replaceAll(`\r
|
|
2507
|
+
`, `
|
|
2508
|
+
`)));
|
|
2509
|
+
console.log(bodies.join(`
|
|
2510
|
+
|
|
2511
|
+
`));
|
|
2512
|
+
return 0;
|
|
2513
|
+
}
|
|
2514
|
+
const read = await Promise.all(numbers.map(async (number) => Promise.all([getIssue(number, values.repo), commentsOf(number, values.repo)])));
|
|
2515
|
+
const author = await sessionAuthor();
|
|
2516
|
+
if (values.json === true) {
|
|
2517
|
+
const json = read.map(([found, comments]) => issueJson(found, comments, author));
|
|
2518
|
+
printJson(json.length === 1 ? json[0] : json);
|
|
2519
|
+
return 0;
|
|
2520
|
+
}
|
|
2521
|
+
const view = { todo: values.todo === true, comments: values.comments === true, author };
|
|
2522
|
+
console.log(read.map(([found, comments]) => renderIssue(found, comments, view)).join(view.todo ? `
|
|
2523
|
+
|
|
2524
|
+
` : `
|
|
2525
|
+
|
|
2526
|
+
|
|
2527
|
+
`));
|
|
2528
|
+
return 0;
|
|
2529
|
+
}
|
|
2530
|
+
var noteOptions = {
|
|
2531
|
+
message: { type: "string", short: "m", description: "comment this text on the issue" },
|
|
2532
|
+
file: { type: "string", short: "F", description: "comment the text of this file, - for stdin" }
|
|
2533
|
+
};
|
|
2534
|
+
async function noteText(values) {
|
|
2535
|
+
if (values.message !== undefined && values.file !== undefined)
|
|
2536
|
+
fail("give the comment once, as text or with -F");
|
|
2537
|
+
const text = values.file === undefined ? values.message : await readInput(values.file);
|
|
2538
|
+
return text?.trim() === "" ? undefined : text?.trim();
|
|
2539
|
+
}
|
|
2540
|
+
var NOT_FOUND = /not exist|not found|couldn't be found/i;
|
|
2541
|
+
async function isClosed(number, repo) {
|
|
2542
|
+
try {
|
|
2543
|
+
return (await getIssue(number, repo)).state === "closed";
|
|
2544
|
+
} catch (error) {
|
|
2545
|
+
if (error instanceof Error && NOT_FOUND.test(error.message))
|
|
2546
|
+
return false;
|
|
2547
|
+
throw error;
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
async function closedReferences(body, repo) {
|
|
2551
|
+
const listed = [...new Set(referencedBoxes(body).filter(({ box }) => !box.done).map(({ issue }) => issue))];
|
|
2552
|
+
const states = await Promise.all(listed.map(async (issue) => isClosed(issue, repo)));
|
|
2553
|
+
return new Set(listed.filter((_, at) => states[at] === true));
|
|
2554
|
+
}
|
|
2555
|
+
var newUsage = `ft new -t <title> [-F <file>] [-L a,b] [-m <milestone>]
|
|
2556
|
+
|
|
2557
|
+
Creates an issue and prints its number and url. The description is read from -F <file>, or from stdin with -F -, and is empty without it. A label or milestone the repository lacks is refused before anything is created.
|
|
2558
|
+
|
|
2559
|
+
Exits 0 when it created the issue, 1 when Forgejo refuses, 2 on a usage error or a label or milestone the repository lacks.`;
|
|
2560
|
+
var newOptions = {
|
|
2561
|
+
title: { type: "string", short: "t", description: "the issue title" },
|
|
2562
|
+
file: { type: "string", short: "F", description: "the description: a file, - for stdin" },
|
|
2563
|
+
labels: { type: "string", short: "L", description: "comma-separated labels" },
|
|
2564
|
+
milestone: { type: "string", short: "m", description: "the milestone, a title or an id; the repository must have it" },
|
|
2565
|
+
...repoOption
|
|
2566
|
+
};
|
|
2567
|
+
async function milestoneTitle(reference, repo) {
|
|
2568
|
+
if (reference === undefined)
|
|
2569
|
+
return;
|
|
2570
|
+
return reference.trim() === "" ? "" : (await findMilestone(reference.trim(), repo)).title;
|
|
2571
|
+
}
|
|
2572
|
+
async function newIssue(args) {
|
|
2573
|
+
const parsed = parse(args, newUsage, newOptions);
|
|
2574
|
+
const { values } = parsed;
|
|
2575
|
+
if (values.title === undefined || values.title.trim() === "")
|
|
2576
|
+
fail(`give the issue a title with -t
|
|
2577
|
+
|
|
2578
|
+
${newUsage}`);
|
|
2579
|
+
const body = await noteText({ file: values.file });
|
|
2580
|
+
await checkLabels((values.labels ?? "").split(",").map((name) => name.trim()).filter((name) => name !== ""), values.repo);
|
|
2581
|
+
const milestone = await milestoneTitle(values.milestone, values.repo);
|
|
2582
|
+
const created = await createIssue(values.title.trim(), body ?? "", values.labels, milestone === "" ? undefined : milestone, values.repo);
|
|
2583
|
+
console.log(`#${created.number} ${created.html_url}`);
|
|
2584
|
+
return 0;
|
|
2585
|
+
}
|
|
2586
|
+
var editUsage = `ft edit <n> [-t <title>] [-F <file> [--append]] [--add-box <text>]... [-m <milestone>]
|
|
2587
|
+
|
|
2588
|
+
Replaces the title and/or the description of issue <n>, the description from -F <file> or from stdin with -F -.
|
|
2589
|
+
-m moves it to a milestone given by title or id, and \`-m ''\` takes it out of its milestone.
|
|
2590
|
+
--append adds the -F text after the description instead, and each --add-box an unticked box after the last one, the rest of the description untouched.
|
|
2591
|
+
\`ft issue <n> --body\` prints the description to edit.
|
|
2592
|
+
|
|
2593
|
+
Exits 0 when it edited the issue, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
2594
|
+
var editOptions = {
|
|
2595
|
+
title: { type: "string", short: "t", description: "the new title" },
|
|
2596
|
+
file: { type: "string", short: "F", description: "the new description: a file, - for stdin" },
|
|
2597
|
+
append: { type: "boolean", short: "a", description: "add the -F text after the description instead of replacing it" },
|
|
2598
|
+
"add-box": { type: "string", multiple: true, description: "add an unticked box after the last one, repeatable" },
|
|
2599
|
+
milestone: { type: "string", short: "m", description: "move the issue to this milestone, a title or an id; an empty value takes it out of its milestone" },
|
|
2600
|
+
...repoOption
|
|
2601
|
+
};
|
|
2602
|
+
async function edit(args) {
|
|
2603
|
+
const parsed = parse(args, editUsage, editOptions);
|
|
2604
|
+
const { values, positionals } = parsed;
|
|
2605
|
+
const number = issueNumber(positionals[0], editUsage);
|
|
2606
|
+
const text = await noteText({ file: values.file });
|
|
2607
|
+
const added = values["add-box"] ?? [];
|
|
2608
|
+
if (values.file !== undefined && text === undefined)
|
|
2609
|
+
fail("the description file is empty");
|
|
2610
|
+
if (values.append === true && text === undefined)
|
|
2611
|
+
fail("--append adds the -F text, give -F");
|
|
2612
|
+
if (values.title === undefined && text === undefined && added.length === 0 && values.milestone === undefined)
|
|
2613
|
+
fail(`nothing to change: give -t, -F, --add-box or -m
|
|
2614
|
+
|
|
2615
|
+
${editUsage}`);
|
|
2616
|
+
const change = values.title === undefined ? {} : { title: values.title.trim() };
|
|
2617
|
+
const milestone = await milestoneTitle(values.milestone, values.repo);
|
|
2618
|
+
if (milestone !== undefined)
|
|
2619
|
+
change.milestone = milestone;
|
|
2620
|
+
const grows = text !== undefined && values.append === true || added.length > 0;
|
|
2621
|
+
if (text !== undefined && !grows)
|
|
2622
|
+
change.body = text;
|
|
2623
|
+
if (Object.keys(change).length > 0)
|
|
2624
|
+
await editIssue(number, change, values.repo);
|
|
2625
|
+
if (grows) {
|
|
2626
|
+
await editBody(number, (body) => {
|
|
2627
|
+
const appended = text !== undefined && values.append === true && !body.trimEnd().endsWith(text) ? `${body.trimEnd()}
|
|
2628
|
+
|
|
2629
|
+
${text}` : body;
|
|
2630
|
+
const present = new Set(boxes(appended).map((box) => box.text));
|
|
2631
|
+
const missing = added.filter((box) => !present.has(box));
|
|
2632
|
+
return missing.length > 0 ? appendBoxes(appended, missing) : appended;
|
|
2633
|
+
}, values.repo);
|
|
2634
|
+
}
|
|
2635
|
+
console.log(`edited #${number}`);
|
|
2636
|
+
return 0;
|
|
2637
|
+
}
|
|
2638
|
+
var tickUsage = `ft tick <n> <box>...
|
|
2639
|
+
|
|
2640
|
+
Ticks checklist boxes of issue <n>, each given by its number from \`ft issue\` or by text matching exactly one box, then posts the -m or -F comment.
|
|
2641
|
+
With --closed, ticks instead every box opening with \`#<issue>\` whose issue is closed, as a release plan lists them.
|
|
2642
|
+
|
|
2643
|
+
Exits 0 when it ticked the boxes, 1 when Forgejo refuses, 2 on a usage error or a box matching none or several.`;
|
|
2644
|
+
var tickOptions = {
|
|
2645
|
+
undo: { type: "boolean", short: "u", description: "untick them instead" },
|
|
2646
|
+
closed: { type: "boolean", description: "tick the boxes listing a closed issue, no box to name" },
|
|
2647
|
+
...noteOptions,
|
|
2648
|
+
...repoOption
|
|
2649
|
+
};
|
|
2650
|
+
function tickedOrFail(number, run) {
|
|
2651
|
+
try {
|
|
2652
|
+
return run();
|
|
2653
|
+
} catch (error) {
|
|
2654
|
+
fail(`#${number}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
async function tick(args) {
|
|
2658
|
+
const parsed = parse(args, tickUsage, tickOptions);
|
|
2659
|
+
const { values, positionals } = parsed;
|
|
2660
|
+
const number = issueNumber(positionals[0], tickUsage);
|
|
2661
|
+
const picks = positionals.slice(1);
|
|
2662
|
+
if (values.closed === true && (picks.length > 0 || values.undo === true))
|
|
2663
|
+
fail(`--closed takes no boxes and no --undo
|
|
2664
|
+
|
|
2665
|
+
${tickUsage}`);
|
|
2666
|
+
if (picks.length === 0 && values.closed !== true)
|
|
2667
|
+
fail(`name the boxes to tick
|
|
2668
|
+
|
|
2669
|
+
${tickUsage}`);
|
|
2670
|
+
const note = await noteText(values);
|
|
2671
|
+
const found = await getIssue(number, values.repo);
|
|
2672
|
+
const done = values.undo !== true;
|
|
2673
|
+
const closed = values.closed === true ? await closedReferences(found.body, values.repo) : undefined;
|
|
2674
|
+
const apply = (body) => closed === undefined ? setBoxes(body, picks, done) : tickReferences(body, (issue) => closed.has(issue));
|
|
2675
|
+
let result = tickedOrFail(number, () => apply(found.body));
|
|
2676
|
+
if (result.changed.length > 0) {
|
|
2677
|
+
await editBody(number, (body) => {
|
|
2678
|
+
result = tickedOrFail(number, () => apply(body));
|
|
2679
|
+
return result.body;
|
|
2680
|
+
}, values.repo);
|
|
2681
|
+
}
|
|
2682
|
+
for (const box of result.changed)
|
|
2683
|
+
console.log(`${done ? "ticked" : "unticked"} ${box.number}: ${box.text}`);
|
|
2684
|
+
const left = boxes(result.body).filter((box) => !box.done).length;
|
|
2685
|
+
console.log(`#${number}: ${result.changed.length === 0 ? "nothing to change, " : ""}${left} box${left === 1 ? "" : "es"} left`);
|
|
2686
|
+
if (note !== undefined) {
|
|
2687
|
+
await comment(number, note, values.repo);
|
|
2688
|
+
console.log(`commented on #${number}`);
|
|
2689
|
+
}
|
|
2690
|
+
return 0;
|
|
2691
|
+
}
|
|
2692
|
+
var commentUsage = `ft comment <n> [text]
|
|
2693
|
+
|
|
2694
|
+
Posts a comment on issue <n>: the text given, -F <file>, or stdin when neither is, so a heredoc needs no escaping.
|
|
2695
|
+
|
|
2696
|
+
Exits 0 when it posted the comment, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
2697
|
+
var commentOptions = {
|
|
2698
|
+
file: noteOptions.file,
|
|
2699
|
+
...repoOption
|
|
2700
|
+
};
|
|
2701
|
+
async function commentOn(args) {
|
|
2702
|
+
const parsed = parse(args, commentUsage, commentOptions);
|
|
2703
|
+
const { values, positionals } = parsed;
|
|
2704
|
+
const number = issueNumber(positionals[0], commentUsage);
|
|
2705
|
+
const given = positionals.slice(1).join(" ") || undefined;
|
|
2706
|
+
const text = await noteText({ message: given, file: values.file ?? (given === undefined ? "-" : undefined) });
|
|
2707
|
+
if (text === undefined)
|
|
2708
|
+
fail(`nothing to comment
|
|
2709
|
+
|
|
2710
|
+
${commentUsage}`);
|
|
2711
|
+
await comment(number, text, values.repo);
|
|
2712
|
+
console.log(`commented on #${number}`);
|
|
2713
|
+
return 0;
|
|
2714
|
+
}
|
|
2715
|
+
var fixedUsage = `ft fixed <n> [commit]...
|
|
2716
|
+
|
|
2717
|
+
Comments "Fixed in <sha>: <message>" on issue <n> and closes it, naming each commit given as "Fixed in <a>, <b> and <c>".
|
|
2718
|
+
Without a commit it takes those on origin's default branch whose message names #<n>, and says which, or HEAD when none does.
|
|
2719
|
+
The message defaults to the subject of the first commit. Every open issue listing \`- [ ] #<n>\` in its checklist gets that line ticked. An issue with boxes left is refused, as a partly done issue stays open, unless --tick ticks them first.
|
|
2720
|
+
|
|
2721
|
+
Exits 0 when it closed the issue, 1 when the issue is already closed, has boxes left or Forgejo refuses, 2 on a usage error.`;
|
|
2722
|
+
var fixedOptions = {
|
|
2723
|
+
message: { type: "string", short: "m", description: 'the line after "Fixed in <sha>:"' },
|
|
2724
|
+
tick: { type: "boolean", description: "tick the boxes left before closing" },
|
|
2725
|
+
force: { type: "boolean", description: "close even with boxes left" },
|
|
2726
|
+
...repoOption
|
|
2727
|
+
};
|
|
2728
|
+
function joinShas(shas) {
|
|
2729
|
+
const last = shas.at(-1) ?? "";
|
|
2730
|
+
return shas.length < 2 ? last : `${shas.slice(0, -1).join(", ")} and ${last}`;
|
|
2731
|
+
}
|
|
2732
|
+
async function fixingCommits(number, given) {
|
|
2733
|
+
if (given.length > 0) {
|
|
2734
|
+
const named = [];
|
|
2735
|
+
for (const ref of given) {
|
|
2736
|
+
const sha = await resolveCommit(ref);
|
|
2737
|
+
named.push({ sha, subject: await git(["log", "-1", "--format=%s", sha]) });
|
|
2738
|
+
}
|
|
2739
|
+
return named;
|
|
2740
|
+
}
|
|
2741
|
+
const ref = `origin/${await defaultBranch()}`;
|
|
2742
|
+
const found = await commitsNaming(number, ref);
|
|
2743
|
+
if (found.length > 0) {
|
|
2744
|
+
console.log(`commits on ${ref} naming #${number}:
|
|
2745
|
+
${found.map((each) => ` ${each.sha.slice(0, 7)} ${each.subject}`).join(`
|
|
2746
|
+
`)}`);
|
|
2747
|
+
return found;
|
|
2748
|
+
}
|
|
2749
|
+
const sha = await resolveCommit("HEAD");
|
|
2750
|
+
console.log(`no commit on ${ref} names #${number}, using HEAD`);
|
|
2751
|
+
return [{ sha, subject: await git(["log", "-1", "--format=%s", sha]) }];
|
|
2752
|
+
}
|
|
2753
|
+
async function tickListings(closed, repo) {
|
|
2754
|
+
for (const listing of await openIssues(undefined, repo)) {
|
|
2755
|
+
if (!referencedBoxes(listing.body).some(({ box, issue }) => issue === closed && !box.done))
|
|
2756
|
+
continue;
|
|
2757
|
+
if (await editBody(listing.number, (body) => tickReferences(body, (issue) => issue === closed).body, repo))
|
|
2758
|
+
console.log(`ticked #${closed} in #${listing.number}`);
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
async function fixed(args) {
|
|
2762
|
+
const parsed = parse(args, fixedUsage, fixedOptions);
|
|
2763
|
+
const { values, positionals } = parsed;
|
|
2764
|
+
const number = issueNumber(positionals[0], fixedUsage);
|
|
2765
|
+
const commits = await fixingCommits(number, positionals.slice(1));
|
|
2766
|
+
const found = await getIssue(number, values.repo);
|
|
2767
|
+
if (found.state === "closed")
|
|
2768
|
+
fail(`#${number} is already closed`, 1, runHint(`ft reopen ${number}`, "reopen it"));
|
|
2769
|
+
const left = boxes(found.body).filter((box) => !box.done);
|
|
2770
|
+
if (left.length > 0 && values.tick === true) {
|
|
2771
|
+
await editBody(number, (body) => setBoxes(body, boxes(body).filter((box) => !box.done).map((box) => String(box.number)), true).body, values.repo);
|
|
2772
|
+
console.log(`ticked ${left.length} box${left.length === 1 ? "" : "es"} of #${number}`);
|
|
2773
|
+
} else if (left.length > 0 && values.force !== true) {
|
|
2774
|
+
fail(`#${number} has ${left.length} boxes left:
|
|
2775
|
+
${left.map((box) => `${String(box.number).padStart(3)} [ ] ${box.text}`).join(`
|
|
2776
|
+
`)}`, 1, `${runHint(`ft fixed ${number} --tick`, "tick them and close")}, or ${runHint(`ft fixed ${number} --force`, "close with them left")}`);
|
|
2777
|
+
}
|
|
2778
|
+
const shas = joinShas(commits.map((each) => each.sha.slice(0, 7)));
|
|
2779
|
+
const line = `Fixed in ${shas}: ${values.message ?? commits[0]?.subject ?? ""}`;
|
|
2780
|
+
if ((await commentsOf(number, values.repo)).at(-1)?.body.trim() !== line.trim())
|
|
2781
|
+
await comment(number, line, values.repo);
|
|
2782
|
+
await close(number, values.repo);
|
|
2783
|
+
console.log(`closed #${number}: fixed in ${shas}`);
|
|
2784
|
+
await tickListings(number, values.repo);
|
|
2785
|
+
return 0;
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
// src/commands/logs.ts
|
|
2789
|
+
var usage3 = `ft logs <run id>
|
|
2790
|
+
|
|
2791
|
+
Prints what the failed jobs of a run say went wrong: each failed bun test's output and the end of each failed step.
|
|
2792
|
+
With no failed job it prints every job's last lines; --full prints whole logs.
|
|
2793
|
+
|
|
2794
|
+
Exits 0 when it printed the logs, 1 when Forgejo cannot be read, 2 on a usage error or a job the run lacks.`;
|
|
2795
|
+
var options3 = {
|
|
2796
|
+
job: { type: "string", short: "j", description: "only this job, by name or id" },
|
|
2797
|
+
full: { type: "boolean", short: "f", description: "the whole log, timestamps stripped" },
|
|
2798
|
+
...repoOption
|
|
2799
|
+
};
|
|
2800
|
+
function pickJobs(jobs, wanted) {
|
|
2801
|
+
if (wanted !== undefined)
|
|
2802
|
+
return jobs.filter((job) => job.name === wanted || String(job.id) === wanted);
|
|
2803
|
+
const failed = jobs.filter((job) => job.status === "failure");
|
|
2804
|
+
return failed.length > 0 ? failed : jobs;
|
|
2805
|
+
}
|
|
2806
|
+
async function logs2(args) {
|
|
2807
|
+
const parsed = parse(args, usage3, options3);
|
|
2808
|
+
const { values, positionals } = parsed;
|
|
2809
|
+
if (positionals[0] === undefined)
|
|
2810
|
+
fail("a run id is needed", 2, runHint("ft runs", "list them"));
|
|
2811
|
+
const run = await runById(wholeNumber(positionals[0], "<run id>", 0), values.repo);
|
|
2812
|
+
const jobs = await jobsOf(run.id, values.repo);
|
|
2813
|
+
const picked = pickJobs(jobs, values.job);
|
|
2814
|
+
if (picked.length === 0)
|
|
2815
|
+
fail(`run ${run.id} has no job ${values.job ?? ""}: ${jobs.map((job) => job.name).join(", ")}`, 2, runHint(`ft logs ${run.id}`, "read every failed job"));
|
|
2816
|
+
console.log(`${run.workflow_id} run ${run.id} on ${run.prettyref} (${run.commit_sha.slice(0, 7)}): ${badge(run.status, process.stdout)}, ${run.html_url}`);
|
|
2817
|
+
for (const job of picked) {
|
|
2818
|
+
const log = await jobLog(job.id, values.repo);
|
|
2819
|
+
console.log(`
|
|
2820
|
+
job ${job.name}: ${badge(job.status, process.stdout)}
|
|
2821
|
+
${values.full === true ? logLines(log).join(`
|
|
2822
|
+
`) : excerpt(log)}`);
|
|
2823
|
+
}
|
|
2824
|
+
return 0;
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
// src/commands/milestone.ts
|
|
2828
|
+
var TITLE_WIDTH3 = 60;
|
|
2829
|
+
var LIST_LIMIT = 30;
|
|
2830
|
+
function counts(milestone) {
|
|
2831
|
+
return `${milestone.open_issues} open, ${milestone.closed_issues} closed`;
|
|
2832
|
+
}
|
|
2833
|
+
var listUsage = `ft milestones
|
|
2834
|
+
|
|
2835
|
+
Lists the repository's milestones, the open ones unless --state says otherwise, with the issues open and closed in each, the progress and the due date.
|
|
2836
|
+
|
|
2837
|
+
Exits 0 when it listed them, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
2838
|
+
var listOptions = {
|
|
2839
|
+
state: { type: "string", description: "open (the default), closed or all" },
|
|
2840
|
+
...limitOptions(LIST_LIMIT),
|
|
2841
|
+
json: jsonOption("id, title, state, description, open, closed, due (YYYY-MM-DD or null)"),
|
|
2842
|
+
...repoOption
|
|
2843
|
+
};
|
|
2844
|
+
async function milestones(args) {
|
|
2845
|
+
const parsed = parse(args, listUsage, listOptions);
|
|
2846
|
+
const { values } = parsed;
|
|
2847
|
+
const state = values.state ?? "open";
|
|
2848
|
+
if (state !== "open" && state !== "closed" && state !== "all")
|
|
2849
|
+
fail(`--state takes open, closed or all, not ${state}`);
|
|
2850
|
+
const limit = limitOf(values, LIST_LIMIT);
|
|
2851
|
+
const found = await listMilestones(state, values.repo);
|
|
2852
|
+
if (values.json === true) {
|
|
2853
|
+
printJson(found.map((each) => ({ id: each.id, title: each.title, state: each.state, description: each.description, open: each.open_issues, closed: each.closed_issues, due: dueDate(each) || null })));
|
|
2854
|
+
return 0;
|
|
2855
|
+
}
|
|
2856
|
+
if (found.length === 0) {
|
|
2857
|
+
console.log(`no ${state === "all" ? "" : `${state} `}milestone`);
|
|
2858
|
+
return 0;
|
|
2859
|
+
}
|
|
2860
|
+
const { shown, footer } = capped(found, limit);
|
|
2861
|
+
const showState = state === "all";
|
|
2862
|
+
const rows = shown.map((each) => [String(each.id), truncate(each.title, TITLE_WIDTH3), `${each.open_issues} open`, `${each.closed_issues} closed`, progress(each), dueDate(each) === "" ? "" : `due ${dueDate(each)}`, ...showState ? [each.state] : []]);
|
|
2863
|
+
console.log(table(rows));
|
|
2864
|
+
if (footer !== undefined)
|
|
2865
|
+
console.log(footer);
|
|
2866
|
+
return 0;
|
|
2867
|
+
}
|
|
2868
|
+
var newUsage2 = `ft milestone new <title> [-d <text>] [--due <YYYY-MM-DD>]
|
|
2869
|
+
|
|
2870
|
+
Creates a milestone through the API and prints its id. Without --due it has no due date.
|
|
2871
|
+
|
|
2872
|
+
Exits 0 when it created the milestone, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
2873
|
+
var newOptions2 = {
|
|
2874
|
+
description: { type: "string", short: "d", description: "the milestone description" },
|
|
2875
|
+
due: { type: "string", description: "the due date, YYYY-MM-DD" },
|
|
2876
|
+
...repoOption
|
|
2877
|
+
};
|
|
2878
|
+
async function create(args) {
|
|
2879
|
+
const parsed = parse(args, newUsage2, newOptions2);
|
|
2880
|
+
const { values, positionals } = parsed;
|
|
2881
|
+
const title = positionals.join(" ").trim();
|
|
2882
|
+
if (title === "")
|
|
2883
|
+
fail(`give the milestone a title
|
|
2884
|
+
|
|
2885
|
+
${newUsage2}`);
|
|
2886
|
+
const due = values.due === undefined ? undefined : dueOn(values.due);
|
|
2887
|
+
const created = await createMilestone(title, values.description, due, values.repo);
|
|
2888
|
+
console.log(`milestone ${created.id} ${created.title}${dueDate(created) === "" ? "" : `, due ${dueDate(created)}`}`);
|
|
2889
|
+
return 0;
|
|
2890
|
+
}
|
|
2891
|
+
var closeUsage2 = `ft milestone close <title|id> [--force]
|
|
2892
|
+
|
|
2893
|
+
Closes a milestone, refused while issues are open in it, which it names. --force closes it with them left.
|
|
2894
|
+
|
|
2895
|
+
Exits 0 when it closed the milestone, 1 when issues are open in it or Forgejo refuses, 2 on a usage error.`;
|
|
2896
|
+
var closeOptions = {
|
|
2897
|
+
force: { type: "boolean", description: "close it with issues left open" },
|
|
2898
|
+
...repoOption
|
|
2899
|
+
};
|
|
2900
|
+
async function closeOne(args) {
|
|
2901
|
+
const parsed = parse(args, closeUsage2, closeOptions);
|
|
2902
|
+
const { values, positionals } = parsed;
|
|
2903
|
+
const reference = positionals.join(" ").trim();
|
|
2904
|
+
if (reference === "")
|
|
2905
|
+
fail(`name the milestone to close
|
|
2906
|
+
|
|
2907
|
+
${closeUsage2}`);
|
|
2908
|
+
const found = await findMilestone(reference, values.repo);
|
|
2909
|
+
if (found.state === "closed") {
|
|
2910
|
+
console.log(`milestone ${found.title} is already closed`);
|
|
2911
|
+
return 0;
|
|
2912
|
+
}
|
|
2913
|
+
const open = await openIssues(undefined, values.repo, found.id);
|
|
2914
|
+
if (open.length > 0 && values.force !== true)
|
|
2915
|
+
fail(`milestone ${found.title} has ${open.length} open issue${open.length === 1 ? "" : "s"}:
|
|
2916
|
+
${open.map((issue) => ` #${issue.number} ${truncate(issue.title, TITLE_WIDTH3)}`).join(`
|
|
2917
|
+
`)}`, 1, `${runHint(`ft milestone close ${found.title} --force`, "close it with them open")}, or move them with \`ft edit <n> -m <milestone>\``);
|
|
2918
|
+
await closeMilestone(found.id, values.repo);
|
|
2919
|
+
console.log(`closed milestone ${found.title}`);
|
|
2920
|
+
return 0;
|
|
2921
|
+
}
|
|
2922
|
+
var showUsage = `ft milestone <title|id>
|
|
2923
|
+
ft milestone new <title> [-d <text>] [--due <YYYY-MM-DD>]
|
|
2924
|
+
ft milestone close <title|id> [--force]
|
|
2925
|
+
|
|
2926
|
+
Shows a milestone with its open issues as \`ft board\` does: available, taken by a session running here, or claimed by one gone, each with its boxes left, at most 30 of each kind (--full for all).
|
|
2927
|
+
\`ft milestone new\` and \`ft milestone close\` have their own --help; a milestone titled new or close is named by its id.
|
|
2928
|
+
|
|
2929
|
+
Exits 0 when it showed the milestone, 1 when it cannot be read, 2 on a usage error or an unknown milestone.`;
|
|
2930
|
+
var showOptions = {
|
|
2931
|
+
...limitOptions(LIST_LIMIT),
|
|
2932
|
+
json: jsonOption("the milestone (id, title, state, description, open, closed, due) and its open issues as `ft board --json` lists them"),
|
|
2933
|
+
...repoOption
|
|
2934
|
+
};
|
|
2935
|
+
async function show(args) {
|
|
2936
|
+
const parsed = parse(args, showUsage, showOptions);
|
|
2937
|
+
const { values, positionals } = parsed;
|
|
2938
|
+
const reference = positionals.join(" ").trim();
|
|
2939
|
+
if (reference === "")
|
|
2940
|
+
fail(`name the milestone, or see them all with \`ft milestones\`
|
|
2941
|
+
|
|
2942
|
+
${showUsage}`);
|
|
2943
|
+
const found = await findMilestone(reference, values.repo);
|
|
2944
|
+
const [issues, sessions] = await Promise.all([openIssues(undefined, values.repo, found.id), liveSessions()]);
|
|
2945
|
+
const rows = await boardRows(issues, sessions, values.repo);
|
|
2946
|
+
if (values.json === true) {
|
|
2947
|
+
printJson({ id: found.id, title: found.title, state: found.state, description: found.description, open: found.open_issues, closed: found.closed_issues, due: dueDate(found) || null, issues: boardJson(rows) });
|
|
2948
|
+
return 0;
|
|
2949
|
+
}
|
|
2950
|
+
const facts = [found.state, counts(found), progress(found), dueDate(found) === "" ? "" : `due ${dueDate(found)}`].filter((fact) => fact !== "");
|
|
2951
|
+
console.log(`milestone ${found.title} (${facts.join(", ")})`);
|
|
2952
|
+
if (found.description.trim() !== "")
|
|
2953
|
+
console.log(found.description.trim());
|
|
2954
|
+
console.log(`
|
|
2955
|
+
${renderBoard(rows, Date.now(), limitOf(values, LIST_LIMIT))}`);
|
|
2956
|
+
return 0;
|
|
2957
|
+
}
|
|
2958
|
+
async function milestone(args) {
|
|
2959
|
+
const [first, ...rest] = args;
|
|
2960
|
+
if (first === "new")
|
|
2961
|
+
return create(rest);
|
|
2962
|
+
return first === "close" ? closeOne(rest) : show(args);
|
|
2963
|
+
}
|
|
2964
|
+
|
|
2965
|
+
// src/plan.ts
|
|
2966
|
+
var MARKUP = /^[#*_\s]+|[*_\s]+$/g;
|
|
2967
|
+
function heading(line) {
|
|
2968
|
+
return line.replaceAll(MARKUP, "").toLowerCase();
|
|
2969
|
+
}
|
|
2970
|
+
function insertionPoint(lines, body, section) {
|
|
2971
|
+
const all = boxes(body);
|
|
2972
|
+
if (section === undefined)
|
|
2973
|
+
return all.length === 0 ? undefined : (all.at(-1)?.line ?? 0) + 1;
|
|
2974
|
+
const title = heading(section);
|
|
2975
|
+
const at = lines.findIndex((line) => heading(line) === title);
|
|
2976
|
+
if (at === -1)
|
|
2977
|
+
return;
|
|
2978
|
+
const lineOfBox = new Set(all.map((box) => box.line));
|
|
2979
|
+
let end = at + 1;
|
|
2980
|
+
for (let next = at + 1;next < lines.length; next++) {
|
|
2981
|
+
if (lineOfBox.has(next))
|
|
2982
|
+
end = next + 1;
|
|
2983
|
+
else if (lines[next]?.trim() !== "")
|
|
2984
|
+
break;
|
|
2985
|
+
}
|
|
2986
|
+
return end;
|
|
2987
|
+
}
|
|
2988
|
+
function addLines(body, added, section) {
|
|
2989
|
+
if (added.length === 0)
|
|
2990
|
+
return body;
|
|
2991
|
+
const eol = body.includes(`\r
|
|
2992
|
+
`) ? "\r" : "";
|
|
2993
|
+
const lines = body.split(`
|
|
2994
|
+
`);
|
|
2995
|
+
const at = insertionPoint(lines, body, section);
|
|
2996
|
+
const fresh = added.map((line) => `${line}${eol}`);
|
|
2997
|
+
if (at !== undefined) {
|
|
2998
|
+
lines.splice(at, 0, ...fresh);
|
|
2999
|
+
return lines.join(`
|
|
3000
|
+
`);
|
|
3001
|
+
}
|
|
3002
|
+
const text = body.trimEnd();
|
|
3003
|
+
return `${text}${text === "" ? "" : `${eol}
|
|
3004
|
+
${eol}
|
|
3005
|
+
`}${section === undefined ? "" : `${section}${eol}
|
|
3006
|
+
`}${fresh.join(`
|
|
3007
|
+
`)}${body.endsWith(`
|
|
3008
|
+
`) ? `
|
|
3009
|
+
` : ""}`;
|
|
3010
|
+
}
|
|
3011
|
+
function listedIssues(body) {
|
|
3012
|
+
return new Set(referencedBoxes(body).map(({ issue }) => issue));
|
|
3013
|
+
}
|
|
3014
|
+
function openLines(body) {
|
|
3015
|
+
return referencedBoxes(body).filter(({ box }) => !box.done).map(({ box, issue }) => ({ issue, line: `- [ ] ${box.text}` }));
|
|
3016
|
+
}
|
|
3017
|
+
|
|
3018
|
+
// src/commands/plan.ts
|
|
3019
|
+
var addUsage = `ft plan add <plan> <n>... [--section "Bugs:"]
|
|
3020
|
+
|
|
3021
|
+
Lists each issue <n> as \`- [ ] #<n> <title>\` in the checklist of issue <plan>, skipping those already listed.
|
|
3022
|
+
Lines go under --section, created at the end of the body when missing, or else after the checklist's last box.
|
|
3023
|
+
The body is read again just before it is written, so an edit made meanwhile is kept.
|
|
3024
|
+
|
|
3025
|
+
Exits 0 when it listed the issues, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
3026
|
+
var carryUsage = `ft plan carry <from> <to> [--section "Carried from 1.71.0:"]
|
|
3027
|
+
|
|
3028
|
+
Copies the unticked \`#<n>\` lines of issue <from> into issue <to>, skipping those <to> already lists.
|
|
3029
|
+
Lines go under --section, created at the end of the body when missing, or else after the checklist's last box.
|
|
3030
|
+
The body is read again just before it is written, so an edit made meanwhile is kept.
|
|
3031
|
+
|
|
3032
|
+
Exits 0 when it copied the lines, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
3033
|
+
var options4 = {
|
|
3034
|
+
section: { type: "string", short: "s", description: 'the heading the lines go under, e.g. "Bugs:"' },
|
|
3035
|
+
...repoOption
|
|
3036
|
+
};
|
|
3037
|
+
var plan = {
|
|
3038
|
+
summary: "add issues to a release plan's checklist, or carry its unticked lines to the next plan",
|
|
3039
|
+
commands: {
|
|
3040
|
+
add: { run: add, summary: "list issues in a plan's checklist" },
|
|
3041
|
+
carry: { run: carry, summary: "copy a plan's unticked lines into the next plan" }
|
|
3042
|
+
}
|
|
3043
|
+
};
|
|
3044
|
+
async function add(args) {
|
|
3045
|
+
const parsed = parse(args, addUsage, options4);
|
|
3046
|
+
const { section, repo } = parsed.values;
|
|
3047
|
+
const [target, ...listed] = parsed.positionals;
|
|
3048
|
+
const planNumber = issueNumber(target, addUsage);
|
|
3049
|
+
if (listed.length === 0)
|
|
3050
|
+
fail(`name the issues to add
|
|
3051
|
+
|
|
3052
|
+
${addUsage}`);
|
|
3053
|
+
const numbers = issueNumbers(listed, addUsage);
|
|
3054
|
+
const titled = await Promise.all(numbers.map(async (number) => ({ number, title: (await getIssue(number, repo)).title })));
|
|
3055
|
+
let added = [];
|
|
3056
|
+
await editBody(planNumber, (body) => {
|
|
3057
|
+
const known = listedIssues(body);
|
|
3058
|
+
const fresh = titled.filter(({ number }) => !known.has(number));
|
|
3059
|
+
added = fresh.map(({ number, title }) => `- [ ] #${number} ${title}`);
|
|
3060
|
+
return addLines(body, added, section);
|
|
3061
|
+
}, repo);
|
|
3062
|
+
report(planNumber, added, titled.length - added.length);
|
|
3063
|
+
return 0;
|
|
3064
|
+
}
|
|
3065
|
+
async function carry(args) {
|
|
3066
|
+
const parsed = parse(args, carryUsage, options4);
|
|
3067
|
+
const { section, repo } = parsed.values;
|
|
3068
|
+
const from = issueNumber(parsed.positionals[0], carryUsage);
|
|
3069
|
+
const to = issueNumber(parsed.positionals[1], carryUsage);
|
|
3070
|
+
const source = openLines((await getIssue(from, repo)).body);
|
|
3071
|
+
let added = [];
|
|
3072
|
+
await editBody(to, (body) => {
|
|
3073
|
+
const known = listedIssues(body);
|
|
3074
|
+
added = source.filter(({ issue }) => !known.has(issue)).map(({ line }) => line);
|
|
3075
|
+
return addLines(body, added, section);
|
|
3076
|
+
}, repo);
|
|
3077
|
+
report(to, added, source.length - added.length);
|
|
3078
|
+
return 0;
|
|
3079
|
+
}
|
|
3080
|
+
function report(plan, added, skipped) {
|
|
3081
|
+
for (const line of added)
|
|
3082
|
+
console.log(`#${plan}: ${line}`);
|
|
3083
|
+
console.log(`#${plan}: ${added.length} added${skipped === 0 ? "" : `, ${skipped} already listed`}`);
|
|
3084
|
+
}
|
|
3085
|
+
|
|
3086
|
+
// src/commands/release.ts
|
|
3087
|
+
import { basename as basename2, join as join2, relative, resolve } from "path";
|
|
3088
|
+
import process14 from "process";
|
|
3089
|
+
var {$ } = globalThis.Bun;
|
|
3090
|
+
|
|
3091
|
+
// src/commands/watch.ts
|
|
3092
|
+
var usage4 = `ft watch [--after <id>]
|
|
3093
|
+
|
|
3094
|
+
Waits for runs to finish: those newer than run <id>, or else the ones in progress now.
|
|
3095
|
+
Exits 0 when every one passed or was skipped, 1 when one failed or was cancelled, 2 on a timeout or a stalled queue.`;
|
|
3096
|
+
var options5 = {
|
|
3097
|
+
after: { type: "string", short: "a", description: "watch the runs newer than this run id, as `ft runs --json` gives it" },
|
|
3098
|
+
timeout: { type: "string", short: "t", description: "how long before giving up (15m), a bare number in minutes" },
|
|
3099
|
+
...repoOption
|
|
3100
|
+
};
|
|
3101
|
+
var timing = { poll: 1e4 };
|
|
3102
|
+
var LIMIT = 20;
|
|
3103
|
+
var STALLED2 = 3 * 60000;
|
|
3104
|
+
async function watchRuns(pick, timeout, repo, idle, out = process.stdout) {
|
|
3105
|
+
const started = Date.now();
|
|
3106
|
+
const latest = new Map;
|
|
3107
|
+
const seen = new Map;
|
|
3108
|
+
const line = (run) => `${run.workflow_id} run ${run.id} on ${run.prettyref}: ${badge(run.status, out)}${elapsed(run, seen.get(run.id) ?? Date.now())}`;
|
|
3109
|
+
const region = takesControlCodes(out) ? liveRegion(() => [...latest.values()].map(line), out) : undefined;
|
|
3110
|
+
const followed = new Set;
|
|
3111
|
+
const failed = new Set;
|
|
3112
|
+
let moving = started;
|
|
3113
|
+
async function poll() {
|
|
3114
|
+
const newest = await recentRuns(LIMIT, repo);
|
|
3115
|
+
const gone = await Promise.all([...followed].filter((id) => !newest.some((run) => run.id === id)).map(async (id) => runById(id, repo)));
|
|
3116
|
+
const runs = [...pick(newest), ...gone];
|
|
3117
|
+
for (const run of runs)
|
|
3118
|
+
followed.add(run.id);
|
|
3119
|
+
for (const run of runs) {
|
|
3120
|
+
if (!seen.has(run.id))
|
|
3121
|
+
seen.set(run.id, Date.now());
|
|
3122
|
+
if (region === undefined && latest.get(run.id)?.status !== run.status)
|
|
3123
|
+
out.write(`${line(run)}
|
|
3124
|
+
`);
|
|
3125
|
+
latest.set(run.id, run);
|
|
3126
|
+
}
|
|
3127
|
+
region?.redraw();
|
|
3128
|
+
if (runs.length === 0) {
|
|
3129
|
+
if (idle !== undefined && Date.now() - started > idle) {
|
|
3130
|
+
console.log("no run started, so nothing was waited for");
|
|
3131
|
+
return 0;
|
|
3132
|
+
}
|
|
3133
|
+
return;
|
|
3134
|
+
}
|
|
3135
|
+
for (const run of runs) {
|
|
3136
|
+
if (run.status === "failure" && !failed.has(run.id)) {
|
|
3137
|
+
console.error(`
|
|
3138
|
+
${await failureReport(run, repo)}
|
|
3139
|
+
|
|
3140
|
+
${run.html_url}`);
|
|
3141
|
+
failed.add(run.id);
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
if (runs.every((run) => FINISHED.has(run.status))) {
|
|
3145
|
+
const status = overall(runs);
|
|
3146
|
+
return status === "failure" || status === "cancelled" ? 1 : 0;
|
|
3147
|
+
}
|
|
3148
|
+
const stall = await stallReason(runs, repo);
|
|
3149
|
+
if (stall === undefined)
|
|
3150
|
+
moving = Date.now();
|
|
3151
|
+
else if (stall.certain || Date.now() - moving > STALLED2)
|
|
3152
|
+
fail(`queued runs are not moving: ${stall.reason}`);
|
|
3153
|
+
return;
|
|
3154
|
+
}
|
|
3155
|
+
async function settle() {
|
|
3156
|
+
for (;; ) {
|
|
3157
|
+
await Bun.sleep(timing.poll);
|
|
3158
|
+
if (Date.now() - started > timeout)
|
|
3159
|
+
fail(`the runs did not finish in ${formatDuration(timeout)}`);
|
|
3160
|
+
try {
|
|
3161
|
+
const code = await poll();
|
|
3162
|
+
if (code !== undefined)
|
|
3163
|
+
return code;
|
|
3164
|
+
} catch (error) {
|
|
3165
|
+
if (error instanceof Exit)
|
|
3166
|
+
throw error;
|
|
3167
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3168
|
+
if (isPermanentFailure(error))
|
|
3169
|
+
fail(message);
|
|
3170
|
+
console.warn(`ft watch: ${message}, polling again`);
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
try {
|
|
3175
|
+
return await settle();
|
|
3176
|
+
} finally {
|
|
3177
|
+
if (region !== undefined) {
|
|
3178
|
+
region.stop();
|
|
3179
|
+
for (const run of latest.values())
|
|
3180
|
+
out.write(`${line(run)}
|
|
3181
|
+
`);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
function elapsed(run, seen) {
|
|
3186
|
+
if (FINISHED.has(run.status))
|
|
3187
|
+
return run.duration > 0 ? ` in ${formatSeconds(runSeconds(run))}` : "";
|
|
3188
|
+
const seconds = Math.floor((Date.now() - (startedAt(run) ?? seen)) / 1000);
|
|
3189
|
+
return seconds > 0 ? ` for ${formatSeconds(seconds)}` : "";
|
|
3190
|
+
}
|
|
3191
|
+
async function watch(args) {
|
|
3192
|
+
const parsed = parse(args, usage4, options5);
|
|
3193
|
+
const { values } = parsed;
|
|
3194
|
+
const timeout = duration(values.timeout, "timeout", 15 * 60000, "m");
|
|
3195
|
+
if (values.after !== undefined) {
|
|
3196
|
+
const after = wholeNumber(values.after, "after", 0, 0);
|
|
3197
|
+
return watchRuns((runs) => runs.filter((run) => run.id > after), timeout, values.repo);
|
|
3198
|
+
}
|
|
3199
|
+
const active = new Set((await recentRuns(LIMIT, values.repo)).filter((run) => !FINISHED.has(run.status)).map((run) => run.id));
|
|
3200
|
+
if (active.size === 0) {
|
|
3201
|
+
console.log("no run in progress");
|
|
3202
|
+
return 0;
|
|
3203
|
+
}
|
|
3204
|
+
return watchRuns((runs) => runs.filter((run) => active.has(run.id)), timeout, values.repo);
|
|
3205
|
+
}
|
|
3206
|
+
|
|
3207
|
+
// src/commands/release.ts
|
|
3208
|
+
var usage5 = `ft release <patch|minor|major|x.y.z>
|
|
3209
|
+
ft release --tagged
|
|
3210
|
+
|
|
3211
|
+
Cuts a release from the default branch: first the commit it sits on is pushed and its runs waited for, so failing tests stop it before anything is bumped or tagged. Then \`bun pm version\` commits and tags the bump, one atomic push sends the branch and its tag, and it waits for the runs the push started and for the registry to serve the version.
|
|
3212
|
+
--tagged releases a version commit already tagged at HEAD instead, for repos bumping with their own script; the runs waited for first are then those of the commit below it.
|
|
3213
|
+
--package releases one workspace package of a monorepo on its own, tagged \`<folder>-v<version>\` (\`ft release patch -p ft\` tags packages/ft as ft-v0.3.0).
|
|
3214
|
+
A refused or interrupted push drops the bump commit and its tag, so a retry starts clean; with --tagged the commit and tag are yours and stay.
|
|
3215
|
+
Once released, an open milestone titled like the version (\`1.2.0\`, \`v1.2.0\` or the tag) has its closed issues listed and is closed; a failure there only warns.
|
|
3216
|
+
--dry-run checks the same and prints the plan: the version bump, the tag, the pushes and the runs and registry it would wait for, changing nothing.
|
|
3217
|
+
Exits 0 once released or planned, 1 when a run fails, origin refuses a push or the registry never serves the version, 2 on a timeout, a stalled queue, a refusal before anything ran (another branch, uncommitted changes, origin ahead) or a usage error.`;
|
|
3218
|
+
var options6 = {
|
|
3219
|
+
tagged: { type: "boolean", description: "push the version commit and tag already at HEAD instead of bumping" },
|
|
3220
|
+
package: { type: "string", short: "p", description: "workspace folder to release, a path or a name under packages/" },
|
|
3221
|
+
"no-registry": { type: "boolean", description: "do not wait for the registry to serve the new version" },
|
|
3222
|
+
"dry-run": { type: "boolean", description: "print what the release would do, changing nothing" },
|
|
3223
|
+
timeout: { type: "string", short: "t", description: "how long to wait for the runs (15m), a bare number in minutes" }
|
|
3224
|
+
};
|
|
3225
|
+
var LEVELS = new Set(["patch", "minor", "major", "prepatch", "preminor", "premajor", "prerelease"]);
|
|
3226
|
+
var VERSION = /^\d+\.\d+\.\d+(?:-[\w.]+)?$/;
|
|
3227
|
+
var PARTS = /^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/;
|
|
3228
|
+
var LAST_NUMBER = /\d+$/;
|
|
3229
|
+
var REGISTRY_TRIES = 12;
|
|
3230
|
+
var REGISTRY_POLL = 5000;
|
|
3231
|
+
var limits = { pushMs: 5 * 60000 };
|
|
3232
|
+
var REGISTRY_INFO_MS = 30000;
|
|
3233
|
+
var NO_RUN2 = 3 * 60000;
|
|
3234
|
+
var RUNS_LOOKED_AT = 20;
|
|
3235
|
+
function taggedVersion(tag, prefix) {
|
|
3236
|
+
const version = tag.slice(prefix.length);
|
|
3237
|
+
return tag.startsWith(prefix) && VERSION.test(version) ? version : undefined;
|
|
3238
|
+
}
|
|
3239
|
+
function nextVersion(current, level) {
|
|
3240
|
+
if (VERSION.test(level))
|
|
3241
|
+
return level;
|
|
3242
|
+
const [, major = "0", minor = "0", patch = "0", pre] = PARTS.exec(current) ?? [];
|
|
3243
|
+
const [x, y, z] = [Number(major), Number(minor), Number(patch)];
|
|
3244
|
+
switch (level) {
|
|
3245
|
+
case "major":
|
|
3246
|
+
return pre !== undefined && y === 0 && z === 0 ? `${x}.0.0` : `${x + 1}.0.0`;
|
|
3247
|
+
case "minor":
|
|
3248
|
+
return pre !== undefined && z === 0 ? `${x}.${y}.0` : `${x}.${y + 1}.0`;
|
|
3249
|
+
case "patch":
|
|
3250
|
+
return pre === undefined ? `${x}.${y}.${z + 1}` : `${x}.${y}.${z}`;
|
|
3251
|
+
case "premajor":
|
|
3252
|
+
return `${x + 1}.0.0-0`;
|
|
3253
|
+
case "preminor":
|
|
3254
|
+
return `${x}.${y + 1}.0-0`;
|
|
3255
|
+
case "prepatch":
|
|
3256
|
+
return `${x}.${y}.${z + 1}-0`;
|
|
3257
|
+
default: {
|
|
3258
|
+
if (pre === undefined)
|
|
3259
|
+
return `${x}.${y}.${z + 1}-0`;
|
|
3260
|
+
const numbered = LAST_NUMBER.exec(pre);
|
|
3261
|
+
return `${x}.${y}.${z}-${numbered === null ? `${pre}.0` : `${pre.slice(0, numbered.index)}${Number(numbered[0]) + 1}`}`;
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
async function packageDir(value) {
|
|
3266
|
+
for (const dir of [resolve(value), join2(await git(["rev-parse", "--show-toplevel"]), "packages", value)]) {
|
|
3267
|
+
if (await Bun.file(join2(dir, "package.json")).exists())
|
|
3268
|
+
return dir;
|
|
3269
|
+
}
|
|
3270
|
+
fail(`no package.json in ${value} nor in packages/${value}`);
|
|
3271
|
+
}
|
|
3272
|
+
async function commitPackageBump(dir, prefix) {
|
|
3273
|
+
const { version } = await Bun.file(join2(dir, "package.json")).json();
|
|
3274
|
+
const root = await git(["rev-parse", "--show-toplevel"]);
|
|
3275
|
+
const tag = `${prefix}${version}`;
|
|
3276
|
+
const lock = await $`bun install --lockfile-only`.cwd(root).quiet().nothrow();
|
|
3277
|
+
if (lock.exitCode !== 0)
|
|
3278
|
+
fail(`bun install --lockfile-only after the bump: ${lock.stderr.toString().trim()}`);
|
|
3279
|
+
await git(["add", join2(dir, "package.json"), join2(root, "bun.lock")]);
|
|
3280
|
+
await git(["commit", "-q", "-m", tag]);
|
|
3281
|
+
await git(["tag", "-a", tag, "-m", tag]);
|
|
3282
|
+
}
|
|
3283
|
+
async function waitForRegistry(name, version) {
|
|
3284
|
+
for (let attempt = 0;attempt < REGISTRY_TRIES; attempt++) {
|
|
3285
|
+
let served;
|
|
3286
|
+
try {
|
|
3287
|
+
served = (await runTool("bun info", ["bun", "info", name, "version", "--no-cache"], { timeoutMs: REGISTRY_INFO_MS })).stdout.trim().split(`
|
|
3288
|
+
`).at(-1);
|
|
3289
|
+
} catch (error) {
|
|
3290
|
+
if (isPermanentFailure(error))
|
|
3291
|
+
throw error;
|
|
3292
|
+
}
|
|
3293
|
+
if (served === version)
|
|
3294
|
+
return true;
|
|
3295
|
+
await Bun.sleep(REGISTRY_POLL);
|
|
3296
|
+
}
|
|
3297
|
+
return false;
|
|
3298
|
+
}
|
|
3299
|
+
async function alreadyPassed(sha) {
|
|
3300
|
+
try {
|
|
3301
|
+
const own = newestPerWorkflow((await recentRuns(RUNS_LOOKED_AT)).filter((run) => run.commit_sha === sha));
|
|
3302
|
+
return own.length > 0 && own.every((run) => FINISHED.has(run.status)) && ["success", "skipped"].includes(overall(own));
|
|
3303
|
+
} catch {
|
|
3304
|
+
return false;
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
async function testsPass(sha, branch, timeout) {
|
|
3308
|
+
if (!await gitOk(["merge-base", "--is-ancestor", sha, `origin/${branch}`])) {
|
|
3309
|
+
const held = holdSignals();
|
|
3310
|
+
let push;
|
|
3311
|
+
try {
|
|
3312
|
+
push = await runTool("git push", ["git", "push", "origin", `${sha}:refs/heads/${branch}`], { timeoutMs: limits.pushMs, onStart: (child) => held.forward(child) });
|
|
3313
|
+
} finally {
|
|
3314
|
+
held.release();
|
|
3315
|
+
}
|
|
3316
|
+
if (held.signal !== undefined)
|
|
3317
|
+
fail(`interrupted by ${held.signal} while pushing ${sha.slice(0, 7)}, so nothing was bumped`, exitCodeOf(null, held.signal));
|
|
3318
|
+
if (push.code !== 0)
|
|
3319
|
+
fail(`origin refused the push of ${sha.slice(0, 7)}, so nothing was bumped:
|
|
3320
|
+
${push.stderr.trim()}`, 1);
|
|
3321
|
+
console.log(`pushed ${branch} at ${sha.slice(0, 7)}, waiting for its runs before the bump`);
|
|
3322
|
+
} else if (await alreadyPassed(sha)) {
|
|
3323
|
+
return true;
|
|
3324
|
+
} else {
|
|
3325
|
+
console.log(`${branch} at ${sha.slice(0, 7)} is on origin, waiting for its runs before the bump`);
|
|
3326
|
+
}
|
|
3327
|
+
return await watchRuns((runs) => newestPerWorkflow(runs.filter((run) => run.commit_sha === sha)), timeout, undefined, NO_RUN2) === 0;
|
|
3328
|
+
}
|
|
3329
|
+
async function printPlan({ level, dir, prefix, branch, base, timeout, registry }) {
|
|
3330
|
+
const file = Bun.file(join2(dir ?? ".", "package.json"));
|
|
3331
|
+
const pkg = await file.exists() ? await file.json() : undefined;
|
|
3332
|
+
const name = pkg?.name ?? basename2(dir ?? process14.cwd());
|
|
3333
|
+
const where = dir === undefined ? "" : ` in ${relative(process14.cwd(), dir) || "."}`;
|
|
3334
|
+
const sha = base.slice(0, 7);
|
|
3335
|
+
let version;
|
|
3336
|
+
let bump;
|
|
3337
|
+
if (level === undefined) {
|
|
3338
|
+
const tag = (await tagsAt("HEAD")).find((each) => taggedVersion(each, prefix) !== undefined);
|
|
3339
|
+
if (tag === undefined)
|
|
3340
|
+
fail(`HEAD carries no ${prefix}* tag`);
|
|
3341
|
+
version = tag.slice(prefix.length);
|
|
3342
|
+
bump = `take the version commit at HEAD, tagged ${tag}`;
|
|
3343
|
+
console.log(`would release ${name} ${version}, tagged ${tag}`);
|
|
3344
|
+
} else {
|
|
3345
|
+
if (pkg?.version === undefined)
|
|
3346
|
+
fail(`no version in ${join2(dir ?? ".", "package.json")}`);
|
|
3347
|
+
version = nextVersion(pkg.version, level);
|
|
3348
|
+
bump = dir === undefined ? `bun pm version ${level}, which commits and tags ${prefix}${version}` : `bun pm version ${level} --no-git-tag-version${where}, then commit it with bun.lock refreshed and tag ${prefix}${version}`;
|
|
3349
|
+
console.log(`would release ${name} ${pkg.version} -> ${version}, tagged ${prefix}${version}`);
|
|
3350
|
+
}
|
|
3351
|
+
const pushed = await gitOk(["merge-base", "--is-ancestor", base, `origin/${branch}`]);
|
|
3352
|
+
const registryStep = registry && pkg?.name !== undefined && pkg.private !== true ? `wait for the registry to serve ${pkg.name}@${version}` : `skip the registry: ${registry ? "the package is private or unnamed" : "--no-registry"}`;
|
|
3353
|
+
const steps = [
|
|
3354
|
+
pushed ? `wait for the runs on ${sha}, already on origin/${branch}` : `push ${branch} at ${sha}, which origin lacks, then wait for its runs`,
|
|
3355
|
+
bump,
|
|
3356
|
+
`push ${branch} and ${prefix}${version} in one atomic push, then wait for the runs it starts (${formatDuration(timeout)} at most)`,
|
|
3357
|
+
registryStep
|
|
3358
|
+
];
|
|
3359
|
+
console.log(steps.map((step, i) => ` ${i + 1}. ${step}`).join(`
|
|
3360
|
+
`));
|
|
3361
|
+
console.log("dry run: nothing was pushed, committed or tagged");
|
|
3362
|
+
return 0;
|
|
3363
|
+
}
|
|
3364
|
+
async function rollBack(preBump, tagsBefore) {
|
|
3365
|
+
try {
|
|
3366
|
+
for (const name of await tagsAt("HEAD")) {
|
|
3367
|
+
if (!tagsBefore.has(name))
|
|
3368
|
+
await git(["tag", "-d", name]);
|
|
3369
|
+
}
|
|
3370
|
+
await git(["reset", "--keep", preBump]);
|
|
3371
|
+
} catch (error) {
|
|
3372
|
+
warn(`could not undo the bump, back to ${preBump.slice(0, 7)} by hand`, error instanceof Error ? error.message : String(error));
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3375
|
+
async function release(args) {
|
|
3376
|
+
const parsed = parse(args, usage5, options6);
|
|
3377
|
+
const { values, positionals } = parsed;
|
|
3378
|
+
const level = positionals[0];
|
|
3379
|
+
const tagged = values.tagged === true;
|
|
3380
|
+
if (tagged === (level !== undefined))
|
|
3381
|
+
fail(`give a level or --tagged
|
|
3382
|
+
|
|
3383
|
+
${usage5}`);
|
|
3384
|
+
if (level !== undefined && !LEVELS.has(level) && !VERSION.test(level))
|
|
3385
|
+
fail(`${level} is no level nor x.y.z version`);
|
|
3386
|
+
const timeout = duration(values.timeout, "timeout", 15 * 60000, "m");
|
|
3387
|
+
const dir = values.package === undefined ? undefined : await packageDir(values.package);
|
|
3388
|
+
const prefix = dir === undefined ? "v" : `${basename2(dir)}-v`;
|
|
3389
|
+
const branch = await defaultBranch();
|
|
3390
|
+
const current = await git(["branch", "--show-current"]);
|
|
3391
|
+
if (current !== branch)
|
|
3392
|
+
fail(`a release is cut from ${branch}, not ${current || "a detached HEAD"}`, 2, runHint(`git switch ${branch}`));
|
|
3393
|
+
if (await git(["status", "--porcelain"]) !== "")
|
|
3394
|
+
fail("the tree has uncommitted changes", 2, runHint("gst", "see them, then commit them with gc"));
|
|
3395
|
+
await fetchBranch(branch);
|
|
3396
|
+
if ((await $`git merge-base --is-ancestor ${`origin/${branch}`} HEAD`.quiet().nothrow()).exitCode !== 0)
|
|
3397
|
+
fail(`origin/${branch} has commits HEAD lacks`, 2, runHint(`git pull --rebase origin ${branch}`));
|
|
3398
|
+
const base = await git(["rev-parse", tagged ? "HEAD~1" : "HEAD"]);
|
|
3399
|
+
if (values["dry-run"] === true)
|
|
3400
|
+
return printPlan({ level, dir, prefix, branch, base, timeout, registry: values["no-registry"] !== true });
|
|
3401
|
+
if (!await testsPass(base, branch, timeout))
|
|
3402
|
+
fail(`the runs on ${base.slice(0, 7)} failed, so nothing was bumped or tagged`, 1, runHint(`ft runs --sha ${base.slice(0, 7)}`, "list the runs, then ft logs <id> reads the failure"));
|
|
3403
|
+
const preBump = await git(["rev-parse", "HEAD"]);
|
|
3404
|
+
const tagsBefore = new Set(await tagsAt("HEAD"));
|
|
3405
|
+
const before = (await recentRuns(1))[0]?.id ?? 0;
|
|
3406
|
+
const held = holdSignals();
|
|
3407
|
+
const signalOf = () => held.signal;
|
|
3408
|
+
let tag = "";
|
|
3409
|
+
let head = "";
|
|
3410
|
+
let pushed = false;
|
|
3411
|
+
let isPushUnknown = false;
|
|
3412
|
+
try {
|
|
3413
|
+
if (level !== undefined) {
|
|
3414
|
+
const bump = dir === undefined ? await $`bun pm version ${level}`.quiet().nothrow() : await $`bun pm version ${level} --no-git-tag-version`.cwd(dir).quiet().nothrow();
|
|
3415
|
+
if (bump.exitCode !== 0)
|
|
3416
|
+
fail(`bun pm version ${level}: ${bump.stderr.toString().trim() || bump.stdout.toString().trim()}`);
|
|
3417
|
+
if (dir !== undefined)
|
|
3418
|
+
await commitPackageBump(dir, prefix);
|
|
3419
|
+
}
|
|
3420
|
+
const found = (await tagsAt("HEAD")).find((name) => taggedVersion(name, prefix) !== undefined);
|
|
3421
|
+
if (found === undefined)
|
|
3422
|
+
fail(tagged ? `HEAD carries no ${prefix}* tag` : `the bump made no ${prefix}* tag`);
|
|
3423
|
+
tag = found;
|
|
3424
|
+
head = await git(["rev-parse", "HEAD"]);
|
|
3425
|
+
if (held.signal !== undefined)
|
|
3426
|
+
fail(`interrupted by ${held.signal} before the push`, exitCodeOf(null, held.signal));
|
|
3427
|
+
let push;
|
|
3428
|
+
try {
|
|
3429
|
+
push = await runTool("git push", ["git", "push", "--atomic", "origin", `HEAD:refs/heads/${branch}`, tag], { timeoutMs: limits.pushMs, onStart: (child) => held.forward(child) });
|
|
3430
|
+
} catch (error) {
|
|
3431
|
+
isPushUnknown = true;
|
|
3432
|
+
fail(`${error instanceof Error ? error.message : String(error)}, so ${tag} and its commit are kept: the push may have landed`, 2, `git ls-remote origin refs/tags/${tag} tells; if it is there, ft release --tagged waits for its runs`);
|
|
3433
|
+
}
|
|
3434
|
+
if (push.code !== 0) {
|
|
3435
|
+
const signal = signalOf();
|
|
3436
|
+
fail(`origin refused the push${signal === undefined ? "" : `, or ${signal} interrupted it`}, so ${level === undefined ? `${tag} and its commit are kept for a retry` : `${tag} and its commit were dropped for a clean retry`}:
|
|
3437
|
+
${push.stderr.trim()}`, signal === undefined ? 1 : exitCodeOf(null, signal));
|
|
3438
|
+
}
|
|
3439
|
+
pushed = true;
|
|
3440
|
+
} finally {
|
|
3441
|
+
held.release();
|
|
3442
|
+
if (!pushed && !isPushUnknown && level !== undefined)
|
|
3443
|
+
await rollBack(preBump, tagsBefore);
|
|
3444
|
+
}
|
|
3445
|
+
const late = signalOf();
|
|
3446
|
+
if (late !== undefined)
|
|
3447
|
+
fail(`interrupted by ${late} after ${tag} was pushed: its runs are not waited for`, exitCodeOf(null, late));
|
|
3448
|
+
console.log(`pushed ${branch} and ${tag}, waiting for their runs`);
|
|
3449
|
+
const code = await watchRuns((runs) => runs.filter((run) => run.id > before && run.commit_sha === head), timeout, undefined, NO_RUN2);
|
|
3450
|
+
if (code !== 0)
|
|
3451
|
+
return code;
|
|
3452
|
+
const file = Bun.file(join2(dir ?? ".", "package.json"));
|
|
3453
|
+
const pkg = await file.exists() ? await file.json() : undefined;
|
|
3454
|
+
const version = tag.slice(prefix.length);
|
|
3455
|
+
if (values["no-registry"] === true || pkg?.name === undefined || pkg.private === true) {
|
|
3456
|
+
console.log(`released ${tag}`);
|
|
3457
|
+
await settleMilestone(version, tag);
|
|
3458
|
+
return 0;
|
|
3459
|
+
}
|
|
3460
|
+
if (!await waitForRegistry(pkg.name, version))
|
|
3461
|
+
fail(`the runs passed but the registry does not serve ${pkg.name}@${version}: read the publish job with \`ft logs\``, 1);
|
|
3462
|
+
console.log(`released ${pkg.name}@${version}`);
|
|
3463
|
+
await settleMilestone(version, tag);
|
|
3464
|
+
return 0;
|
|
3465
|
+
}
|
|
3466
|
+
async function settleMilestone(version, tag) {
|
|
3467
|
+
try {
|
|
3468
|
+
const names = new Set([version, `v${version}`, tag]);
|
|
3469
|
+
const found = (await listMilestones("open")).find((each) => names.has(each.title));
|
|
3470
|
+
if (found === undefined)
|
|
3471
|
+
return;
|
|
3472
|
+
const [done, left] = await Promise.all([closedIssues(found.id), openIssues(undefined, undefined, found.id)]);
|
|
3473
|
+
console.log(`milestone ${found.title}: ${done.length} closed issue${done.length === 1 ? "" : "s"}${done.length === 0 ? "" : `
|
|
3474
|
+
${done.map((issue) => ` #${issue.number} ${issue.title}`).join(`
|
|
3475
|
+
`)}`}`);
|
|
3476
|
+
if (left.length > 0)
|
|
3477
|
+
warn(`${left.length} issue${left.length === 1 ? " is" : "s are"} still open in it`, left.map((issue) => `#${issue.number}`).join(" "));
|
|
3478
|
+
await closeMilestone(found.id);
|
|
3479
|
+
console.log(`closed milestone ${found.title}`);
|
|
3480
|
+
} catch (error) {
|
|
3481
|
+
warn(`released, but the milestone ${version} could not be settled`, error instanceof Error ? error.message : String(error));
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3485
|
+
// src/commands/remote.ts
|
|
3486
|
+
import { lookup } from "dns/promises";
|
|
3487
|
+
import { homedir as homedir3 } from "os";
|
|
3488
|
+
var {$: $2 } = globalThis.Bun;
|
|
3489
|
+
|
|
3490
|
+
// src/config.ts
|
|
3491
|
+
import { homedir as homedir2 } from "os";
|
|
3492
|
+
import { join as join3 } from "path";
|
|
3493
|
+
function settingsPath(home = homedir2()) {
|
|
3494
|
+
return join3(home, ".config", "ft", "config.json");
|
|
3495
|
+
}
|
|
3496
|
+
async function loadSettings(home = homedir2()) {
|
|
3497
|
+
const path = settingsPath(home);
|
|
3498
|
+
const file = Bun.file(path);
|
|
3499
|
+
if (!await file.exists())
|
|
3500
|
+
return {};
|
|
3501
|
+
let raw;
|
|
3502
|
+
try {
|
|
3503
|
+
raw = await file.json();
|
|
3504
|
+
} catch (error) {
|
|
3505
|
+
warn(`${path} is not valid JSON, so its settings are ignored`, error instanceof Error ? error.message : String(error));
|
|
3506
|
+
return {};
|
|
3507
|
+
}
|
|
3508
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
3509
|
+
warn(`${path} is not a JSON object, so its settings are ignored`);
|
|
3510
|
+
return {};
|
|
3511
|
+
}
|
|
3512
|
+
const host = "remoteHost" in raw ? raw.remoteHost : undefined;
|
|
3513
|
+
if (host !== undefined && (typeof host !== "string" || host === ""))
|
|
3514
|
+
warn(`remoteHost in ${path} must be a non-empty string, so it is ignored`);
|
|
3515
|
+
return typeof host === "string" && host !== "" ? { remoteHost: host } : {};
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3518
|
+
// src/remote.ts
|
|
3519
|
+
var SCP_LIKE = /^(?:([^@/]+)@)?([^:/]+):(?!\/)(.+?)(?:\.git)?\/?$/;
|
|
3520
|
+
var SSH_URL = /^ssh:\/\/(?:([^@/]+)@)?([^:/]+)(?::(\d+))?\/(.+?)(?:\.git)?\/?$/;
|
|
3521
|
+
var USERINFO = /^([a-z][a-z\d+.-]*:\/\/)[^@/]*@/i;
|
|
3522
|
+
var DEFAULT_PORT = "22";
|
|
3523
|
+
function parseSshRemote(url) {
|
|
3524
|
+
const ssh = SSH_URL.exec(url);
|
|
3525
|
+
const scp = ssh === null && !url.includes("://") ? SCP_LIKE.exec(url) : null;
|
|
3526
|
+
const match = ssh ?? scp;
|
|
3527
|
+
if (match === null || match[2]?.startsWith("-") === true)
|
|
3528
|
+
return;
|
|
3529
|
+
const login = match[1] ?? "git";
|
|
3530
|
+
const user = login.includes(":") ? login.slice(0, login.indexOf(":")) : login;
|
|
3531
|
+
if (ssh === null)
|
|
3532
|
+
return { user, host: match[2] ?? "", path: match[3] ?? "" };
|
|
3533
|
+
return { user, host: match[2] ?? "", path: match[4] ?? "", ...ssh[3] === undefined ? {} : { port: ssh[3] } };
|
|
3534
|
+
}
|
|
3535
|
+
function redactUrl(url) {
|
|
3536
|
+
return url.replace(USERINFO, "$1");
|
|
3537
|
+
}
|
|
3538
|
+
function canonicalRemote(url, host, reaches) {
|
|
3539
|
+
const remote = parseSshRemote(url);
|
|
3540
|
+
if (remote === undefined || remote.host === host || !reaches(remote.host))
|
|
3541
|
+
return;
|
|
3542
|
+
if (remote.port !== undefined && remote.port !== DEFAULT_PORT)
|
|
3543
|
+
return `ssh://${remote.user}@${host}:${remote.port}/${remote.path}.git`;
|
|
3544
|
+
return `${remote.user}@${host}:${remote.path}.git`;
|
|
3545
|
+
}
|
|
3546
|
+
async function reachesHost(hostname, host, hostAddresses, addressesOf) {
|
|
3547
|
+
if (hostname === undefined)
|
|
3548
|
+
return false;
|
|
3549
|
+
return hostname === host || (await addressesOf(hostname)).some((address) => hostAddresses.has(address));
|
|
3550
|
+
}
|
|
3551
|
+
|
|
3552
|
+
// src/commands/remote.ts
|
|
3553
|
+
var usage6 = `ft remote [--fix]
|
|
3554
|
+
|
|
3555
|
+
Checks that origin's URLs name the Forgejo host itself: tea only finds the repository when origin's host is the login's ssh_host, never through an ssh alias such as \`forgejo\` or \`gitea\`.
|
|
3556
|
+
--fix switches every alias URL to \`git@<host>:<owner>/<repo>.git\` and proves it with \`git ls-remote\`.
|
|
3557
|
+
The host comes from --host, else \`remoteHost\` in ~/.config/ft/config.json; with neither, it checks nothing.
|
|
3558
|
+
|
|
3559
|
+
Exits 0 when origin names the Forgejo host (or was switched) or no host is set, 1 when it does not or a switch is still to run, 2 on a usage error.`;
|
|
3560
|
+
var options7 = {
|
|
3561
|
+
host: { type: "string", description: "the Forgejo ssh host, instead of remoteHost in ~/.config/ft/config.json" },
|
|
3562
|
+
fix: { type: "boolean", description: "rewrite the alias URLs" }
|
|
3563
|
+
};
|
|
3564
|
+
var HOSTNAME = /^hostname (.+)$/m;
|
|
3565
|
+
async function sshHostname(alias) {
|
|
3566
|
+
return HOSTNAME.exec(await $2`ssh -G -- ${alias}`.quiet().nothrow().text())?.[1];
|
|
3567
|
+
}
|
|
3568
|
+
async function addresses(name) {
|
|
3569
|
+
try {
|
|
3570
|
+
return (await lookup(name, { all: true })).map((entry) => entry.address);
|
|
3571
|
+
} catch {
|
|
3572
|
+
return [];
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
async function restoreOrigin(fetchUrl, pushUrls, changes) {
|
|
3576
|
+
if (changes.some(([from]) => from === fetchUrl))
|
|
3577
|
+
await git(["remote", "set-url", "origin", fetchUrl]);
|
|
3578
|
+
for (const [from, to] of changes) {
|
|
3579
|
+
if (pushUrls.includes(from))
|
|
3580
|
+
await git(["remote", "set-url", "--push", "origin", from, to]);
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
function originHost(url) {
|
|
3584
|
+
return parseSshRemote(url)?.host ?? (URL.canParse(url) ? new URL(url).hostname : undefined);
|
|
3585
|
+
}
|
|
3586
|
+
async function remote(args, home = homedir3()) {
|
|
3587
|
+
const { values } = parse(args, usage6, options7);
|
|
3588
|
+
const host = values.host ?? (await loadSettings(home)).remoteHost;
|
|
3589
|
+
if (host === undefined) {
|
|
3590
|
+
note(`no Forgejo host to check origin against: pass --host, or set "remoteHost" in ${settingsPath(home)}`);
|
|
3591
|
+
return 0;
|
|
3592
|
+
}
|
|
3593
|
+
const fetchUrl = await git(["remote", "get-url", "origin"]);
|
|
3594
|
+
const pushUrls = (await $2`git config --get-all remote.origin.pushurl`.quiet().nothrow().text()).split(`
|
|
3595
|
+
`).filter(Boolean);
|
|
3596
|
+
const hostAddresses = new Set(await addresses(host));
|
|
3597
|
+
const hostnames = new Map;
|
|
3598
|
+
const reaching = new Set;
|
|
3599
|
+
for (const url of [fetchUrl, ...pushUrls]) {
|
|
3600
|
+
const alias = parseSshRemote(url)?.host;
|
|
3601
|
+
if (alias === undefined || hostnames.has(alias))
|
|
3602
|
+
continue;
|
|
3603
|
+
const hostname = await sshHostname(alias);
|
|
3604
|
+
hostnames.set(alias, hostname);
|
|
3605
|
+
if (await reachesHost(hostname, host, hostAddresses, addresses))
|
|
3606
|
+
reaching.add(alias);
|
|
3607
|
+
}
|
|
3608
|
+
const changes = [fetchUrl, ...pushUrls].map((url) => [url, canonicalRemote(url, host, (alias) => reaching.has(alias))]).filter((change) => change[1] !== undefined);
|
|
3609
|
+
if (changes.length === 0) {
|
|
3610
|
+
const named = originHost(fetchUrl);
|
|
3611
|
+
if (named === host) {
|
|
3612
|
+
console.log(`origin already names ${host}: ${redactUrl(fetchUrl)}`);
|
|
3613
|
+
return 0;
|
|
3614
|
+
}
|
|
3615
|
+
const hostname = named === undefined ? undefined : hostnames.get(named);
|
|
3616
|
+
console.log(`origin ${redactUrl(fetchUrl)} does not reach ${host}${hostname === undefined || hostname === named ? "" : `: ssh connects ${named} to ${hostname}`}, pass --host if Forgejo lives elsewhere`);
|
|
3617
|
+
return 1;
|
|
3618
|
+
}
|
|
3619
|
+
for (const [from, to] of changes)
|
|
3620
|
+
console.log(`${redactUrl(from)} -> ${redactUrl(to)}`);
|
|
3621
|
+
if (values.fix !== true) {
|
|
3622
|
+
console.log("run `ft remote --fix` to switch them");
|
|
3623
|
+
return 1;
|
|
3624
|
+
}
|
|
3625
|
+
const fetchChange = changes.find(([from]) => from === fetchUrl);
|
|
3626
|
+
if (fetchChange !== undefined)
|
|
3627
|
+
await git(["remote", "set-url", "origin", fetchChange[1]]);
|
|
3628
|
+
for (const [from, to] of changes) {
|
|
3629
|
+
if (pushUrls.includes(from))
|
|
3630
|
+
await git(["remote", "set-url", "--push", "origin", to, from]);
|
|
3631
|
+
}
|
|
3632
|
+
try {
|
|
3633
|
+
await git(["ls-remote", "origin", "HEAD"]);
|
|
3634
|
+
} catch (error) {
|
|
3635
|
+
await restoreOrigin(fetchUrl, pushUrls, changes);
|
|
3636
|
+
return fail(`the switched origin does not answer, so the old URLs were put back: ${redactUrl(error instanceof Error ? error.message : String(error))}`, 1);
|
|
3637
|
+
}
|
|
3638
|
+
console.log("origin switched, and git ls-remote reaches it");
|
|
3639
|
+
return 0;
|
|
3640
|
+
}
|
|
3641
|
+
|
|
3642
|
+
// src/commands/runs.ts
|
|
3643
|
+
var usage7 = `ft runs [--sha <ref>]
|
|
3644
|
+
|
|
3645
|
+
Lists recent runs with what tea's own listing leaves empty: workflow, ref, duration and age, ten by default with the count of the rest (--full for all of them; --json is never cut unless --limit is given).
|
|
3646
|
+
|
|
3647
|
+
Exits 0 when it listed them, 1 when Forgejo or git cannot be read, 2 on a usage error.`;
|
|
3648
|
+
var DEFAULT_LIMIT = 10;
|
|
3649
|
+
var options8 = {
|
|
3650
|
+
limit: { ...limitOptions(DEFAULT_LIMIT).limit, short: "n" },
|
|
3651
|
+
full: limitOptions(DEFAULT_LIMIT).full,
|
|
3652
|
+
sha: { type: "string", short: "s", description: "only the runs of this commit" },
|
|
3653
|
+
workflow: { type: "string", short: "w", description: "only this workflow file, e.g. test.yml" },
|
|
3654
|
+
json: jsonOption(),
|
|
3655
|
+
...repoOption
|
|
3656
|
+
};
|
|
3657
|
+
var TITLE_WIDTH4 = 70;
|
|
3658
|
+
async function onCommit(sha, repo) {
|
|
3659
|
+
const found = await runsOn(await resolveCommit(sha), repo);
|
|
3660
|
+
return { runs: found, total: found.length };
|
|
3661
|
+
}
|
|
3662
|
+
async function runs(args) {
|
|
3663
|
+
const parsed = parse(args, usage7, options8);
|
|
3664
|
+
const { values } = parsed;
|
|
3665
|
+
const limit = limitOf(values, DEFAULT_LIMIT);
|
|
3666
|
+
const { runs: found, total } = values.sha === undefined ? await runsListing(limit, values.repo, values.workflow) : await onCommit(values.sha, values.repo);
|
|
3667
|
+
const matching = found.filter((run) => values.workflow === undefined || run.workflow_id === values.workflow);
|
|
3668
|
+
const list = matching.slice(0, limit);
|
|
3669
|
+
const more = values.sha === undefined ? total - list.length : matching.length - list.length;
|
|
3670
|
+
if (values.json === true) {
|
|
3671
|
+
printJson(list.map((run) => ({ id: run.id, number: run.index_in_repo, status: run.status, workflow: run.workflow_id, ref: run.prettyref, event: run.event, sha: run.commit_sha, seconds: runSeconds(run), started: run.started, title: run.title, url: run.html_url })));
|
|
3672
|
+
return 0;
|
|
3673
|
+
}
|
|
3674
|
+
if (list.length === 0) {
|
|
3675
|
+
console.log("no run");
|
|
3676
|
+
return 0;
|
|
3677
|
+
}
|
|
3678
|
+
console.log(table([
|
|
3679
|
+
["ID", "STATUS", "WORKFLOW", "REF", "EVENT", "TOOK", "STARTED", "TITLE"],
|
|
3680
|
+
...list.map((run) => [String(run.id), badge(run.status, process.stdout), run.workflow_id, run.prettyref, run.event, run.duration > 0 ? formatSeconds(runSeconds(run)) : "-", startedAge(run), truncate(upTo(run.title, `
|
|
3681
|
+
`), TITLE_WIDTH4)])
|
|
3682
|
+
], { header: true }));
|
|
3683
|
+
if (more > 0)
|
|
3684
|
+
console.log(moreFooter(more));
|
|
3685
|
+
return 0;
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3688
|
+
// src/cli.ts
|
|
3689
|
+
process15.exitCode = await runCli({
|
|
3690
|
+
name: "ft",
|
|
3691
|
+
version,
|
|
3692
|
+
about: "Forgejo tools over tea, run from a repository whose origin is on Forgejo",
|
|
3693
|
+
replaces: "tea api calls piped through jq, and sleep loops waiting on CI",
|
|
3694
|
+
examples: [["ft ci", "wait for the runs of origin's tip, failures printed"], ["ft issue 12 -c", "an issue with its boxes numbered and its comments"]],
|
|
3695
|
+
commands: {
|
|
3696
|
+
runs: { run: runs, summary: "recent runs with workflow, ref, duration and age" },
|
|
3697
|
+
ci: { run: ci2, summary: "wait for the runs covering a commit, printing what failed" },
|
|
3698
|
+
watch: { run: watch, summary: "wait for runs newer than an id, or those in progress" },
|
|
3699
|
+
logs: { run: logs2, summary: "what the failed jobs of a run say went wrong" },
|
|
3700
|
+
release: { run: release, summary: "bump, push branch and tag atomically, wait for runs and registry" },
|
|
3701
|
+
board: { run: board, summary: "open issues: available, taken by a live session, or claimed by one gone" },
|
|
3702
|
+
digest: { run: digest, summary: "repo state for a cold start: held and abandoned claims, red CI, unpushed commits, dirty files, stale TODOs" },
|
|
3703
|
+
take: { run: take, summary: "claim an issue for this Claude Code session" },
|
|
3704
|
+
drop: { run: drop, summary: "give back an issue this session took" },
|
|
3705
|
+
issue: { run: issue, summary: "an issue's claim, description and numbered boxes, -c comments" },
|
|
3706
|
+
new: { run: newIssue, summary: "create an issue from -t and a description file or stdin" },
|
|
3707
|
+
edit: { run: edit, summary: "replace an issue's title or description, from a file or stdin" },
|
|
3708
|
+
tick: { run: tick, summary: "tick checklist boxes of an issue, -m to comment too" },
|
|
3709
|
+
comment: { run: commentOn, summary: "comment on an issue, from stdin when no text is given" },
|
|
3710
|
+
fixed: { run: fixed, summary: 'comment "Fixed in <sha>" and close an issue' },
|
|
3711
|
+
close: { run: closeIssues, summary: "close issues without a fix, -m posting the reason" },
|
|
3712
|
+
reopen: { run: reopenIssues, summary: "reopen closed issues, -m posting the reason" },
|
|
3713
|
+
label: { run: label, summary: "add +name and remove -name labels of an issue" },
|
|
3714
|
+
plan,
|
|
3715
|
+
milestones: { run: milestones, summary: "milestones with their open and closed issues, progress and due date" },
|
|
3716
|
+
milestone: { run: milestone, summary: "show a milestone's issues like the board, `new` creates one, `close` closes it" },
|
|
3717
|
+
remote: { run: remote, summary: "check or fix an origin using an ssh alias tea cannot match" }
|
|
3718
|
+
},
|
|
3719
|
+
aliases: { show: "issue", view: "issue" }
|
|
3720
|
+
});
|