@cnzgray/dsh-mattpocock-workflow 0.6.0 → 0.7.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/README.md +150 -169
- package/README.zh-CN.md +182 -0
- package/lib/client.js +689 -166
- package/lib/index.js +192 -76
- package/package.json +1 -1
- package/skills/README.md +17 -15
- package/skills/README.zh-CN.md +23 -0
- package/skills/engineering/setup-matt-pocock-skills/issue-tracker-gitea.zh.md +0 -73
package/lib/index.js
CHANGED
|
@@ -31,9 +31,13 @@ import { join } from "node:path";
|
|
|
31
31
|
function isRecord(value) {
|
|
32
32
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
33
|
}
|
|
34
|
+
function readNonNegativeInteger(value) {
|
|
35
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) return void 0;
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
34
38
|
|
|
35
39
|
// src/core/snapshot-store.ts
|
|
36
|
-
var SNAPSHOT_STORE_VERSION =
|
|
40
|
+
var SNAPSHOT_STORE_VERSION = 7;
|
|
37
41
|
var BACKENDS = ["github", "gitlab", "gitea", "markdown"];
|
|
38
42
|
function serializeSnapshotStoreEntry(entry) {
|
|
39
43
|
return JSON.stringify({
|
|
@@ -141,10 +145,18 @@ function readTicket(value) {
|
|
|
141
145
|
if (number !== null && (typeof number !== "number" || !Number.isInteger(number))) return void 0;
|
|
142
146
|
const labels = readStringArray(value.labels);
|
|
143
147
|
if (labels === void 0) return void 0;
|
|
144
|
-
const assignees =
|
|
148
|
+
const assignees = readAuthorArray(value.assignees);
|
|
145
149
|
if (assignees === void 0) return void 0;
|
|
146
150
|
const author = readAuthor(value.author);
|
|
147
151
|
if (author === void 0) return void 0;
|
|
152
|
+
const excerpt = value.excerpt;
|
|
153
|
+
if (excerpt !== void 0 && (typeof excerpt !== "string" || excerpt.length === 0)) {
|
|
154
|
+
return void 0;
|
|
155
|
+
}
|
|
156
|
+
const commentCount = value.commentCount;
|
|
157
|
+
if (commentCount !== void 0 && (typeof commentCount !== "number" || !Number.isInteger(commentCount) || commentCount < 0)) {
|
|
158
|
+
return void 0;
|
|
159
|
+
}
|
|
148
160
|
const closedAt = value.closedAt;
|
|
149
161
|
if (closedAt !== void 0 && typeof closedAt !== "string") return void 0;
|
|
150
162
|
const url = value.url;
|
|
@@ -172,7 +184,9 @@ function readTicket(value) {
|
|
|
172
184
|
...closedAt === void 0 ? {} : { closedAt },
|
|
173
185
|
...url === void 0 ? {} : { url },
|
|
174
186
|
...blockedBy === void 0 ? {} : { blockedBy },
|
|
175
|
-
...typeof parent === "string" ? { parent } : {}
|
|
187
|
+
...typeof parent === "string" ? { parent } : {},
|
|
188
|
+
...excerpt === void 0 ? {} : { excerpt },
|
|
189
|
+
...commentCount === void 0 ? {} : { commentCount }
|
|
176
190
|
};
|
|
177
191
|
}
|
|
178
192
|
function readHierarchy(value) {
|
|
@@ -226,6 +240,16 @@ function readAuthor(value) {
|
|
|
226
240
|
avatarUrl: avatarUrl ?? null
|
|
227
241
|
};
|
|
228
242
|
}
|
|
243
|
+
function readAuthorArray(value) {
|
|
244
|
+
if (!Array.isArray(value)) return void 0;
|
|
245
|
+
const authors = [];
|
|
246
|
+
for (const entry of value) {
|
|
247
|
+
const author = readAuthor(entry);
|
|
248
|
+
if (author === null || author === void 0) return void 0;
|
|
249
|
+
authors.push(author);
|
|
250
|
+
}
|
|
251
|
+
return authors;
|
|
252
|
+
}
|
|
229
253
|
function readState(value) {
|
|
230
254
|
if (value === "open" || value === "closed") return value;
|
|
231
255
|
return void 0;
|
|
@@ -260,11 +284,11 @@ function createNodeSnapshotStore(deps = {}) {
|
|
|
260
284
|
return {
|
|
261
285
|
read: (workspaceRoot) => readWorkspace(dirFor(root, workspaceRoot)),
|
|
262
286
|
write: (entry) => commitEntry(dirFor(root, entry.workspaceRoot), entry),
|
|
263
|
-
remove: (workspaceRoot) =>
|
|
287
|
+
remove: (workspaceRoot) => removeCachedPath(dirFor(root, workspaceRoot)),
|
|
264
288
|
async list() {
|
|
265
289
|
const entries = [];
|
|
266
290
|
for (const meta of await listMetas(root)) {
|
|
267
|
-
const entry = await readWorkspace(
|
|
291
|
+
const entry = await readWorkspace(meta.dir);
|
|
268
292
|
if (entry !== void 0) entries.push(entry);
|
|
269
293
|
}
|
|
270
294
|
return entries;
|
|
@@ -272,7 +296,7 @@ function createNodeSnapshotStore(deps = {}) {
|
|
|
272
296
|
async clear() {
|
|
273
297
|
const metas = await listMetas(root);
|
|
274
298
|
for (const meta of metas) {
|
|
275
|
-
await
|
|
299
|
+
await removeCachedPath(meta.dir);
|
|
276
300
|
}
|
|
277
301
|
return metas.length + await sweepLegacyFiles(root);
|
|
278
302
|
},
|
|
@@ -310,7 +334,7 @@ async function sweepLegacyFiles(root) {
|
|
|
310
334
|
if (!name2.endsWith(".json")) continue;
|
|
311
335
|
const path = join(root, name2);
|
|
312
336
|
if ((await stat2(path)).isDirectory()) continue;
|
|
313
|
-
await
|
|
337
|
+
await removeCachedPath(path);
|
|
314
338
|
removed += 1;
|
|
315
339
|
}
|
|
316
340
|
return removed;
|
|
@@ -321,12 +345,12 @@ async function pruneDirs(root, now) {
|
|
|
321
345
|
const workspaceRoot = meta.entry.workspaceRoot;
|
|
322
346
|
const gone = await isWorkspaceGone(workspaceRoot);
|
|
323
347
|
if (gone === true) {
|
|
324
|
-
await
|
|
348
|
+
await removeCachedPath(meta.dir);
|
|
325
349
|
removed += 1;
|
|
326
350
|
continue;
|
|
327
351
|
}
|
|
328
352
|
if (gone === false && now - meta.entry.fetchedAt > SNAPSHOT_STORE_TTL_MS) {
|
|
329
|
-
await
|
|
353
|
+
await removeCachedPath(meta.dir);
|
|
330
354
|
removed += 1;
|
|
331
355
|
}
|
|
332
356
|
}
|
|
@@ -334,7 +358,7 @@ async function pruneDirs(root, now) {
|
|
|
334
358
|
if (kept.length > SNAPSHOT_STORE_MAX_ENTRIES) {
|
|
335
359
|
const sorted = [...kept].sort((left, right) => left.entry.fetchedAt - right.entry.fetchedAt);
|
|
336
360
|
for (const meta of sorted.slice(0, kept.length - SNAPSHOT_STORE_MAX_ENTRIES)) {
|
|
337
|
-
await
|
|
361
|
+
await removeCachedPath(meta.dir);
|
|
338
362
|
removed += 1;
|
|
339
363
|
}
|
|
340
364
|
}
|
|
@@ -481,7 +505,7 @@ async function readMetaAt(dir) {
|
|
|
481
505
|
if (entry === void 0) return void 0;
|
|
482
506
|
const manifest = readManifest(payload.manifest);
|
|
483
507
|
if (manifest === void 0) return void 0;
|
|
484
|
-
return { entry, manifest };
|
|
508
|
+
return { dir, entry, manifest };
|
|
485
509
|
}
|
|
486
510
|
function readManifest(value) {
|
|
487
511
|
if (!Array.isArray(value)) return void 0;
|
|
@@ -557,7 +581,7 @@ async function sweepOrphans(dir, live) {
|
|
|
557
581
|
return;
|
|
558
582
|
}
|
|
559
583
|
for (const name2 of names) {
|
|
560
|
-
if (!live.has(name2)) await
|
|
584
|
+
if (!live.has(name2)) await removeCachedPath(join(ticketsDirOf(dir), name2));
|
|
561
585
|
}
|
|
562
586
|
}
|
|
563
587
|
async function writeAtomic(target, content) {
|
|
@@ -568,7 +592,7 @@ async function writeAtomic(target, content) {
|
|
|
568
592
|
await rename(temporary, target);
|
|
569
593
|
await chmod(target, 384);
|
|
570
594
|
} catch (error) {
|
|
571
|
-
await
|
|
595
|
+
await removeCachedPath(temporary).catch(() => void 0);
|
|
572
596
|
throw error;
|
|
573
597
|
}
|
|
574
598
|
}
|
|
@@ -576,10 +600,20 @@ function digest(content) {
|
|
|
576
600
|
return createHash("sha1").update(content).digest("hex");
|
|
577
601
|
}
|
|
578
602
|
function dirFor(root, workspaceRoot) {
|
|
579
|
-
return join(root,
|
|
603
|
+
return join(root, snapshotKeyOf(workspaceRoot));
|
|
604
|
+
}
|
|
605
|
+
var CACHE_REMOVE_OPTIONS = {
|
|
606
|
+
recursive: true,
|
|
607
|
+
force: true,
|
|
608
|
+
maxRetries: 10,
|
|
609
|
+
retryDelay: 50
|
|
610
|
+
};
|
|
611
|
+
async function removeCachedPath(target, impl = rm) {
|
|
612
|
+
await impl(target, CACHE_REMOVE_OPTIONS);
|
|
580
613
|
}
|
|
581
|
-
function
|
|
582
|
-
|
|
614
|
+
function snapshotKeyOf(workspaceRoot, platform = process.platform) {
|
|
615
|
+
const comparable = platform === "win32" ? workspaceRoot.replaceAll("\\", "/").toLowerCase() : workspaceRoot;
|
|
616
|
+
return createHash("sha256").update(comparable).digest("hex").slice(0, 16);
|
|
583
617
|
}
|
|
584
618
|
function ticketFileFor(ref) {
|
|
585
619
|
return `${createHash("sha256").update(ref).digest("hex").slice(0, 16)}.json`;
|
|
@@ -840,9 +874,13 @@ function commandFailureDetail(error) {
|
|
|
840
874
|
}
|
|
841
875
|
|
|
842
876
|
// src/core/author.ts
|
|
877
|
+
function readLogin(value, field) {
|
|
878
|
+
if (!isRecord(value)) return null;
|
|
879
|
+
return readText(value[field]);
|
|
880
|
+
}
|
|
843
881
|
function readAuthor2(value, fields, avatarBaseUrl2) {
|
|
844
882
|
if (!isRecord(value)) return null;
|
|
845
|
-
const login =
|
|
883
|
+
const login = readLogin(value, fields.login);
|
|
846
884
|
if (login === null) return null;
|
|
847
885
|
return {
|
|
848
886
|
login,
|
|
@@ -850,6 +888,15 @@ function readAuthor2(value, fields, avatarBaseUrl2) {
|
|
|
850
888
|
avatarUrl: normalizeAvatarUrl(value[fields.avatarUrl], avatarBaseUrl2)
|
|
851
889
|
};
|
|
852
890
|
}
|
|
891
|
+
function readAuthors(value, fields, avatarBaseUrl2) {
|
|
892
|
+
if (!Array.isArray(value)) return [];
|
|
893
|
+
const authors = [];
|
|
894
|
+
for (const entry of value) {
|
|
895
|
+
const author = readAuthor2(entry, fields, avatarBaseUrl2);
|
|
896
|
+
if (author !== null) authors.push(author);
|
|
897
|
+
}
|
|
898
|
+
return authors;
|
|
899
|
+
}
|
|
853
900
|
function normalizeAvatarUrl(value, baseUrl) {
|
|
854
901
|
if (typeof value !== "string") return null;
|
|
855
902
|
const trimmed = value.trim();
|
|
@@ -868,6 +915,17 @@ function readText(value) {
|
|
|
868
915
|
return text.length === 0 ? null : text;
|
|
869
916
|
}
|
|
870
917
|
|
|
918
|
+
// src/core/excerpt.ts
|
|
919
|
+
var EXCERPT_LIMIT = 240;
|
|
920
|
+
function plainExcerpt(text, limit = EXCERPT_LIMIT) {
|
|
921
|
+
const max = Math.max(1, Math.trunc(limit));
|
|
922
|
+
const cleaned = text.replace(/\r\n?/g, "\n").replace(/<!--[\s\S]*?-->/g, " ").replace(/<[^>]+>/g, " ").replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g, "$1").replace(/^\s{0,3}```.*$/gm, "").replace(/^\s{0,3}#{1,6}\s+/gm, "").replace(/^\s{0,3}>\s?/gm, "").replace(/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s+/gm, "").replace(/^\s*\[[ xX]\]\s*/gm, "").replace(/^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/gm, "").replace(/`+/g, "").replace(/\s+/g, " ").trim();
|
|
923
|
+
if (cleaned.length === 0) return void 0;
|
|
924
|
+
const points = Array.from(cleaned);
|
|
925
|
+
if (points.length <= max) return cleaned;
|
|
926
|
+
return `${points.slice(0, max - 1).join("")}\u2026`;
|
|
927
|
+
}
|
|
928
|
+
|
|
871
929
|
// src/core/ticket-detail.ts
|
|
872
930
|
function diffSets(current, target) {
|
|
873
931
|
const currentSet = new Set(current);
|
|
@@ -1023,6 +1081,8 @@ function parseIssue(value, index, avatarBaseUrl2) {
|
|
|
1023
1081
|
const url = readWebUrl(value.html_url);
|
|
1024
1082
|
const body = typeof value.body === "string" ? value.body : "";
|
|
1025
1083
|
const parent = readParent(body, number);
|
|
1084
|
+
const excerpt = plainExcerpt(giteaExcerptBody(body));
|
|
1085
|
+
const commentCount = readNonNegativeInteger(value.comments);
|
|
1026
1086
|
return {
|
|
1027
1087
|
ticket: {
|
|
1028
1088
|
ref: `#${String(number)}`,
|
|
@@ -1031,18 +1091,23 @@ function parseIssue(value, index, avatarBaseUrl2) {
|
|
|
1031
1091
|
state,
|
|
1032
1092
|
labels: readLabels(value.labels),
|
|
1033
1093
|
author: readAuthor2(value.user, AUTHOR_FIELDS, avatarBaseUrl2),
|
|
1034
|
-
assignees:
|
|
1094
|
+
assignees: readAuthors(value.assignees, AUTHOR_FIELDS, avatarBaseUrl2),
|
|
1035
1095
|
createdAt: readString2(value.created_at, `\u7B2C ${String(number)} \u5F20\u7968\u7684\u521B\u5EFA\u65F6\u95F4`),
|
|
1036
1096
|
updatedAt: readString2(value.updated_at, `\u7B2C ${String(number)} \u5F20\u7968\u7684\u66F4\u65B0\u65F6\u95F4`),
|
|
1037
1097
|
openBlockers: 0,
|
|
1038
1098
|
blockedBy: [],
|
|
1039
1099
|
...closedAt === void 0 ? {} : { closedAt },
|
|
1040
1100
|
...url === void 0 ? {} : { url },
|
|
1041
|
-
...parent === void 0 ? {} : { parent }
|
|
1101
|
+
...parent === void 0 ? {} : { parent },
|
|
1102
|
+
...excerpt === void 0 ? {} : { excerpt },
|
|
1103
|
+
...commentCount === void 0 ? {} : { commentCount }
|
|
1042
1104
|
},
|
|
1043
1105
|
body
|
|
1044
1106
|
};
|
|
1045
1107
|
}
|
|
1108
|
+
function giteaExcerptBody(body) {
|
|
1109
|
+
return body.replace(/^\s*Part of #\d+\s*(?:\r?\n|$)/i, "").replace(/^\s*Blocked by:\s*[^\n]*(?:\r?\n|$)/i, "");
|
|
1110
|
+
}
|
|
1046
1111
|
function readParent(body, number) {
|
|
1047
1112
|
const first = body.split(/\r?\n/).find((line) => line.trim().length > 0);
|
|
1048
1113
|
if (first === void 0) return void 0;
|
|
@@ -1073,16 +1138,6 @@ function parseViewer(body) {
|
|
|
1073
1138
|
const login = payload.login;
|
|
1074
1139
|
return typeof login === "string" && login.length > 0 ? login : null;
|
|
1075
1140
|
}
|
|
1076
|
-
function readAssignees(value) {
|
|
1077
|
-
if (!Array.isArray(value)) return [];
|
|
1078
|
-
const logins = [];
|
|
1079
|
-
for (const assignee of value) {
|
|
1080
|
-
if (!isRecord(assignee)) continue;
|
|
1081
|
-
const login = assignee.login;
|
|
1082
|
-
if (typeof login === "string" && login.length > 0) logins.push(login);
|
|
1083
|
-
}
|
|
1084
|
-
return logins;
|
|
1085
|
-
}
|
|
1086
1141
|
function readString2(value, field) {
|
|
1087
1142
|
if (typeof value !== "string" || value.length === 0) {
|
|
1088
1143
|
throw invalid(`${field} \u4E0D\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);
|
|
@@ -1377,6 +1432,9 @@ function parseIssue2(value, index) {
|
|
|
1377
1432
|
const state = readState3(value.state, iid);
|
|
1378
1433
|
const closedAt = readClosedAt2(value.closed_at, iid);
|
|
1379
1434
|
const url = readWebUrl(value.web_url);
|
|
1435
|
+
const description = typeof value.description === "string" ? value.description : "";
|
|
1436
|
+
const excerpt = plainExcerpt(stripLeadingBlockedBy(description));
|
|
1437
|
+
const commentCount = readNonNegativeInteger(value.user_notes_count);
|
|
1380
1438
|
return {
|
|
1381
1439
|
ticket: {
|
|
1382
1440
|
ref: `#${String(iid)}`,
|
|
@@ -1385,18 +1443,23 @@ function parseIssue2(value, index) {
|
|
|
1385
1443
|
state,
|
|
1386
1444
|
labels: readLabels2(value.labels),
|
|
1387
1445
|
author: readAuthor2(value.author, AUTHOR_FIELDS2),
|
|
1388
|
-
assignees:
|
|
1446
|
+
assignees: readAuthors(value.assignees, AUTHOR_FIELDS2),
|
|
1389
1447
|
createdAt: readString3(value.created_at, `\u7B2C ${String(iid)} \u5F20\u7968\u7684\u521B\u5EFA\u65F6\u95F4`),
|
|
1390
1448
|
updatedAt: readString3(value.updated_at, `\u7B2C ${String(iid)} \u5F20\u7968\u7684\u66F4\u65B0\u65F6\u95F4`),
|
|
1391
1449
|
openBlockers: 0,
|
|
1392
1450
|
blockedBy: [],
|
|
1393
1451
|
...closedAt === void 0 ? {} : { closedAt },
|
|
1394
|
-
...url === void 0 ? {} : { url }
|
|
1452
|
+
...url === void 0 ? {} : { url },
|
|
1453
|
+
...excerpt === void 0 ? {} : { excerpt },
|
|
1454
|
+
...commentCount === void 0 ? {} : { commentCount }
|
|
1395
1455
|
},
|
|
1396
|
-
description
|
|
1456
|
+
description,
|
|
1397
1457
|
hasBlockingIssuesCount: Object.hasOwn(value, "blocking_issues_count")
|
|
1398
1458
|
};
|
|
1399
1459
|
}
|
|
1460
|
+
function stripLeadingBlockedBy(text) {
|
|
1461
|
+
return text.replace(/^\s*Blocked by:\s*[^\n]*(?:\r?\n|$)/i, "");
|
|
1462
|
+
}
|
|
1400
1463
|
function readState3(value, iid) {
|
|
1401
1464
|
if (value === "opened") return "open";
|
|
1402
1465
|
if (value === "closed") return "closed";
|
|
@@ -1418,16 +1481,6 @@ function parseViewer2(output) {
|
|
|
1418
1481
|
const username = payload.username;
|
|
1419
1482
|
return typeof username === "string" && username.length > 0 ? username : null;
|
|
1420
1483
|
}
|
|
1421
|
-
function readAssignees2(value) {
|
|
1422
|
-
if (!Array.isArray(value)) return [];
|
|
1423
|
-
const usernames = [];
|
|
1424
|
-
for (const assignee of value) {
|
|
1425
|
-
if (!isRecord(assignee)) continue;
|
|
1426
|
-
const username = assignee.username;
|
|
1427
|
-
if (typeof username === "string" && username.length > 0) usernames.push(username);
|
|
1428
|
-
}
|
|
1429
|
-
return usernames;
|
|
1430
|
-
}
|
|
1431
1484
|
function readIid(value) {
|
|
1432
1485
|
if (typeof value === "number" && Number.isInteger(value) && value > 0) return value;
|
|
1433
1486
|
if (typeof value === "string" && /^\d+$/.test(value)) {
|
|
@@ -2278,22 +2331,34 @@ async function readComments(deps, workspaceRoot, repository, number) {
|
|
|
2278
2331
|
const finish = () => sortCommentsByTime([...collected.values()]);
|
|
2279
2332
|
const first = await readCommentsPage(deps, workspaceRoot, repository, number, 1);
|
|
2280
2333
|
absorb(first.entries);
|
|
2281
|
-
if (first.total !== void 0 && collected.size >= first.total) return finish();
|
|
2282
|
-
if (first.entries.length < deps.pageSize) return finish();
|
|
2283
|
-
const second = await readCommentsPage(deps, workspaceRoot, repository, number, 2);
|
|
2284
|
-
if (absorb(second.entries) === 0) return finish();
|
|
2285
2334
|
const total = first.total;
|
|
2335
|
+
if (total !== void 0) {
|
|
2336
|
+
if (collected.size >= total) return finish();
|
|
2337
|
+
if (Math.ceil(total / deps.pageSize) > MAX_COMMENT_PAGES) {
|
|
2338
|
+
throw incompleteComments(`\u8D85\u8FC7 ${String(MAX_COMMENT_PAGES)} \u9875`);
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
if (total === void 0 && first.entries.length < deps.pageSize) return finish();
|
|
2342
|
+
const second = await readCommentsPage(deps, workspaceRoot, repository, number, 2);
|
|
2343
|
+
if (absorb(second.entries) === 0) {
|
|
2344
|
+
if (total === void 0) return finish();
|
|
2345
|
+
throw incompleteComments(`\u5DF2\u53D6 ${String(collected.size)} / \u5171 ${String(total)} \u6761`);
|
|
2346
|
+
}
|
|
2286
2347
|
if (total === void 0) {
|
|
2287
2348
|
for (let page = 3; page <= MAX_COMMENT_PAGES; page += 1) {
|
|
2288
2349
|
const next = await readCommentsPage(deps, workspaceRoot, repository, number, page);
|
|
2289
2350
|
const added = absorb(next.entries);
|
|
2290
|
-
if (added === 0)
|
|
2291
|
-
if (next.total !== void 0 && collected.size >= next.total)
|
|
2292
|
-
if (next.entries.length < deps.pageSize)
|
|
2351
|
+
if (added === 0) return finish();
|
|
2352
|
+
if (next.total !== void 0 && collected.size >= next.total) return finish();
|
|
2353
|
+
if (next.entries.length < deps.pageSize) return finish();
|
|
2293
2354
|
}
|
|
2294
|
-
|
|
2355
|
+
throw incompleteComments(`\u8D85\u8FC7 ${String(MAX_COMMENT_PAGES)} \u9875`);
|
|
2356
|
+
}
|
|
2357
|
+
const pageCapacity = Math.max(first.entries.length, second.entries.length, 1);
|
|
2358
|
+
const lastPage = Math.ceil(total / pageCapacity);
|
|
2359
|
+
if (lastPage > MAX_COMMENT_PAGES) {
|
|
2360
|
+
throw incompleteComments(`\u8D85\u8FC7 ${String(MAX_COMMENT_PAGES)} \u9875`);
|
|
2295
2361
|
}
|
|
2296
|
-
const lastPage = Math.min(Math.ceil(total / deps.pageSize), MAX_COMMENT_PAGES);
|
|
2297
2362
|
const rest = Array.from({ length: Math.max(0, lastPage - 2) }, (_, index) => index + 3);
|
|
2298
2363
|
const pages = await mapWithConcurrency(
|
|
2299
2364
|
rest,
|
|
@@ -2301,8 +2366,14 @@ async function readComments(deps, workspaceRoot, repository, number) {
|
|
|
2301
2366
|
(page) => readCommentsPage(deps, workspaceRoot, repository, number, page)
|
|
2302
2367
|
);
|
|
2303
2368
|
for (const page of pages) absorb(page.entries);
|
|
2369
|
+
if (collected.size < total) {
|
|
2370
|
+
throw incompleteComments(`\u5DF2\u53D6 ${String(collected.size)} / \u5171 ${String(total)} \u6761`);
|
|
2371
|
+
}
|
|
2304
2372
|
return finish();
|
|
2305
2373
|
}
|
|
2374
|
+
function incompleteComments(detail) {
|
|
2375
|
+
return new TrackerError("fetch-failed", `Gitea \u5DE5\u5355\u8BC4\u8BBA\u672A\u53D6\u5168\uFF1A${detail}\u3002`);
|
|
2376
|
+
}
|
|
2306
2377
|
async function readCommentsPage(deps, workspaceRoot, repository, number, page) {
|
|
2307
2378
|
const endpoint = `/repos/${repository.owner}/${repository.name}/issues/${String(number)}/comments?page=${String(page)}&limit=${String(deps.pageSize)}`;
|
|
2308
2379
|
const response = await callGiteaApi(deps.run, workspaceRoot, endpoint);
|
|
@@ -2389,7 +2460,7 @@ async function readGiteaOptions(deps, workspaceRoot) {
|
|
|
2389
2460
|
const repository = await readRepository(deps.run, workspaceRoot);
|
|
2390
2461
|
return {
|
|
2391
2462
|
labels: await readLabels3(deps, workspaceRoot, repository),
|
|
2392
|
-
assignees: await
|
|
2463
|
+
assignees: await readAssignees(deps, workspaceRoot, repository)
|
|
2393
2464
|
};
|
|
2394
2465
|
}
|
|
2395
2466
|
async function readLabels3(deps, workspaceRoot, repository) {
|
|
@@ -2411,7 +2482,7 @@ async function readLabels3(deps, workspaceRoot, repository) {
|
|
|
2411
2482
|
}
|
|
2412
2483
|
return dedupeBy(labels, (label) => label.name);
|
|
2413
2484
|
}
|
|
2414
|
-
async function
|
|
2485
|
+
async function readAssignees(deps, workspaceRoot, repository) {
|
|
2415
2486
|
const response = await callGiteaApi(
|
|
2416
2487
|
deps.run,
|
|
2417
2488
|
workspaceRoot,
|
|
@@ -2976,7 +3047,7 @@ function readViewer2(payload) {
|
|
|
2976
3047
|
}
|
|
2977
3048
|
function readPageCursor(issues) {
|
|
2978
3049
|
const pageInfo = issues.pageInfo;
|
|
2979
|
-
if (!isRecord(pageInfo))
|
|
3050
|
+
if (!isRecord(pageInfo)) throw invalid3("\u4ED3\u5E93\u7684 issues.pageInfo \u7F3A\u5931");
|
|
2980
3051
|
const hasNextPage = pageInfo.hasNextPage;
|
|
2981
3052
|
if (typeof hasNextPage !== "boolean") {
|
|
2982
3053
|
throw invalid3("\u4ED3\u5E93\u7684 issues.pageInfo.hasNextPage \u4E0D\u662F\u5E03\u5C14\u503C");
|
|
@@ -3001,6 +3072,9 @@ function parseIssueNode(value, index, repository) {
|
|
|
3001
3072
|
const closedAt = readClosedAt3(value.closedAt, number);
|
|
3002
3073
|
const url = readWebUrl(value.url);
|
|
3003
3074
|
const parent = readParent2(value.parent, number, repository);
|
|
3075
|
+
const bodyText = typeof value.bodyText === "string" ? value.bodyText : void 0;
|
|
3076
|
+
const excerpt = bodyText === void 0 ? void 0 : plainExcerpt(bodyText);
|
|
3077
|
+
const commentCount = readCommentTotal(value.comments);
|
|
3004
3078
|
return {
|
|
3005
3079
|
ref: `#${String(number)}`,
|
|
3006
3080
|
number,
|
|
@@ -3008,13 +3082,15 @@ function parseIssueNode(value, index, repository) {
|
|
|
3008
3082
|
state,
|
|
3009
3083
|
labels: readLabels4(value.labels),
|
|
3010
3084
|
author: readAuthor2(value.author, AUTHOR_FIELDS3),
|
|
3011
|
-
assignees:
|
|
3085
|
+
assignees: readUserNodes(value.assignees),
|
|
3012
3086
|
createdAt: readString4(value.createdAt, `\u7B2C ${String(number)} \u5F20\u7968\u7684\u521B\u5EFA\u65F6\u95F4`),
|
|
3013
3087
|
updatedAt: readString4(value.updatedAt, `\u7B2C ${String(number)} \u5F20\u7968\u7684\u66F4\u65B0\u65F6\u95F4`),
|
|
3014
3088
|
openBlockers: readOpenBlockers(value.issueDependenciesSummary),
|
|
3015
3089
|
...closedAt === void 0 ? {} : { closedAt },
|
|
3016
3090
|
...url === void 0 ? {} : { url },
|
|
3017
|
-
...parent === void 0 ? {} : { parent }
|
|
3091
|
+
...parent === void 0 ? {} : { parent },
|
|
3092
|
+
...excerpt === void 0 ? {} : { excerpt },
|
|
3093
|
+
...commentCount === void 0 ? {} : { commentCount }
|
|
3018
3094
|
};
|
|
3019
3095
|
}
|
|
3020
3096
|
function readParent2(value, number, repository) {
|
|
@@ -3070,17 +3146,13 @@ function readLabels4(value) {
|
|
|
3070
3146
|
}
|
|
3071
3147
|
return labels;
|
|
3072
3148
|
}
|
|
3073
|
-
function
|
|
3149
|
+
function readUserNodes(value) {
|
|
3074
3150
|
if (!isRecord(value)) return [];
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
const login = node.login;
|
|
3081
|
-
if (typeof login === "string" && login.length > 0) logins.push(login);
|
|
3082
|
-
}
|
|
3083
|
-
return logins;
|
|
3151
|
+
return readAuthors(value.nodes, AUTHOR_FIELDS3);
|
|
3152
|
+
}
|
|
3153
|
+
function readCommentTotal(value) {
|
|
3154
|
+
if (!isRecord(value)) return void 0;
|
|
3155
|
+
return readNonNegativeInteger(value.totalCount);
|
|
3084
3156
|
}
|
|
3085
3157
|
function readOpenBlockers(value) {
|
|
3086
3158
|
if (value === void 0 || value === null) return 0;
|
|
@@ -3188,14 +3260,16 @@ var DEFAULT_CHANGES_PAGE_LIMIT = 5;
|
|
|
3188
3260
|
var ISSUE_NODES = `nodes {
|
|
3189
3261
|
number
|
|
3190
3262
|
title
|
|
3263
|
+
bodyText
|
|
3191
3264
|
url
|
|
3192
3265
|
state
|
|
3193
3266
|
createdAt
|
|
3194
3267
|
updatedAt
|
|
3195
3268
|
closedAt
|
|
3269
|
+
comments { totalCount }
|
|
3196
3270
|
labels(first: 50) { nodes { name } }
|
|
3197
3271
|
author { login avatarUrl ... on User { name } }
|
|
3198
|
-
assignees(first: 10) { nodes { login } }
|
|
3272
|
+
assignees(first: 10) { nodes { login avatarUrl ... on User { name } } }
|
|
3199
3273
|
issueDependenciesSummary { blockedBy }
|
|
3200
3274
|
parent { number repository { nameWithOwner } }
|
|
3201
3275
|
}`;
|
|
@@ -5620,7 +5694,9 @@ function toTicketSnapshot(ticket) {
|
|
|
5620
5694
|
...ticket.closedAt === void 0 ? {} : { closedAt: ticket.closedAt },
|
|
5621
5695
|
...ticket.url === void 0 ? {} : { url: ticket.url },
|
|
5622
5696
|
...ticket.blockedBy === void 0 ? {} : { blockedBy: ticket.blockedBy },
|
|
5623
|
-
...ticket.parent === void 0 ? {} : { parent: ticket.parent }
|
|
5697
|
+
...ticket.parent === void 0 ? {} : { parent: ticket.parent },
|
|
5698
|
+
...ticket.excerpt === void 0 ? {} : { excerpt: ticket.excerpt },
|
|
5699
|
+
...ticket.commentCount === void 0 ? {} : { commentCount: ticket.commentCount }
|
|
5624
5700
|
};
|
|
5625
5701
|
}
|
|
5626
5702
|
function buildStoredSnapshot(deps, stored, state) {
|
|
@@ -5914,33 +5990,73 @@ function ticketsDiffer(base, raw) {
|
|
|
5914
5990
|
return JSON.stringify(base.tickets) !== JSON.stringify(raw.tickets);
|
|
5915
5991
|
}
|
|
5916
5992
|
async function respondUnchanged(host, workspaceRoot, resolved, base, raw, ifVersion, startedAt) {
|
|
5993
|
+
const checkedAt = host.now();
|
|
5917
5994
|
if (ifVersion !== void 0 && ifVersion === base.libraryVersion) {
|
|
5995
|
+
const verified = await verifyCachedWorkspace(
|
|
5996
|
+
host,
|
|
5997
|
+
workspaceRoot,
|
|
5998
|
+
resolved,
|
|
5999
|
+
base,
|
|
6000
|
+
raw,
|
|
6001
|
+
checkedAt,
|
|
6002
|
+
startedAt
|
|
6003
|
+
);
|
|
6004
|
+
if (verified !== null) {
|
|
6005
|
+
host.guard.noteFailure(workspaceRoot, host.now());
|
|
6006
|
+
return { ok: false, error: verified };
|
|
6007
|
+
}
|
|
5918
6008
|
host.guard.noteSuccess(workspaceRoot);
|
|
5919
6009
|
return {
|
|
5920
6010
|
ok: true,
|
|
5921
|
-
result: { kind: "not-modified", version: base.libraryVersion, checkedAt
|
|
6011
|
+
result: { kind: "not-modified", version: base.libraryVersion, checkedAt }
|
|
5922
6012
|
};
|
|
5923
6013
|
}
|
|
6014
|
+
const published = await host.publish(workspaceRoot, resolved, raw, startedAt, "full", {
|
|
6015
|
+
skipWrite: true,
|
|
6016
|
+
versionFallback: base.libraryVersion
|
|
6017
|
+
});
|
|
6018
|
+
if (!published.ok) {
|
|
6019
|
+
host.guard.noteFailure(workspaceRoot, host.now());
|
|
6020
|
+
return published;
|
|
6021
|
+
}
|
|
5924
6022
|
if (ifVersion !== void 0 && ifVersion < base.libraryVersion) {
|
|
5925
6023
|
const changes = await host.store?.changesSince(workspaceRoot, ifVersion);
|
|
5926
6024
|
if (changes !== void 0) {
|
|
5927
|
-
const delta = buildDelta(
|
|
6025
|
+
const delta = buildDelta(
|
|
6026
|
+
host,
|
|
6027
|
+
base.libraryVersion,
|
|
6028
|
+
raw.fetchedAt,
|
|
6029
|
+
changes,
|
|
6030
|
+
base,
|
|
6031
|
+
published.result
|
|
6032
|
+
);
|
|
5928
6033
|
if (delta !== void 0) {
|
|
5929
6034
|
host.guard.noteSuccess(workspaceRoot);
|
|
5930
6035
|
return { ok: true, result: delta };
|
|
5931
6036
|
}
|
|
5932
6037
|
}
|
|
5933
6038
|
}
|
|
6039
|
+
host.guard.noteSuccess(workspaceRoot);
|
|
6040
|
+
return { ok: true, result: { kind: "full", snapshot: published.result } };
|
|
6041
|
+
}
|
|
6042
|
+
async function verifyCachedWorkspace(host, workspaceRoot, resolved, base, raw, checkedAt, startedAt) {
|
|
6043
|
+
const repositoryHost = resolved.kind === "markdown" ? null : resolved.address?.host ?? null;
|
|
6044
|
+
const cached = host.cache.get(workspaceRoot);
|
|
6045
|
+
if (cached?.kind === resolved.kind && cached.repositoryHost === repositoryHost && cached.raw.repository === base.repository && cached.snapshot.libraryVersion === base.libraryVersion) {
|
|
6046
|
+
cached.snapshot = {
|
|
6047
|
+
...cached.snapshot,
|
|
6048
|
+
source: "live",
|
|
6049
|
+
stale: false,
|
|
6050
|
+
refreshError: null,
|
|
6051
|
+
fetchedAt: checkedAt
|
|
6052
|
+
};
|
|
6053
|
+
return null;
|
|
6054
|
+
}
|
|
5934
6055
|
const published = await host.publish(workspaceRoot, resolved, raw, startedAt, "full", {
|
|
5935
6056
|
skipWrite: true,
|
|
5936
6057
|
versionFallback: base.libraryVersion
|
|
5937
6058
|
});
|
|
5938
|
-
|
|
5939
|
-
host.guard.noteFailure(workspaceRoot, host.now());
|
|
5940
|
-
return published;
|
|
5941
|
-
}
|
|
5942
|
-
host.guard.noteSuccess(workspaceRoot);
|
|
5943
|
-
return { ok: true, result: { kind: "full", snapshot: published.result } };
|
|
6059
|
+
return published.ok ? null : published.error;
|
|
5944
6060
|
}
|
|
5945
6061
|
async function shapeDelta(host, workspaceRoot, snapshot, ifVersion) {
|
|
5946
6062
|
const full = { kind: "full", snapshot };
|
package/package.json
CHANGED
package/skills/README.md
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
English | [简体中文](README.zh-CN.md)
|
|
2
|
+
|
|
1
3
|
# skills
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
`skills
|
|
5
|
-
|
|
5
|
+
Skills shipped with the plugin (skill bodies and seed templates are English only, and file names match upstream). The directory structure mirrors upstream [mattpocock/skills](https://github.com/mattpocock/skills):
|
|
6
|
+
`skills/<category>/<skill name>/`; skill files keep their upstream file names (such as `issue-tracker-gitea.md`), with no separate directories and no translation copies.
|
|
7
|
+
When upstream skills are upgraded, align by the same file name.
|
|
6
8
|
|
|
7
|
-
##
|
|
9
|
+
## Ticket backend seed templates
|
|
8
10
|
|
|
9
|
-
`engineering/setup-matt-pocock-skills/`
|
|
10
|
-
`docs/agents/issue-tracker.md
|
|
11
|
-
Gitea
|
|
11
|
+
Under `engineering/setup-matt-pocock-skills/` there is one seed template per ticket backend; when initializing a workspace, choose one of them and write it into
|
|
12
|
+
`docs/agents/issue-tracker.md`. Templates for GitHub, GitLab and local Markdown come with the upstream skills; the one this plugin adds is
|
|
13
|
+
the Gitea version: `issue-tracker-gitea.md`.
|
|
12
14
|
|
|
13
|
-
Gitea
|
|
15
|
+
Conventions for initializing the Gitea backend:
|
|
14
16
|
|
|
15
|
-
1.
|
|
16
|
-
Gitea
|
|
17
|
-
2.
|
|
18
|
-
3. `tea --version`
|
|
19
|
-
4.
|
|
20
|
-
|
|
21
|
-
5.
|
|
17
|
+
1. When the host of the current workspace's `origin` remote matches the host of a login in `tea logins list --output json`, recommend
|
|
18
|
+
Gitea by default; the user may also choose it manually;
|
|
19
|
+
2. If Gitea is chosen but no matching login exists, stop and have the user run `tea login add` first; do not write a configuration that cannot work;
|
|
20
|
+
3. When `tea --version` is below 0.16, suggest upgrading; `tea api --include` and `--description-file` depend on this version;
|
|
21
|
+
4. The completion criterion is that running `tea api /repos/{owner}/{repo}` in the repository directory returns repository information (`tea repo` only lists repositories
|
|
22
|
+
and cannot judge the current directory);
|
|
23
|
+
5. First use `tea labels list --output json` to see which triage labels are missing, then use `tea labels create` to add them, and finally write the seed template.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[English](README.md) | 简体中文
|
|
2
|
+
|
|
3
|
+
# skills
|
|
4
|
+
|
|
5
|
+
随插件发布的技能(技能正文与种子模板只英文,文件名与上游一致)。目录结构对照上游 [mattpocock/skills](https://github.com/mattpocock/skills):
|
|
6
|
+
`skills/<分类>/<技能名>/`,技能文件沿用上游文件名(如 `issue-tracker-gitea.md`),不另起目录,也不提供翻译副本。
|
|
7
|
+
上游技能升级时按同名文件对齐。
|
|
8
|
+
|
|
9
|
+
## 工单后端种子模板
|
|
10
|
+
|
|
11
|
+
`engineering/setup-matt-pocock-skills/` 下每种工单后端一份种子模板,初始化工作区时选用其中一份写进
|
|
12
|
+
`docs/agents/issue-tracker.md`。GitHub、GitLab 与本地 Markdown 的模板随上游技能提供;本插件新增的是
|
|
13
|
+
Gitea 版:`issue-tracker-gitea.md`。
|
|
14
|
+
|
|
15
|
+
Gitea 后端的初始化约定:
|
|
16
|
+
|
|
17
|
+
1. 当前工作区 `origin` 远端的主机与 `tea logins list --output json` 里某个登录的主机一致时,默认推荐
|
|
18
|
+
Gitea;用户也可以手动选择;
|
|
19
|
+
2. 选了 Gitea 但没有匹配的登录时停下来,让用户先运行 `tea login add`,不要写出一份用不了的配置;
|
|
20
|
+
3. `tea --version` 低于 0.16 时提示升级,`tea api --include` 与 `--description-file` 依赖这个版本;
|
|
21
|
+
4. 完成标志是在仓库目录里运行 `tea api /repos/{owner}/{repo}` 能返回仓库信息(`tea repo` 只列仓库,
|
|
22
|
+
不能判断当前目录);
|
|
23
|
+
5. 先用 `tea labels list --output json` 看缺哪些分诊标签,再用 `tea labels create` 补齐,最后写种子模板。
|