@danielstyle/featflow 0.0.0-stage → 0.6.4

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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +249 -2
  3. package/README.zh-CN.md +250 -0
  4. package/bin/featflow.mjs +116 -0
  5. package/package.json +63 -4
  6. package/skills/featflow/SKILL.md +127 -0
  7. package/skills/featflow-issues/SKILL.md +104 -0
  8. package/skills/featflow-regression/SKILL.md +63 -0
  9. package/src/agent-docs.mjs +143 -0
  10. package/src/changed-files.mjs +204 -0
  11. package/src/commands/cleanup.mjs +221 -0
  12. package/src/commands/codegraph.mjs +108 -0
  13. package/src/commands/doctor.mjs +303 -0
  14. package/src/commands/finish.mjs +249 -0
  15. package/src/commands/hook-cmd.mjs +78 -0
  16. package/src/commands/hooks-cmd.mjs +247 -0
  17. package/src/commands/init.mjs +477 -0
  18. package/src/commands/issue.mjs +434 -0
  19. package/src/commands/new.mjs +311 -0
  20. package/src/commands/plan-check.mjs +75 -0
  21. package/src/commands/policy-cmd.mjs +55 -0
  22. package/src/commands/pr-cleanup.mjs +194 -0
  23. package/src/commands/regression.mjs +206 -0
  24. package/src/commands/setup.mjs +343 -0
  25. package/src/commands/size-check.mjs +137 -0
  26. package/src/commands/skills.mjs +181 -0
  27. package/src/commands/status.mjs +100 -0
  28. package/src/commands/sync.mjs +421 -0
  29. package/src/commands/verify.mjs +206 -0
  30. package/src/commands/worktree.mjs +205 -0
  31. package/src/config.mjs +295 -0
  32. package/src/detect.mjs +314 -0
  33. package/src/git.mjs +331 -0
  34. package/src/hook-adapters.mjs +218 -0
  35. package/src/hooks-core.mjs +420 -0
  36. package/src/index.mjs +14 -0
  37. package/src/init-args.mjs +294 -0
  38. package/src/init-hooks.mjs +312 -0
  39. package/src/init-prompts.mjs +191 -0
  40. package/src/issues-helpers.mjs +463 -0
  41. package/src/issues.mjs +521 -0
  42. package/src/plan.mjs +202 -0
  43. package/src/policy.mjs +143 -0
  44. package/src/regression.mjs +338 -0
  45. package/src/size-check.mjs +203 -0
  46. package/src/skills-manager.mjs +348 -0
  47. package/src/tui-select.mjs +378 -0
  48. package/templates/adapters/antigravity/hooks.json +42 -0
  49. package/templates/adapters/claude-code/settings.json +46 -0
  50. package/templates/adapters/codex/config.toml +19 -0
  51. package/templates/adapters/cursor/hooks.json +27 -0
  52. package/templates/agents/codex/codebase-locator.toml +28 -0
  53. package/templates/agents/codex/implementation-scout.toml +28 -0
  54. package/templates/agents/codex/regression-guard-planner.toml +20 -0
  55. package/templates/features/README.md +56 -0
  56. package/templates/features/_program_template.md +79 -0
  57. package/templates/features/_template.md +120 -0
  58. package/templates/features/current-feature.md +18 -0
  59. package/templates/githooks/post-merge +10 -0
  60. package/templates/githooks/pre-commit +14 -0
  61. package/templates/githooks/pre-push +13 -0
  62. package/templates/regression/regression-ledger.yml +23 -0
  63. package/templates/snippets/AGENTS-workflow.md +21 -0
package/src/issues.mjs ADDED
@@ -0,0 +1,521 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+
4
+ import { DEFAULT_ISSUES_CONFIG, resolveIssuesConfig } from "./config.mjs";
5
+ import { gitConfigGet } from "./git.mjs";
6
+ import { createTaskWorktree, preflightTaskWorktree } from "./commands/worktree.mjs";
7
+ import {
8
+ buildWorkflowLabels,
9
+ deriveBranchNameFromIssue,
10
+ deriveBranchSpecFromIssue,
11
+ downloadIssueAssets,
12
+ ensureWorkflowLabels,
13
+ extractIssueAssetPaths,
14
+ failIssue,
15
+ formatIssueTitle,
16
+ getCurrentGitHubUser,
17
+ ghRun,
18
+ parseIssueTitle,
19
+ priorityRankOf,
20
+ sortIssues,
21
+ TYPE_TO_DEFAULT_LABEL,
22
+ uploadIssueAttachments,
23
+ VALID_ISSUE_TYPES,
24
+ VALID_PRIORITIES,
25
+ } from "./issues-helpers.mjs";
26
+
27
+ export * from "./issues-helpers.mjs";
28
+
29
+ export function createIssue({
30
+ repoSlug,
31
+ repoName,
32
+ type,
33
+ scope = "",
34
+ title,
35
+ body = "",
36
+ bodyFile = "",
37
+ priority = "",
38
+ agentReady = false,
39
+ labels: extraLabels = [],
40
+ attaches = [],
41
+ imageUrls = [],
42
+ assetsConfig = null,
43
+ issuesConfig = DEFAULT_ISSUES_CONFIG,
44
+ validTypes = VALID_ISSUE_TYPES,
45
+ dryRun = false,
46
+ cwd = process.cwd(),
47
+ }) {
48
+ const resolvedRepoName = repoName || repoSlug.split("/")[1] || repoSlug;
49
+ const formattedTitle = formatIssueTitle(type, scope, title, validTypes);
50
+
51
+ let effectiveBody = body;
52
+ if (bodyFile) {
53
+ const absBody = path.resolve(bodyFile);
54
+ if (!existsSync(absBody)) {
55
+ failIssue(`Body file not found: ${absBody}`);
56
+ }
57
+ effectiveBody = readFileSync(absBody, "utf8");
58
+ }
59
+ if (!String(effectiveBody ?? "").trim()) {
60
+ failIssue('Missing issue body. Pass `--body "..."` or `--body-file <path>`.');
61
+ }
62
+
63
+ if (priority && !VALID_PRIORITIES.includes(priority.toLowerCase())) {
64
+ failIssue(`Invalid --priority "${priority}". Expected one of: ${VALID_PRIORITIES.join(", ")}`);
65
+ }
66
+
67
+ const uploaded = uploadIssueAttachments(assetsConfig, resolvedRepoName, attaches, { dryRun, cwd });
68
+ const imageLines = [
69
+ ...uploaded.map((img) => `![${img.alt}](${img.url})`),
70
+ ...(imageUrls ?? []).map((url, idx) => `![screenshot-${idx + 1}](${url})`),
71
+ ];
72
+
73
+ let finalBody = effectiveBody.trimEnd();
74
+ if (imageLines.length > 0) {
75
+ finalBody = `${finalBody}\n\n## Screenshots\n\n${imageLines.join("\n\n")}\n`;
76
+ }
77
+
78
+ const labels = [];
79
+ const defaultLabel = TYPE_TO_DEFAULT_LABEL[String(type).toLowerCase()];
80
+ if (defaultLabel) labels.push(defaultLabel);
81
+ if (priority) labels.push(`priority:${priority.toLowerCase()}`);
82
+ if (agentReady) labels.push("agent-ready");
83
+ for (const extra of extraLabels ?? []) {
84
+ for (const part of String(extra).split(",").map((s) => s.trim()).filter(Boolean)) {
85
+ if (!labels.includes(part)) labels.push(part);
86
+ }
87
+ }
88
+
89
+ ensureWorkflowLabels(repoSlug, labels, { dryRun, cwd, issuesConfig });
90
+
91
+ let createdUrl = "";
92
+ let issueNumber = null;
93
+ if (!dryRun) {
94
+ const createArgs = ["issue", "create", "-R", repoSlug, "--title", formattedTitle, "--body-file", "-"];
95
+ for (const label of labels) createArgs.push("--label", label);
96
+ createdUrl = ghRun(createArgs, { input: finalBody, cwd });
97
+ const numMatch = createdUrl.match(/\/issues\/(\d+)$/);
98
+ issueNumber = numMatch ? Number(numMatch[1]) : null;
99
+ }
100
+
101
+ return {
102
+ repo: resolvedRepoName,
103
+ repoSlug,
104
+ number: issueNumber,
105
+ ref: issueNumber ? `${resolvedRepoName}#${issueNumber}` : null,
106
+ url: createdUrl || null,
107
+ title: formattedTitle,
108
+ labels,
109
+ uploadedAttachments: uploaded,
110
+ dryRun,
111
+ };
112
+ }
113
+
114
+ export function listIssues({
115
+ repoSlug,
116
+ repoName,
117
+ state = "open",
118
+ limit = 30,
119
+ labels = [],
120
+ mine = false,
121
+ unassigned = false,
122
+ currentLogin = "",
123
+ issuesConfig = DEFAULT_ISSUES_CONFIG,
124
+ cwd = process.cwd(),
125
+ }) {
126
+ const resolvedRepoName = repoName || repoSlug.split("/")[1] || repoSlug;
127
+ const inProgressLabel = issuesConfig?.inProgressLabel || DEFAULT_ISSUES_CONFIG.inProgressLabel;
128
+ const effectiveLogin = mine ? currentLogin || getCurrentGitHubUser(cwd) : "";
129
+
130
+ const args = [
131
+ "issue",
132
+ "list",
133
+ "-R",
134
+ repoSlug,
135
+ "--state",
136
+ state || "open",
137
+ "--limit",
138
+ String(limit || 30),
139
+ "--json",
140
+ "number,title,state,url,labels,assignees,createdAt,updatedAt,comments",
141
+ ];
142
+ for (const label of labels ?? []) args.push("--label", label);
143
+ if (mine && effectiveLogin) args.push("--assignee", effectiveLogin);
144
+
145
+ const raw = ghRun(args, { cwd });
146
+ const parsed = raw ? JSON.parse(raw) : [];
147
+ const items = [];
148
+
149
+ for (const item of parsed) {
150
+ const labelNames = (item.labels ?? []).map((l) => l.name);
151
+ const assigneeLogins = (item.assignees ?? []).map((a) => a.login);
152
+ const claimed = assigneeLogins.length > 0 || labelNames.includes(inProgressLabel);
153
+ if (unassigned && claimed) continue;
154
+ const parsedTitle = parseIssueTitle(item.title);
155
+ items.push({
156
+ repo: resolvedRepoName,
157
+ repoSlug,
158
+ number: item.number,
159
+ ref: `${resolvedRepoName}#${item.number}`,
160
+ title: item.title,
161
+ parsedType: parsedTitle?.type ?? null,
162
+ parsedScope: parsedTitle?.scope || null,
163
+ state: item.state,
164
+ url: item.url,
165
+ labels: labelNames,
166
+ assignees: assigneeLogins,
167
+ claimed,
168
+ priorityRank: priorityRankOf(labelNames),
169
+ commentCount: Array.isArray(item.comments) ? item.comments.length : 0,
170
+ createdAt: item.createdAt,
171
+ updatedAt: item.updatedAt,
172
+ });
173
+ }
174
+
175
+ return sortIssues(items);
176
+ }
177
+
178
+ export function viewIssue({
179
+ repoSlug,
180
+ repoName,
181
+ number,
182
+ ref,
183
+ assetsConfig = null,
184
+ downloadImages = false,
185
+ outDir = "",
186
+ issuesConfig = DEFAULT_ISSUES_CONFIG,
187
+ branchMode = "trunk",
188
+ developer = "",
189
+ cwd = process.cwd(),
190
+ }) {
191
+ const resolvedRepoName = repoName || repoSlug.split("/")[1] || repoSlug;
192
+ const resolvedRef = ref || `${resolvedRepoName}#${number}`;
193
+ const inProgressLabel = issuesConfig?.inProgressLabel || DEFAULT_ISSUES_CONFIG.inProgressLabel;
194
+
195
+ const raw = ghRun(
196
+ [
197
+ "issue",
198
+ "view",
199
+ String(number),
200
+ "-R",
201
+ repoSlug,
202
+ "--json",
203
+ "number,title,body,state,url,author,labels,assignees,comments,createdAt,updatedAt",
204
+ ],
205
+ { cwd },
206
+ );
207
+ const issue = JSON.parse(raw);
208
+ const labels = (issue.labels ?? []).map((l) => l.name);
209
+ const assignees = (issue.assignees ?? []).map((a) => a.login);
210
+ const comments = (issue.comments ?? []).map((c) => ({
211
+ author: c.author?.login ?? "unknown",
212
+ createdAt: c.createdAt,
213
+ body: c.body,
214
+ }));
215
+
216
+ const assetRefs = extractIssueAssetPaths(assetsConfig, [issue.body, ...comments.map((c) => c.body)]);
217
+ const downloadedImages = downloadImages
218
+ ? downloadIssueAssets(assetsConfig, resolvedRepoName, issue.number, assetRefs, { outDir, cwd })
219
+ : [];
220
+
221
+ return {
222
+ repo: resolvedRepoName,
223
+ repoSlug,
224
+ number: issue.number,
225
+ ref: resolvedRef,
226
+ url: issue.url,
227
+ state: issue.state,
228
+ title: issue.title,
229
+ parsedTitle: parseIssueTitle(issue.title),
230
+ suggestedBranchSpec: deriveBranchSpecFromIssue({ number: issue.number, title: issue.title, labels }),
231
+ suggestedBranch: deriveBranchNameFromIssue(
232
+ { number: issue.number, title: issue.title, labels },
233
+ { mode: branchMode, developer },
234
+ ),
235
+ author: issue.author?.login ?? "unknown",
236
+ labels,
237
+ assignees,
238
+ claimed: assignees.length > 0 || labels.includes(inProgressLabel),
239
+ body: issue.body ?? "",
240
+ comments,
241
+ issueAssets: assetRefs,
242
+ downloadedImages,
243
+ };
244
+ }
245
+
246
+ export function fetchIssueForClaim(repoSlug, number, { cwd = process.cwd() } = {}) {
247
+ const raw = ghRun(
248
+ ["issue", "view", String(number), "-R", repoSlug, "--json", "number,title,state,url,labels,assignees"],
249
+ { cwd },
250
+ );
251
+ const issue = JSON.parse(raw);
252
+ return {
253
+ ...issue,
254
+ labelNames: (issue.labels ?? []).map((l) => l.name),
255
+ assigneeLogins: (issue.assignees ?? []).map((a) => a.login),
256
+ };
257
+ }
258
+
259
+ export function checkIssueClaimable(
260
+ issue,
261
+ currentUser,
262
+ { force = false, inProgressLabel = DEFAULT_ISSUES_CONFIG.inProgressLabel, ref = `#${issue.number}` } = {},
263
+ ) {
264
+ const labels = issue.labelNames ?? (issue.labels ?? []).map((l) => (typeof l === "string" ? l : l.name));
265
+ const assignees = issue.assigneeLogins ?? (issue.assignees ?? []).map((a) => (typeof a === "string" ? a : a.login));
266
+
267
+ if (issue.state === "CLOSED" && !force) {
268
+ failIssue(`${ref} is already CLOSED. Pass --force to override.`);
269
+ }
270
+ const otherAssignees = assignees.filter((login) => login !== currentUser);
271
+ if (otherAssignees.length > 0 && !force) {
272
+ failIssue(
273
+ `${ref} is already assigned to ${otherAssignees.join(", ")}. Refusing to steal claim (pass --force to override).`,
274
+ );
275
+ }
276
+ if (labels.includes(inProgressLabel) && !assignees.includes(currentUser) && !force) {
277
+ failIssue(`${ref} is already labeled ${inProgressLabel}. Refusing to double-claim (pass --force to override).`);
278
+ }
279
+ }
280
+
281
+ export function mutateIssueClaim({
282
+ repoSlug,
283
+ number,
284
+ currentUser,
285
+ existingLabels = [],
286
+ branchLabel,
287
+ targetsDescription = "",
288
+ issuesConfig = DEFAULT_ISSUES_CONFIG,
289
+ dryRun = false,
290
+ cwd = process.cwd(),
291
+ }) {
292
+ const inProgressLabel = issuesConfig?.inProgressLabel || DEFAULT_ISSUES_CONFIG.inProgressLabel;
293
+ const blockedLabel = issuesConfig?.blockedLabel || DEFAULT_ISSUES_CONFIG.blockedLabel;
294
+
295
+ ensureWorkflowLabels(repoSlug, [inProgressLabel], { dryRun, cwd, issuesConfig });
296
+
297
+ const lines = [`Claimed by @${currentUser}.`, `- Branch: \`${branchLabel}\``];
298
+ if (targetsDescription) lines.push(targetsDescription);
299
+ const claimComment = lines.join("\n");
300
+
301
+ if (!dryRun) {
302
+ const editArgs = [
303
+ "issue",
304
+ "edit",
305
+ String(number),
306
+ "-R",
307
+ repoSlug,
308
+ "--add-assignee",
309
+ currentUser,
310
+ "--add-label",
311
+ inProgressLabel,
312
+ ];
313
+ if (existingLabels.includes(blockedLabel)) editArgs.push("--remove-label", blockedLabel);
314
+ ghRun(editArgs, { cwd });
315
+ ghRun(["issue", "comment", String(number), "-R", repoSlug, "--body-file", "-"], { input: claimComment, cwd });
316
+ }
317
+
318
+ return { claimComment, inProgressLabel };
319
+ }
320
+
321
+ export function claimIssue({
322
+ repoRoot,
323
+ config,
324
+ repoSlug,
325
+ repoName,
326
+ number,
327
+ ref,
328
+ branch = "",
329
+ worktreePath = "",
330
+ base = "",
331
+ noWorktree = false,
332
+ skipPostCreate = false,
333
+ force = false,
334
+ dryRun = false,
335
+ captureOutput = false,
336
+ }) {
337
+ const resolvedRepoName = repoName || repoSlug.split("/")[1] || repoSlug;
338
+ const resolvedRef = ref || `${resolvedRepoName}#${number}`;
339
+ const issuesConfig = resolveIssuesConfig(config);
340
+
341
+ const issue = fetchIssueForClaim(repoSlug, number, { cwd: repoRoot });
342
+ const me = getCurrentGitHubUser(repoRoot);
343
+ checkIssueClaimable(issue, me, { force, inProgressLabel: issuesConfig.inProgressLabel, ref: resolvedRef });
344
+
345
+ const developer =
346
+ config.mode === "developer-branch" ? gitConfigGet(config.developerBranchConfigKey, repoRoot) : "";
347
+ const branchSpec = deriveBranchSpecFromIssue({ number: issue.number, title: issue.title, labels: issue.labelNames });
348
+ const branchName =
349
+ branch ||
350
+ deriveBranchNameFromIssue(
351
+ { number: issue.number, title: issue.title, labels: issue.labelNames },
352
+ { mode: config.mode, developer },
353
+ );
354
+
355
+ const shouldCreateWorktree = !noWorktree && issuesConfig.autoWorktree;
356
+ let preflighted = null;
357
+ if (shouldCreateWorktree) {
358
+ preflighted = preflightTaskWorktree(repoRoot, config, {
359
+ branch: branchName,
360
+ path: worktreePath,
361
+ base,
362
+ baseProvided: Boolean(base),
363
+ });
364
+ }
365
+
366
+ mutateIssueClaim({
367
+ repoSlug,
368
+ number: issue.number,
369
+ currentUser: me,
370
+ existingLabels: issue.labelNames,
371
+ branchLabel: branchName,
372
+ targetsDescription: shouldCreateWorktree
373
+ ? `- Repository: \`${resolvedRepoName}\``
374
+ : "- Mode: issue claim only (`--no-worktree`)",
375
+ issuesConfig,
376
+ dryRun,
377
+ cwd: repoRoot,
378
+ });
379
+
380
+ const worktree = shouldCreateWorktree
381
+ ? createTaskWorktree(
382
+ repoRoot,
383
+ config,
384
+ {
385
+ branch: branchName,
386
+ path: worktreePath,
387
+ base,
388
+ baseProvided: Boolean(base),
389
+ skipPostCreate,
390
+ dryRun,
391
+ captureOutput,
392
+ },
393
+ preflighted,
394
+ )
395
+ : null;
396
+
397
+ return {
398
+ ref: resolvedRef,
399
+ repo: resolvedRepoName,
400
+ repoSlug,
401
+ number: issue.number,
402
+ url: issue.url,
403
+ claimedBy: me,
404
+ branchSpec,
405
+ branch: branchName,
406
+ dryRun,
407
+ worktree,
408
+ };
409
+ }
410
+
411
+ export function reviewIssue({
412
+ repoSlug,
413
+ repoName,
414
+ number,
415
+ ref,
416
+ summary,
417
+ commit = "",
418
+ pr = "",
419
+ checks = "",
420
+ risks = "",
421
+ integrationBranch = "main",
422
+ issuesConfig = DEFAULT_ISSUES_CONFIG,
423
+ dryRun = false,
424
+ cwd = process.cwd(),
425
+ }) {
426
+ const resolvedRepoName = repoName || repoSlug.split("/")[1] || repoSlug;
427
+ const resolvedRef = ref || `${resolvedRepoName}#${number}`;
428
+ if (!String(summary ?? "").trim()) failIssue('Missing `--summary "..."` for issue review.');
429
+
430
+ const inProgressLabel = issuesConfig?.inProgressLabel || DEFAULT_ISSUES_CONFIG.inProgressLabel;
431
+ const inReviewLabel = issuesConfig?.inReviewLabel || DEFAULT_ISSUES_CONFIG.inReviewLabel;
432
+ const blockedLabel = issuesConfig?.blockedLabel || DEFAULT_ISSUES_CONFIG.blockedLabel;
433
+
434
+ const raw = ghRun(["issue", "view", String(number), "-R", repoSlug, "--json", "labels,url"], { cwd });
435
+ const issue = JSON.parse(raw);
436
+ const existingLabels = new Set((issue.labels ?? []).map((l) => l.name));
437
+
438
+ ensureWorkflowLabels(repoSlug, [inReviewLabel], { dryRun, cwd, issuesConfig });
439
+
440
+ const lines = ["### Ready for Review", "", String(summary).trim(), ""];
441
+ if (commit) lines.push(`- **Commit**: \`${commit}\``);
442
+ if (pr) lines.push(`- **PR**: ${pr}`);
443
+ if (checks) lines.push(`- **Verification**: ${checks}`);
444
+ if (risks) lines.push(`- **Residual risk / notes**: ${risks}`);
445
+ lines.push(
446
+ `- **Next**: Will be closed once integrated into \`${integrationBranch}\` (with \`Closes #${number}\`) or after manual verification.`,
447
+ );
448
+
449
+ if (!dryRun) {
450
+ const editArgs = ["issue", "edit", String(number), "-R", repoSlug, "--add-label", inReviewLabel];
451
+ if (existingLabels.has(inProgressLabel)) editArgs.push("--remove-label", inProgressLabel);
452
+ if (existingLabels.has(blockedLabel)) editArgs.push("--remove-label", blockedLabel);
453
+ ghRun(editArgs, { cwd });
454
+ ghRun(["issue", "comment", String(number), "-R", repoSlug, "--body-file", "-"], {
455
+ input: `${lines.join("\n")}\n`,
456
+ cwd,
457
+ });
458
+ }
459
+
460
+ return { ref: resolvedRef, url: issue.url, status: inReviewLabel, commit: commit || null, pr: pr || null, dryRun };
461
+ }
462
+
463
+ export function releaseIssue({
464
+ repoSlug,
465
+ repoName,
466
+ number,
467
+ ref,
468
+ blocked = false,
469
+ reason = "",
470
+ issuesConfig = DEFAULT_ISSUES_CONFIG,
471
+ dryRun = false,
472
+ cwd = process.cwd(),
473
+ }) {
474
+ const resolvedRepoName = repoName || repoSlug.split("/")[1] || repoSlug;
475
+ const resolvedRef = ref || `${resolvedRepoName}#${number}`;
476
+ const inProgressLabel = issuesConfig?.inProgressLabel || DEFAULT_ISSUES_CONFIG.inProgressLabel;
477
+ const blockedLabel = issuesConfig?.blockedLabel || DEFAULT_ISSUES_CONFIG.blockedLabel;
478
+
479
+ const raw = ghRun(["issue", "view", String(number), "-R", repoSlug, "--json", "labels,assignees,url"], { cwd });
480
+ const issue = JSON.parse(raw);
481
+ const existingLabels = new Set((issue.labels ?? []).map((l) => l.name));
482
+ const me = getCurrentGitHubUser(cwd);
483
+
484
+ if (blocked) ensureWorkflowLabels(repoSlug, [blockedLabel], { dryRun, cwd, issuesConfig });
485
+
486
+ const commentBody = [
487
+ blocked ? `Marked blocked and released by @${me}.` : `Released claim by @${me}.`,
488
+ reason ? `\nReason: ${reason}` : "",
489
+ ].join("");
490
+
491
+ if (!dryRun) {
492
+ const editArgs = ["issue", "edit", String(number), "-R", repoSlug];
493
+ if ((issue.assignees ?? []).some((a) => a.login === me)) editArgs.push("--remove-assignee", me);
494
+ if (existingLabels.has(inProgressLabel)) editArgs.push("--remove-label", inProgressLabel);
495
+ if (blocked) editArgs.push("--add-label", blockedLabel);
496
+ if (editArgs.length > 5) ghRun(editArgs, { cwd });
497
+ ghRun(["issue", "comment", String(number), "-R", repoSlug, "--body-file", "-"], { input: commentBody, cwd });
498
+ }
499
+
500
+ return { ref: resolvedRef, url: issue.url, releasedBy: me, blocked: Boolean(blocked), reason: reason || null, dryRun };
501
+ }
502
+
503
+ export function syncIssueLabels({
504
+ repoSlug,
505
+ repoName,
506
+ issuesConfig = DEFAULT_ISSUES_CONFIG,
507
+ dryRun = false,
508
+ cwd = process.cwd(),
509
+ }) {
510
+ const resolvedRepoName = repoName || repoSlug.split("/")[1] || repoSlug;
511
+ const defs = buildWorkflowLabels(issuesConfig);
512
+ if (!dryRun) {
513
+ for (const label of defs) {
514
+ ghRun(
515
+ ["label", "create", label.name, "-R", repoSlug, "--color", label.color, "--description", label.description, "--force"],
516
+ { cwd },
517
+ );
518
+ }
519
+ }
520
+ return { repo: resolvedRepoName, repoSlug, labels: defs.map((l) => l.name) };
521
+ }