gh board-row mutations
This commit is contained in:
@@ -36,7 +36,7 @@ CLI 可以从 `master` 快速演进,但必须兼容 `deploy.json` 固定的 CI
|
||||
- `gh issue update <number> --mode replace|append --body-file <file>` 是正文更新主入口,`edit` 保留为兼容别名。`replace` 用文件正文替换现有 body;`append` 先读取当前 body,再按 UTF-8 文件字节追加,保留真实换行、反引号和 Markdown 表格。更新默认拒绝字面量 `null`、空白正文和过短正文;只有真实需要写短正文时才允许显式加 `--allow-short-body`,返回 JSON 会报告该风险。#20 总看板和指挥简报类 issue 是长期 body-only issue,`--body-profile auto` 会按 issue number 自动启用 #20/#24 legacy guard:#20 必须包含 `## 看板(OPEN)`,#24 legacy 指挥简报必须包含 `## 常驻观察与长期建议`。显式 `--body-profile commander-brief` 不再固定 #24;#24 仍兼容,标题为 `YYYY-MM-DD 指挥简报(北京时间)` 或既有正文首行/关键 heading 表明为每日滚动指挥简报的 issue 也合法,并仍必须包含 `## 常驻观察与长期建议`。对非简报 issue 显式使用 `commander-brief` 会结构化失败为 `profile-issue-mismatch`。`--dry-run` 不 PATCH GitHub,输出新正文长度、SHA、关键标题检查结果、字面量 `\n`、反引号、Markdown 表格和 shell 污染信号;若环境里有 `GH_TOKEN` 或 `GITHUB_TOKEN`,dry-run 还会只读抓取旧正文长度、SHA 和 `updatedAt` 作为更新前对照。正式写入可带 `--expect-updated-at <updated_at>` 或 `--expect-body-sha <sha256>`,CLI 会先读当前 issue,匹配后才 PATCH,防止旧缓存覆盖新正文。
|
||||
- `gh issue edit 24 --body-file <file> --notify-claudeqq-brief-diff [--dry-run]` 是 legacy #24 指挥简报的通知入口。正式执行会先读取 GitHub 上 #24 旧正文并通过 #24 body profile guard,再从 `--body-file` 读取新正文;随后先 PATCH issue 主体,再把本次新增的 `## 更新 YYYY-MM-DD HH:MM 北京时间` 段落发送给 ClaudeQQ,ClaudeQQ 失败不会回滚 issue 正文,失败只体现在返回 JSON 的 `claudeqq.ok=false` 和结构化 `degradedReason`。每日滚动简报 issue 可用普通 `gh issue update <number> --body-profile commander-brief --dry-run` 和并发 guard 更新,但此通知 helper 仍只支持 #24。带通知 flag 的 `--dry-run` 不 PATCH、不发送;它按新正文做发送预览,并在输出中标明非 dry-run 才会读取旧正文做可靠 diff。默认 ClaudeQQ 目标是私聊 `645275593`,默认 base URL 是 UniDesk 受控入口 `http://backend-core:8080/api/microservices/claudeqq/proxy`,可用 `UNIDESK_COMMANDER_BRIEF_CLAUDEQQ_ENABLED`、`UNIDESK_COMMANDER_BRIEF_CLAUDEQQ_BASE_URL`、`UNIDESK_COMMANDER_BRIEF_CLAUDEQQ_TARGET_TYPE`、`UNIDESK_COMMANDER_BRIEF_CLAUDEQQ_USER_ID`、`UNIDESK_COMMANDER_BRIEF_CLAUDEQQ_GROUP_ID` 和 `UNIDESK_COMMANDER_BRIEF_CLAUDEQQ_TIMEOUT_MS` 覆盖。
|
||||
- `gh issue board-audit [--repo owner/name] [--board-issue 20] [--limit N] [--known-meta-issue N[,N...]] [--ignore-issue N[,N...]] [--dry-run]` 是 #20 长期总看板只读覆盖审计入口,默认 repo 为 `pikasTech/unidesk`、board issue 为 `20`、输出 JSON 且不 PATCH/POST/DELETE GitHub。它读取 board body、GitHub open issue 列表和 closed issue 列表,对比 OPEN/CLOSED Markdown 表格并输出 `missingOpenIssues`、`closedInOpenRows`、`missingClosedRows`、`openInClosedRows`、`rowValidationWarnings`、`ignoredIssues` 和 `recommendedActions`。当表格里存在 Issue 列时,row.issueNumber 优先取 Issue cell 中第一个指向 `/issues/<N>` 的 Markdown link,找不到时取开头的 `#N`;同一 Issue cell 里主引用后面的标题说明引用(例如 `#20 总看板`、`基于 #4`)不触发 `multiple-issue-references`。没有 Issue 列的旧表格仍回退到整行 issue 提取,并保留多 issue 引用告警。`相关 Code Queue 任务`/`relatedTask` 列允许 `—`、`-`、`n/a`、`无任务` 等无关联任务占位表示 closed 历史/治理项没有 Code Queue task;这个放宽不适用于 branch、acceptance 或 progress。默认把 #20 和 #24 作为 `known-meta` 治理/简报 issue 忽略;需要扩展治理项用 `--known-meta-issue`,临时排除业务 issue 用 `--ignore-issue`。指挥官发现总看板可能漏行时,应先跑 board audit 获取结构化结果,再决定是否人工编辑 #20,而不是只靠 grep。
|
||||
- `gh issue board-row list --board-issue 20 [--state open|closed|all] [--dry-run]`、`gh issue board-row get <issueNumber> --board-issue 20` 和 `gh issue board-row update <issueNumber> --board-issue 20 --field progress|status|validation|branch|tasks|focus --value <text> [--dry-run] [--expect-updated-at ts|--expect-body-sha sha256]` 是 #20 看板表格单行结构化入口。list/get 复用 board-audit parser,只读返回 row、cells、fields、section、lineNumber、bodySha 和 rowValidationWarnings。update 只替换命中的一行里一个单元格,返回 old/new row、old/new body SHA、body guard、request plan 和 parser 结果;默认没有并发期望时即使不写 `--dry-run` 也只做 dry-run,正式 PATCH 必须带 `--expect-body-sha` 或 `--expect-updated-at`。字段映射固定为:`branch` -> Branch,`progress` -> 进度,`status`/`validation` -> 验收状态,`tasks` -> 相关 Code Queue 任务,`focus` -> 当前关注点。单元格值中的 Markdown 表格管道会转义为 `\|`,真实换行会折叠为空格,避免新增字面量 `\n` 污染。`gh issue board-row move|delete` 第一阶段结构化返回 `unsupported-command`,因为 OPEN/CLOSED 表间移动和删行还需要明确插入位置、重复行和归档策略。
|
||||
- `gh issue board-row list --board-issue 20 [--state open|closed|all] [--dry-run]`、`gh issue board-row get <issueNumber> --board-issue 20` 和 `gh issue board-row update <issueNumber> --board-issue 20 --field progress|status|validation|branch|tasks|focus --value <text> [--dry-run] [--expect-updated-at ts|--expect-body-sha sha256]` 是 #20 看板表格单行结构化入口。list/get 复用 board-audit parser,只读返回 row、cells、fields、section、lineNumber、bodySha 和 rowValidationWarnings。update 只替换命中的一行里一个单元格,返回 old/new row、old/new body SHA、body guard、request plan 和 parser 结果;默认没有并发期望时即使不写 `--dry-run` 也只做 dry-run,正式 PATCH 必须带 `--expect-body-sha` 或 `--expect-updated-at`。字段映射固定为:`branch` -> Branch,`progress` -> 进度,`status`/`validation` -> 验收状态,`tasks` -> 相关 Code Queue 任务,`focus` -> 当前关注点。单元格值中的 Markdown 表格管道会转义为 `\|`,真实换行会折叠为空格,避免新增字面量 `\n` 污染。`gh issue board-row add <issueNumber> --board-issue 20 --section open|closed --row-file <file> [--dry-run] [--expect-body-sha|--expect-updated-at]`、`move <issueNumber> --board-issue 20 --to open|closed [--status OPEN|CLOSED] [--dry-run] [--expect-body-sha|--expect-updated-at]` 和 `delete <issueNumber> --board-issue 20 [--dry-run] [--expect-body-sha|--expect-updated-at]` 是 row-scoped #20 结构化写入口。add 校验一行 `--row-file` 的 Issue 列、列数和 GitHub 状态列与目标 section 一致;move 允许跨 OPEN/CLOSED 表迁移并在需要时同步 GitHub 状态列;delete 仅删除匹配行。三者默认 dry-run,非 dry-run 必须带 `--expect-body-sha` 或 `--expect-updated-at`,并返回 old/new row、body SHA、line/section 计划和 parser 结果。
|
||||
- `gh issue scan-escape [--repo owner/name] [--limit N] [--dry-run]` 只读扫描 issue 主体和 comments 中的字面量 `\n`、可疑 `\t`、shell newline escape、escaped backtick、ANSI escape 字符串、短 body、blank body 和 null body。输出固定 JSON,`findings` 会带 `bodyKind=issue-body|comment-body`、`issueNumber`、`issueId`、`commentId`、`lineNumber`、`column`、`kind`、`snippet` 和 `classification=suspected-pollution|explanatory-mention|risk`,用于区分说明性提到 `\n` 和疑似污染;`cleanupSuggestions` 只给 dry-run 清理建议、body/comment 定位和 diff-like preview,不 PATCH、不 DELETE、不真实清理历史 comment。`gh issue cleanup-plan` 是同一只读能力的别名,默认 `dryRun=true`。`gh pr list|read|view [--json ...]` 提供 REST 列表和详情,PR 字段白名单是 `body,title,state,number,url,author,head,base,draft,createdAt,updatedAt`。`gh pr create --title <title> --body-file <file>|--body <text> --base <branch> --head <branch> [--draft] [--dry-run]`、`gh pr update <number> --mode replace|append --body-file <file>|--body <text> [--title ...] [--dry-run]`、`gh pr comment create <number> --body-file <file>|--body <text> [--dry-run]`、`gh pr comment delete <commentId> [--dry-run]`、`gh pr close|reopen <number> [--dry-run]` 是 PR CRUD/生命周期入口。`pr create --dry-run` 只输出 planned operation,不访问 GitHub;非 dry-run 创建前会校验 repo、base、head 和 compare ahead 状态,成功时返回 PR number/url。`pr update --mode append` 会先读取当前 PR body 再追加正文。`gh pr delete <number>` 和 `gh pr merge` 本阶段不开放,始终结构化返回 `unsupported-command`;PR 生命周期删除语义请使用 `close`。
|
||||
- PR dry-run/probe 的最小手动序列是:`bun scripts/cli.ts gh auth status --repo pikasTech/unidesk` 只读检查 token 来源、GitHub REST egress、repo 可见性和 issue read;`bun scripts/cli.ts gh pr create --repo pikasTech/unidesk --title <title> --body-file <file> --base master --head <head> --dry-run` 检查创建计划;`bun scripts/cli.ts gh pr list --repo pikasTech/unidesk --limit 5 --json number,title,state,url,head,base` 和 `bun scripts/cli.ts gh pr read <number> --repo pikasTech/unidesk --json body,title,state,head,base` 做只读 PR 观察;`bun scripts/cli.ts gh pr comment <number> --repo pikasTech/unidesk --body-file <file> --dry-run` 检查评论计划;`bun scripts/cli.ts gh pr merge <number> --repo pikasTech/unidesk` 必须失败并返回结构化 `unsupported-command`。Code Queue runner 可用 `bun scripts/code-queue-pr-preflight-example.ts --repo pikasTech/unidesk --base master --head <head> --comment-pr <number>` 一次性跑只读 auth status 与 PR create/comment dry-run;该脚本不得输出 token 值,也不会创建、评论或 merge PR。
|
||||
- `ci install|status|run|publish-backend-core|publish-user-service|run-dev-e2e|logs` 管理 D601 原生 k3s 上的 Tekton CI。`run` 手动创建每 commit 检查和 Code Queue 只读性能门禁;`publish-backend-core` 与 `publish-user-service` 从 pushed Git commit 构建并发布 `127.0.0.1:5000/unidesk/<service>:<commit>` commit-pinned artifacts,输出 `artifactSummary`(含 `serviceId`、`sourceCommit`、`sourceRepo`、`dockerfile`、`imageRef`、`tag`、`digest`、`digestRef`),但不部署生产;`run-dev-e2e` 的 Git 控制 runner、短 launcher、host fetch 边界、临时 smoke namespace 和 no-CD 规则只在 `docs/reference/dev-ci-runner.md` 定义;Tekton CI 通用规则见 `docs/reference/ci.md`。
|
||||
|
||||
@@ -86,30 +86,29 @@ async function startMockGitHub(): Promise<{ baseUrl: string; requests: MockReque
|
||||
created_at: "2026-05-20T00:00:00Z",
|
||||
updated_at: "2026-05-20T01:00:00Z",
|
||||
};
|
||||
const boardIssue = {
|
||||
...issue,
|
||||
body: [
|
||||
"# Code Queue",
|
||||
"",
|
||||
"## 看板(OPEN)",
|
||||
"",
|
||||
"| Issue | Branch | 验收状态 | 相关 Code Queue 任务 | 当前关注点 | 进度 |",
|
||||
"| --- | --- | --- | --- | --- | --- |",
|
||||
"| #20 | master | meta | governance | 关注:#19 / #26 / #30 | active |",
|
||||
"| #35 | master | pass | cq-35 | 当前关注点:#19 / #26 / #30 | doing |",
|
||||
"| [#45](https://github.com/pikasTech/unidesk/issues/45) #20 总看板缺少自动覆盖审计 | master | pass | cq-45 | 复核:#20 / #24 | doing |",
|
||||
"| #40 | — | — | — | 复核:#19 / #26 / #30 | — |",
|
||||
"",
|
||||
"## 看板(CLOSED)",
|
||||
"",
|
||||
"| Issue | Branch | 验收状态 | 相关 Code Queue 任务 | 当前关注点 | 进度 |",
|
||||
"| --- | --- | --- | --- | --- | --- |",
|
||||
"| #24 | master | meta | brief | 常驻:#24 / #20 | active |",
|
||||
"| [#18](https://github.com/pikasTech/unidesk/issues/18) 基于 #4 评审结论修复 | master | pass | — | 历史治理归档 | done |",
|
||||
"| #36 | master | pending | cq-36 | 复核:#35 / #40 | done |",
|
||||
"",
|
||||
].join("\n"),
|
||||
};
|
||||
const boardIssueBodyInitial = [
|
||||
"# Code Queue",
|
||||
"",
|
||||
"## 看板(OPEN)",
|
||||
"",
|
||||
"| Issue | GitHub 状态 | Branch | 验收状态 | 相关 Code Queue 任务 | 当前关注点 | 进度 |",
|
||||
"| --- | --- | --- | --- | --- | --- | --- |",
|
||||
"| #20 | OPEN | master | meta | governance | 关注:#19 / #26 / #30 | active |",
|
||||
"| #35 | OPEN | master | pass | cq-35 | 当前关注点:#19 / #26 / #30 | doing |",
|
||||
"| [#45](https://github.com/pikasTech/unidesk/issues/45) #20 总看板缺少自动覆盖审计 | OPEN | master | pass | cq-45 | 复核:#20 / #24 | doing |",
|
||||
"| #40 | OPEN | — | — | — | 复核:#19 / #26 / #30 | — |",
|
||||
"",
|
||||
"## 看板(CLOSED)",
|
||||
"",
|
||||
"| Issue | GitHub 状态 | Branch | 验收状态 | 相关 Code Queue 任务 | 当前关注点 | 进度 |",
|
||||
"| --- | --- | --- | --- | --- | --- | --- |",
|
||||
"| #24 | CLOSED | master | meta | brief | 常驻:#24 / #20 | active |",
|
||||
"| [#18](https://github.com/pikasTech/unidesk/issues/18) 基于 #4 评审结论修复 | CLOSED | master | pass | — | 历史治理归档 | done |",
|
||||
"| #36 | CLOSED | master | pending | cq-36 | 复核:#35 / #40 | done |",
|
||||
"",
|
||||
].join("\n");
|
||||
let boardIssueBody = boardIssueBodyInitial;
|
||||
let boardIssueUpdatedAt = "2026-05-20T01:00:00Z";
|
||||
const legacyBoardIssue = {
|
||||
...issue,
|
||||
id: 2600,
|
||||
@@ -256,19 +255,19 @@ async function startMockGitHub(): Promise<{ baseUrl: string; requests: MockReque
|
||||
updated_at: "2026-05-20T04:40:00Z",
|
||||
},
|
||||
];
|
||||
const boardOpenIssues = [
|
||||
const boardOpenIssues = (): JsonRecord[] => [
|
||||
{
|
||||
id: 2000,
|
||||
number: 20,
|
||||
title: "长期总看板",
|
||||
body: boardIssue.body,
|
||||
body: boardIssueBody,
|
||||
state: "open",
|
||||
html_url: "https://github.com/pikasTech/unidesk/issues/20",
|
||||
comments: 1,
|
||||
user: { login: "tester" },
|
||||
labels: [],
|
||||
created_at: "2026-05-20T00:00:00Z",
|
||||
updated_at: "2026-05-20T01:00:00Z",
|
||||
updated_at: boardIssueUpdatedAt,
|
||||
},
|
||||
issueList[0],
|
||||
issueList[1],
|
||||
@@ -394,7 +393,7 @@ async function startMockGitHub(): Promise<{ baseUrl: string; requests: MockReque
|
||||
const body = await collectBody(req);
|
||||
requests.push({ method: req.method ?? "", url: req.url ?? "", body });
|
||||
if (req.method === "GET" && req.url === "/repos/pikasTech/unidesk/issues/20") {
|
||||
sendJson(res, 200, boardIssue);
|
||||
sendJson(res, 200, { ...issue, body: boardIssueBody, updated_at: boardIssueUpdatedAt });
|
||||
return;
|
||||
}
|
||||
if (req.method === "GET" && req.url === "/repos/pikasTech/unidesk/issues/24") {
|
||||
@@ -438,7 +437,7 @@ async function startMockGitHub(): Promise<{ baseUrl: string; requests: MockReque
|
||||
return;
|
||||
}
|
||||
if (req.method === "GET" && req.url === "/repos/pikasTech/unidesk/issues?state=open&per_page=100") {
|
||||
sendJson(res, 200, boardOpenIssues);
|
||||
sendJson(res, 200, boardOpenIssues());
|
||||
return;
|
||||
}
|
||||
if (req.method === "GET" && req.url === "/repos/pikasTech/unidesk/issues?state=open&per_page=60") {
|
||||
@@ -461,7 +460,9 @@ async function startMockGitHub(): Promise<{ baseUrl: string; requests: MockReque
|
||||
}
|
||||
if (req.method === "PATCH" && req.url === "/repos/pikasTech/unidesk/issues/20") {
|
||||
const parsed = JSON.parse(body) as JsonRecord;
|
||||
sendJson(res, 200, { ...issue, body: String(parsed.body ?? issue.body), updated_at: "2026-05-20T01:05:00Z" });
|
||||
boardIssueBody = String(parsed.body ?? boardIssueBody);
|
||||
boardIssueUpdatedAt = "2026-05-20T01:05:00Z";
|
||||
sendJson(res, 200, { ...issue, body: boardIssueBody, updated_at: boardIssueUpdatedAt });
|
||||
return;
|
||||
}
|
||||
if (req.method === "POST" && req.url === "/repos/pikasTech/unidesk/issues/20/comments") {
|
||||
@@ -525,9 +526,13 @@ export async function runGhCliIssueGuardContract(): Promise<JsonRecord> {
|
||||
assertCondition(usage.some((line) => line.includes("gh issue view")), "gh help should list issue view", { usage });
|
||||
assertCondition(usage.some((line) => line.includes("gh issue board-row list")), "gh help should list board-row list", { usage });
|
||||
assertCondition(usage.some((line) => line.includes("gh issue board-row update")), "gh help should list board-row update", { usage });
|
||||
assertCondition(usage.some((line) => line.includes("gh issue board-row add")), "gh help should list board-row add", { usage });
|
||||
assertCondition(usage.some((line) => line.includes("gh issue board-row move")), "gh help should list board-row move", { usage });
|
||||
assertCondition(usage.some((line) => line.includes("gh issue board-row delete")), "gh help should list board-row delete", { usage });
|
||||
assertCondition(notes.some((line) => line.includes("canonical read path")), "gh help should state issue read is canonical", { notes });
|
||||
assertCondition(notes.some((line) => line.includes("compatibility alias")), "gh help should state issue view is alias", { notes });
|
||||
assertCondition(notes.some((line) => line.includes("board-row update changes one table cell")), "gh help should describe board-row update safety", { notes });
|
||||
assertCondition(notes.some((line) => line.includes("board-row add/move/delete are row-scoped")), "gh help should describe board-row row mutation safety", { notes });
|
||||
|
||||
const mock = await startMockGitHub();
|
||||
const tmp = mkdtempSync(join(tmpdir(), "unidesk-gh-issue-guard-"));
|
||||
@@ -633,6 +638,8 @@ export async function runGhCliIssueGuardContract(): Promise<JsonRecord> {
|
||||
const boardRowListData = dataOf(boardRowList.json ?? {});
|
||||
assertCondition(boardRowListData.command === "issue board-row list" && boardRowListData.readOnly === true && boardRowListData.dryRun === true, "board-row list should be read-only", boardRowListData);
|
||||
assertCondition(boardRowListData.state === "open" && boardRowListData.count === 4, "board-row list should filter OPEN rows", boardRowListData);
|
||||
const boardRowListBoardIssue = boardRowListData.boardIssue as JsonRecord;
|
||||
assertCondition(typeof boardRowListBoardIssue.bodySha === "string" && String(boardRowListBoardIssue.bodySha).length === 64, "board-row list should expose board body sha", boardRowListBoardIssue);
|
||||
const boardRowListRows = boardRowListData.rows as JsonRecord[];
|
||||
assertCondition(Array.isArray(boardRowListRows) && boardRowListRows.some((row) => row.issueNumber === 45), "board-row list should use primary markdown issue link row keys", boardRowListRows);
|
||||
const listWriteCount = mock.requests.slice(boardRowListRequestCountBefore).filter((request) => request.method === "PATCH" || request.method === "DELETE" || request.method === "POST").length;
|
||||
@@ -644,6 +651,7 @@ export async function runGhCliIssueGuardContract(): Promise<JsonRecord> {
|
||||
const boardRowGetRow = boardRowGetData.row as JsonRecord;
|
||||
const boardRowGetFields = boardRowGetRow.fields as JsonRecord;
|
||||
assertCondition(boardRowGetRow.issueNumber === 35 && boardRowGetRow.section === "open", "board-row get should return the target row", boardRowGetData);
|
||||
assertCondition(Array.isArray(boardRowGetRow.cells) && boardRowGetRow.cells[1] === "OPEN", "board-row get should expose the GitHub status column", boardRowGetRow);
|
||||
assertCondition(boardRowGetFields.branch === "master" && boardRowGetFields.status === "pass" && boardRowGetFields.validation === "pass" && boardRowGetFields.tasks === "cq-35" && String(boardRowGetFields.focus ?? "").includes("当前关注点"), "board-row get should expose canonical field aliases", boardRowGetFields);
|
||||
|
||||
const boardRowDryRunRequestCountBefore = mock.requests.length;
|
||||
@@ -652,8 +660,8 @@ export async function runGhCliIssueGuardContract(): Promise<JsonRecord> {
|
||||
const boardRowDryRunData = dataOf(boardRowDryRun.json ?? {});
|
||||
assertCondition(boardRowDryRunData.command === "issue board-row update" && boardRowDryRunData.dryRun === true && boardRowDryRunData.planned === true, "board-row update should default to dry-run", boardRowDryRunData);
|
||||
const dryRunUpdate = boardRowDryRunData.update as JsonRecord;
|
||||
assertCondition(dryRunUpdate.oldRow === "| #35 | master | pass | cq-35 | 当前关注点:#19 / #26 / #30 | doing |", "board-row dry-run should expose old row", dryRunUpdate);
|
||||
assertCondition(dryRunUpdate.newRow === "| #35 | master | pass | cq-35 | 复核 A \\| B second line | doing |", "board-row dry-run should escape table pipes and fold cell newlines", dryRunUpdate);
|
||||
assertCondition(dryRunUpdate.oldRow === "| #35 | OPEN | master | pass | cq-35 | 当前关注点:#19 / #26 / #30 | doing |", "board-row dry-run should expose old row", dryRunUpdate);
|
||||
assertCondition(dryRunUpdate.newRow === "| #35 | OPEN | master | pass | cq-35 | 复核 A \\| B second line | doing |", "board-row dry-run should escape table pipes and fold cell newlines", dryRunUpdate);
|
||||
const dryRunGuard = boardRowDryRunData.guard as JsonRecord;
|
||||
assertCondition(dryRunGuard.ok === true, "board-row dry-run should include body guard result", dryRunGuard);
|
||||
const dryRunSafety = boardRowDryRunData.bodyOnlySafety as JsonRecord;
|
||||
@@ -668,7 +676,7 @@ export async function runGhCliIssueGuardContract(): Promise<JsonRecord> {
|
||||
assertCondition(boardRowValidationDryRun.status === 0, "board-row update validation alias should dry-run", boardRowValidationDryRun.json ?? { stdout: boardRowValidationDryRun.stdout, stderr: boardRowValidationDryRun.stderr });
|
||||
const boardRowValidationData = dataOf(boardRowValidationDryRun.json ?? {});
|
||||
const validationUpdate = boardRowValidationData.update as JsonRecord;
|
||||
assertCondition(validationUpdate.targetColumn === "acceptance" && validationUpdate.targetColumnIndex === 2, "validation field should map to 验收状态/acceptance column", validationUpdate);
|
||||
assertCondition(validationUpdate.targetColumn === "acceptance" && validationUpdate.targetColumnIndex === 3, "validation field should map to 验收状态/acceptance column", validationUpdate);
|
||||
|
||||
const boardRowPollutedValue = await runCli(["gh", "issue", "board-row", "update", "35", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--field", "focus", "--value", "bad\\nvalue", "--dry-run"], env);
|
||||
assertCondition(boardRowPollutedValue.status !== 0, "board-row update should reject literal backslash-n values", boardRowPollutedValue.json ?? { stdout: boardRowPollutedValue.stdout, stderr: boardRowPollutedValue.stderr });
|
||||
@@ -687,13 +695,160 @@ export async function runGhCliIssueGuardContract(): Promise<JsonRecord> {
|
||||
const boardRowPatchPayload = JSON.parse(boardRowPatchRequests[0]?.body ?? "{}") as JsonRecord;
|
||||
assertCondition(typeof boardRowPatchPayload.body === "string", "board-row patch payload should carry body string", boardRowPatchPayload);
|
||||
const patchedBody = String(boardRowPatchPayload.body ?? "");
|
||||
assertCondition(patchedBody.includes("| #35 | master | pass | cq-35 | 复核 A \\| B second line | doing |"), "board-row patch payload should contain escaped updated row", patchedBody);
|
||||
assertCondition(patchedBody.includes("| #35 | OPEN | master | pass | cq-35 | 复核 A \\| B second line | doing |"), "board-row patch payload should contain escaped updated row", patchedBody);
|
||||
assertCondition(!patchedBody.includes("\\n"), "board-row patch payload should not add literal backslash-n pollution to markdown body", patchedBody);
|
||||
|
||||
const boardRowMove = await runCli(["gh", "issue", "board-row", "move", "35", "--repo", "pikasTech/unidesk", "--board-issue", "20"], env);
|
||||
assertCondition(boardRowMove.status !== 0, "board-row move should be structured unsupported in first phase", boardRowMove.json ?? { stdout: boardRowMove.stdout, stderr: boardRowMove.stderr });
|
||||
const boardRowMoveData = failedDataOf(boardRowMove.json ?? {});
|
||||
assertCondition(boardRowMoveData.degradedReason === "unsupported-command" && boardRowMoveData.runnerDisposition === "business-failed", "board-row move unsupported should be structured business failure", boardRowMoveData);
|
||||
const addRowFile = join(tmp, "board-add-row.md");
|
||||
writeFileSync(addRowFile, "| #91 | OPEN | master | pass | cq-91 | 新增 open row | doing |\n", "utf8");
|
||||
const noGuardRowFile = join(tmp, "board-add-row-no-guard.md");
|
||||
writeFileSync(noGuardRowFile, "| #94 | OPEN | master | pass | cq-94 | no guard row | doing |\n", "utf8");
|
||||
const mismatchRowFile = join(tmp, "board-add-row-mismatch.md");
|
||||
writeFileSync(mismatchRowFile, "| #92 | OPEN | master | pass | cq-92 | too few |\n", "utf8");
|
||||
const statusMismatchRowFile = join(tmp, "board-add-row-status-mismatch.md");
|
||||
writeFileSync(statusMismatchRowFile, "| #93 | OPEN | master | pass | cq-93 | status mismatch row | doing |\n", "utf8");
|
||||
|
||||
const boardRowAddNoGuardRequestCountBefore = mock.requests.length;
|
||||
const boardRowAddNoGuard = await runCli(["gh", "issue", "board-row", "add", "94", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--section", "open", "--row-file", noGuardRowFile], env);
|
||||
assertCondition(boardRowAddNoGuard.status === 0, "board-row add without guard should stay on the dry-run path", boardRowAddNoGuard.json ?? { stdout: boardRowAddNoGuard.stdout, stderr: boardRowAddNoGuard.stderr });
|
||||
const boardRowAddNoGuardData = dataOf(boardRowAddNoGuard.json ?? {});
|
||||
assertCondition(boardRowAddNoGuardData.dryRun === true && boardRowAddNoGuardData.planned === true, "board-row add without guard should not PATCH GitHub", boardRowAddNoGuardData);
|
||||
const boardRowAddNoGuardPlan = boardRowAddNoGuardData.add as JsonRecord;
|
||||
assertCondition(boardRowAddNoGuardPlan.section === "open" && boardRowAddNoGuardPlan.insertAfterLine > 0, "board-row add without guard should still return an insertion plan", boardRowAddNoGuardPlan);
|
||||
const boardRowAddNoGuardWriteCount = mock.requests.slice(boardRowAddNoGuardRequestCountBefore).filter((request) => request.method === "PATCH").length;
|
||||
assertCondition(boardRowAddNoGuardWriteCount === 0, "board-row add without guard must not PATCH GitHub", { requests: mock.requests.slice(boardRowAddNoGuardRequestCountBefore) });
|
||||
|
||||
const boardRowAddDryRunRequestCountBefore = mock.requests.length;
|
||||
const boardRowAddDryRun = await runCli(["gh", "issue", "board-row", "add", "91", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--section", "open", "--row-file", addRowFile, "--dry-run"], env);
|
||||
assertCondition(boardRowAddDryRun.status === 0, "board-row add dry-run should succeed", boardRowAddDryRun.json ?? { stdout: boardRowAddDryRun.stdout, stderr: boardRowAddDryRun.stderr });
|
||||
const boardRowAddDryRunData = dataOf(boardRowAddDryRun.json ?? {});
|
||||
assertCondition(boardRowAddDryRunData.command === "issue board-row add" && boardRowAddDryRunData.dryRun === true && boardRowAddDryRunData.planned === true, "board-row add should default to dry-run", boardRowAddDryRunData);
|
||||
const boardRowAddDryRunPlan = boardRowAddDryRunData.add as JsonRecord;
|
||||
assertCondition(boardRowAddDryRunPlan.section === "open" && boardRowAddDryRunPlan.validation.actualStatus === "OPEN", "board-row add dry-run should validate the target section and GitHub status", boardRowAddDryRunPlan);
|
||||
const boardRowAddDryRunPatchCount = mock.requests.slice(boardRowAddDryRunRequestCountBefore).filter((request) => request.method === "PATCH").length;
|
||||
assertCondition(boardRowAddDryRunPatchCount === 0, "board-row add dry-run must not PATCH GitHub", { requests: mock.requests.slice(boardRowAddDryRunRequestCountBefore) });
|
||||
|
||||
const boardRowListBeforeAdd = await runCli(["gh", "issue", "board-row", "list", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--state", "open"], env);
|
||||
assertCondition(boardRowListBeforeAdd.status === 0, "board-row list before add should succeed", boardRowListBeforeAdd.json ?? { stdout: boardRowListBeforeAdd.stdout });
|
||||
const boardRowListBeforeAddData = dataOf(boardRowListBeforeAdd.json ?? {});
|
||||
const boardRowAddBoardSha = String((boardRowListBeforeAddData.boardIssue as JsonRecord).bodySha ?? "");
|
||||
const boardRowAddRequestCountBefore = mock.requests.length;
|
||||
const boardRowAdd = await runCli(["gh", "issue", "board-row", "add", "91", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--section", "open", "--row-file", addRowFile, "--expect-body-sha", boardRowAddBoardSha], env);
|
||||
assertCondition(boardRowAdd.status === 0, "board-row add with expect body sha should PATCH", boardRowAdd.json ?? { stdout: boardRowAdd.stdout, stderr: boardRowAdd.stderr });
|
||||
const boardRowAddData = dataOf(boardRowAdd.json ?? {});
|
||||
assertCondition(boardRowAddData.dryRun === false && boardRowAddData.rest === true, "board-row add should report a real REST update", boardRowAddData);
|
||||
const boardRowAddPlan = boardRowAddData.add as JsonRecord;
|
||||
assertCondition(boardRowAddPlan.section === "open" && boardRowAddPlan.validation.expectedStatus === "OPEN" && boardRowAddPlan.validation.actualStatus === "OPEN", "board-row add should validate section/status alignment", boardRowAddPlan);
|
||||
const boardRowAddRequests = mock.requests.slice(boardRowAddRequestCountBefore).filter((request) => request.method === "PATCH" && request.url === "/repos/pikasTech/unidesk/issues/20");
|
||||
assertCondition(boardRowAddRequests.length === 1, "board-row add should send exactly one PATCH", { requests: mock.requests.slice(boardRowAddRequestCountBefore) });
|
||||
const boardRowAddPayload = JSON.parse(boardRowAddRequests[0]?.body ?? "{}") as JsonRecord;
|
||||
assertCondition(String(boardRowAddPayload.body ?? "").includes("| #91 | OPEN | master | pass | cq-91 | 新增 open row | doing |"), "board-row add payload should contain the inserted row", boardRowAddPayload);
|
||||
|
||||
const boardRowGetAdded = await runCli(["gh", "issue", "board-row", "get", "91", "--repo", "pikasTech/unidesk", "--board-issue", "20"], env);
|
||||
assertCondition(boardRowGetAdded.status === 0, "board-row get should find the added row", boardRowGetAdded.json ?? { stdout: boardRowGetAdded.stdout, stderr: boardRowGetAdded.stderr });
|
||||
const boardRowGetAddedData = dataOf(boardRowGetAdded.json ?? {});
|
||||
const boardRowGetAddedRow = boardRowGetAddedData.row as JsonRecord;
|
||||
assertCondition(boardRowGetAddedRow.issueNumber === 91 && boardRowGetAddedRow.section === "open", "board-row get should see the added issue in OPEN", boardRowGetAddedData);
|
||||
const boardRowListAfterAdd = await runCli(["gh", "issue", "board-row", "list", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--state", "open"], env);
|
||||
assertCondition(boardRowListAfterAdd.status === 0, "board-row list after add should succeed", boardRowListAfterAdd.json ?? { stdout: boardRowListAfterAdd.stdout });
|
||||
const boardRowListAfterAddData = dataOf(boardRowListAfterAdd.json ?? {});
|
||||
const boardRowListAfterAddRows = boardRowListAfterAddData.rows as JsonRecord[];
|
||||
assertCondition(boardRowListAfterAddData.count === 5 && boardRowListAfterAddRows.some((row) => row.issueNumber === 91), "board-row add should make the new row visible to the parser", boardRowListAfterAddData);
|
||||
|
||||
const boardRowAddDuplicate = await runCli(["gh", "issue", "board-row", "add", "91", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--section", "open", "--row-file", addRowFile], env);
|
||||
assertCondition(boardRowAddDuplicate.status !== 0, "duplicate board-row add should fail structurally", boardRowAddDuplicate.json ?? { stdout: boardRowAddDuplicate.stdout, stderr: boardRowAddDuplicate.stderr });
|
||||
const boardRowAddDuplicateData = failedDataOf(boardRowAddDuplicate.json ?? {});
|
||||
assertCondition(String((boardRowAddDuplicateData.details as JsonRecord).message ?? "").includes("already exists"), "duplicate add should report duplicate row", boardRowAddDuplicateData);
|
||||
|
||||
const boardRowAddMismatch = await runCli(["gh", "issue", "board-row", "add", "92", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--section", "open", "--row-file", mismatchRowFile], env);
|
||||
assertCondition(boardRowAddMismatch.status !== 0, "column count mismatch should fail structurally", boardRowAddMismatch.json ?? { stdout: boardRowAddMismatch.stdout, stderr: boardRowAddMismatch.stderr });
|
||||
const boardRowAddMismatchData = failedDataOf(boardRowAddMismatch.json ?? {});
|
||||
assertCondition(String((boardRowAddMismatchData.details as JsonRecord).message ?? "").includes("column count"), "column mismatch should be reported", boardRowAddMismatchData);
|
||||
|
||||
const boardRowAddStatusConflict = await runCli(["gh", "issue", "board-row", "add", "93", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--section", "closed", "--row-file", statusMismatchRowFile], env);
|
||||
assertCondition(boardRowAddStatusConflict.status !== 0, "section/status mismatch should fail structurally", boardRowAddStatusConflict.json ?? { stdout: boardRowAddStatusConflict.stdout, stderr: boardRowAddStatusConflict.stderr });
|
||||
const boardRowAddStatusConflictData = failedDataOf(boardRowAddStatusConflict.json ?? {});
|
||||
assertCondition(String((boardRowAddStatusConflictData.details as JsonRecord).message ?? "").includes("GitHub 状态"), "section/status mismatch should be reported", boardRowAddStatusConflictData);
|
||||
|
||||
const boardRowDeleteNoGuardRequestCountBefore = mock.requests.length;
|
||||
const boardRowDeleteNoGuard = await runCli(["gh", "issue", "board-row", "delete", "35", "--repo", "pikasTech/unidesk", "--board-issue", "20"], env);
|
||||
assertCondition(boardRowDeleteNoGuard.status === 0, "board-row delete without guard should stay on the dry-run path", boardRowDeleteNoGuard.json ?? { stdout: boardRowDeleteNoGuard.stdout, stderr: boardRowDeleteNoGuard.stderr });
|
||||
const boardRowDeleteNoGuardData = dataOf(boardRowDeleteNoGuard.json ?? {});
|
||||
assertCondition(boardRowDeleteNoGuardData.dryRun === true && boardRowDeleteNoGuardData.planned === true, "board-row delete without guard should not PATCH GitHub", boardRowDeleteNoGuardData);
|
||||
const boardRowDeleteNoGuardPlan = boardRowDeleteNoGuardData.delete as JsonRecord;
|
||||
assertCondition(boardRowDeleteNoGuardPlan.section === "open" && Number(boardRowDeleteNoGuardPlan.lineNumber ?? 0) > 0, "board-row delete without guard should return the matched row plan", boardRowDeleteNoGuardPlan);
|
||||
const boardRowDeleteNoGuardLinePlan = boardRowDeleteNoGuardPlan.linePlan as JsonRecord;
|
||||
assertCondition(boardRowDeleteNoGuardLinePlan.action === "remove" && Number(boardRowDeleteNoGuardLinePlan.lineNumber ?? 0) > 0, "board-row delete should expose a line plan", boardRowDeleteNoGuardLinePlan);
|
||||
const boardRowDeleteNoGuardWriteCount = mock.requests.slice(boardRowDeleteNoGuardRequestCountBefore).filter((request) => request.method === "PATCH").length;
|
||||
assertCondition(boardRowDeleteNoGuardWriteCount === 0, "board-row delete without guard must not PATCH GitHub", { requests: mock.requests.slice(boardRowDeleteNoGuardRequestCountBefore) });
|
||||
|
||||
const boardRowDeleteStale = await runCli(["gh", "issue", "board-row", "delete", "91", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--expect-body-sha", boardRowAddBoardSha], env);
|
||||
assertCondition(boardRowDeleteStale.status !== 0, "stale board-row delete should fail structurally", boardRowDeleteStale.json ?? { stdout: boardRowDeleteStale.stdout, stderr: boardRowDeleteStale.stderr });
|
||||
const boardRowDeleteStaleData = failedDataOf(boardRowDeleteStale.json ?? {});
|
||||
assertCondition(boardRowDeleteStaleData.degradedReason === "validation-failed", "stale board-row delete should be validation-failed", boardRowDeleteStaleData);
|
||||
|
||||
const boardRowDeleteBoardSha = String((boardRowListAfterAddData.boardIssue as JsonRecord).bodySha ?? "");
|
||||
const boardRowDeleteRequestCountBefore = mock.requests.length;
|
||||
const boardRowDelete = await runCli(["gh", "issue", "board-row", "delete", "91", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--expect-body-sha", boardRowDeleteBoardSha], env);
|
||||
assertCondition(boardRowDelete.status === 0, "board-row delete with expect body sha should PATCH", boardRowDelete.json ?? { stdout: boardRowDelete.stdout, stderr: boardRowDelete.stderr });
|
||||
const boardRowDeleteData = dataOf(boardRowDelete.json ?? {});
|
||||
assertCondition(boardRowDeleteData.dryRun === false && boardRowDeleteData.rest === true, "board-row delete should report a real REST update", boardRowDeleteData);
|
||||
const boardRowDeleteRequests = mock.requests.slice(boardRowDeleteRequestCountBefore).filter((request) => request.method === "PATCH" && request.url === "/repos/pikasTech/unidesk/issues/20");
|
||||
assertCondition(boardRowDeleteRequests.length === 1, "board-row delete should send exactly one PATCH", { requests: mock.requests.slice(boardRowDeleteRequestCountBefore) });
|
||||
const boardRowDeletePayload = JSON.parse(boardRowDeleteRequests[0]?.body ?? "{}") as JsonRecord;
|
||||
assertCondition(!String(boardRowDeletePayload.body ?? "").includes("#91"), "board-row delete payload should remove the row", boardRowDeletePayload);
|
||||
const boardRowGetDeleted = await runCli(["gh", "issue", "board-row", "get", "91", "--repo", "pikasTech/unidesk", "--board-issue", "20"], env);
|
||||
assertCondition(boardRowGetDeleted.status !== 0, "deleted board-row should no longer be discoverable", boardRowGetDeleted.json ?? { stdout: boardRowGetDeleted.stdout, stderr: boardRowGetDeleted.stderr });
|
||||
const boardRowGetDeletedData = failedDataOf(boardRowGetDeleted.json ?? {});
|
||||
assertCondition(String((boardRowGetDeletedData.details as JsonRecord).message ?? "").includes("was not found"), "deleted board-row should report missing row", boardRowGetDeletedData);
|
||||
const boardRowListAfterDelete = await runCli(["gh", "issue", "board-row", "list", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--state", "open"], env);
|
||||
assertCondition(boardRowListAfterDelete.status === 0, "board-row list after delete should succeed", boardRowListAfterDelete.json ?? { stdout: boardRowListAfterDelete.stdout });
|
||||
const boardRowListAfterDeleteData = dataOf(boardRowListAfterDelete.json ?? {});
|
||||
const boardRowListAfterDeleteNumbers = (boardRowListAfterDeleteData.rows as JsonRecord[]).map((row) => row.issueNumber);
|
||||
assertCondition(boardRowListAfterDeleteData.count === 4 && JSON.stringify(boardRowListAfterDeleteNumbers) === JSON.stringify([20, 35, 45, 40]), "board-row delete should preserve other row order", boardRowListAfterDeleteData);
|
||||
|
||||
const boardRowMoveDryRun = await runCli(["gh", "issue", "board-row", "move", "35", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--to", "closed", "--status", "CLOSED", "--dry-run"], env);
|
||||
assertCondition(boardRowMoveDryRun.status === 0, "board-row move dry-run should succeed", boardRowMoveDryRun.json ?? { stdout: boardRowMoveDryRun.stdout, stderr: boardRowMoveDryRun.stderr });
|
||||
const boardRowMoveDryRunData = dataOf(boardRowMoveDryRun.json ?? {});
|
||||
assertCondition(boardRowMoveDryRunData.command === "issue board-row move" && boardRowMoveDryRunData.dryRun === true && boardRowMoveDryRunData.planned === true, "board-row move should default to dry-run", boardRowMoveDryRunData);
|
||||
const boardRowMoveDryRunPlan = boardRowMoveDryRunData.move as JsonRecord;
|
||||
assertCondition(boardRowMoveDryRunPlan.from === "open" && boardRowMoveDryRunPlan.to === "closed" && boardRowMoveDryRunPlan.status.requested === "CLOSED", "board-row move dry-run should plan the cross-section migration", boardRowMoveDryRunPlan);
|
||||
|
||||
const boardRowMoveConflict = await runCli(["gh", "issue", "board-row", "move", "35", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--to", "closed", "--status", "OPEN", "--dry-run"], env);
|
||||
assertCondition(boardRowMoveConflict.status !== 0, "board-row move status conflict should fail structurally", boardRowMoveConflict.json ?? { stdout: boardRowMoveConflict.stdout, stderr: boardRowMoveConflict.stderr });
|
||||
const boardRowMoveConflictData = failedDataOf(boardRowMoveConflict.json ?? {});
|
||||
assertCondition(String((boardRowMoveConflictData.details as JsonRecord).message ?? "").includes("conflicts with --to"), "board-row move should report status conflict", boardRowMoveConflictData);
|
||||
|
||||
const boardRowListBeforeMove = await runCli(["gh", "issue", "board-row", "list", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--state", "open"], env);
|
||||
assertCondition(boardRowListBeforeMove.status === 0, "board-row list before move should succeed", boardRowListBeforeMove.json ?? { stdout: boardRowListBeforeMove.stdout });
|
||||
const boardRowMoveBoardSha = String((dataOf(boardRowListBeforeMove.json ?? {}).boardIssue as JsonRecord).bodySha ?? "");
|
||||
const boardRowMoveRequestCountBefore = mock.requests.length;
|
||||
const boardRowMove = await runCli(["gh", "issue", "board-row", "move", "35", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--to", "closed", "--status", "CLOSED", "--expect-body-sha", boardRowMoveBoardSha], env);
|
||||
assertCondition(boardRowMove.status === 0, "board-row move with expect body sha should PATCH", boardRowMove.json ?? { stdout: boardRowMove.stdout, stderr: boardRowMove.stderr });
|
||||
const boardRowMoveData = dataOf(boardRowMove.json ?? {});
|
||||
assertCondition(boardRowMoveData.dryRun === false && boardRowMoveData.rest === true, "board-row move should report a real REST update", boardRowMoveData);
|
||||
const boardRowMovePlan = boardRowMoveData.move as JsonRecord;
|
||||
assertCondition(boardRowMovePlan.from === "open" && boardRowMovePlan.to === "closed" && boardRowMovePlan.status.new === "CLOSED", "board-row move should update the GitHub status column", boardRowMovePlan);
|
||||
const boardRowMoveLinePlan = boardRowMovePlan.linePlan as JsonRecord;
|
||||
const boardRowMoveSectionPlan = boardRowMovePlan.sectionPlan as JsonRecord;
|
||||
assertCondition(boardRowMoveLinePlan.action === "move" && Number(boardRowMoveLinePlan.sourceLineNumber ?? 0) > 0 && Number(boardRowMoveLinePlan.newLineNumber ?? 0) > 0, "board-row move should expose a line plan", boardRowMoveLinePlan);
|
||||
assertCondition(boardRowMoveSectionPlan.from === "open" && boardRowMoveSectionPlan.to === "closed", "board-row move should expose a section plan", boardRowMoveSectionPlan);
|
||||
const boardRowMoveRequests = mock.requests.slice(boardRowMoveRequestCountBefore).filter((request) => request.method === "PATCH" && request.url === "/repos/pikasTech/unidesk/issues/20");
|
||||
assertCondition(boardRowMoveRequests.length === 1, "board-row move should send exactly one PATCH", { requests: mock.requests.slice(boardRowMoveRequestCountBefore) });
|
||||
const boardRowMovePayload = JSON.parse(boardRowMoveRequests[0]?.body ?? "{}") as JsonRecord;
|
||||
assertCondition(String(boardRowMovePayload.body ?? "").includes("| #35 | CLOSED | master | pass | cq-35 |"), "board-row move payload should move the row into CLOSED", boardRowMovePayload);
|
||||
const boardRowOpenAfterMove = await runCli(["gh", "issue", "board-row", "list", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--state", "open"], env);
|
||||
const boardRowOpenAfterMoveData = dataOf(boardRowOpenAfterMove.json ?? {});
|
||||
assertCondition(boardRowOpenAfterMoveData.count === 3 && !(boardRowOpenAfterMoveData.rows as JsonRecord[]).some((row) => row.issueNumber === 35), "board-row move should remove the row from OPEN", boardRowOpenAfterMoveData);
|
||||
const boardRowClosedAfterMove = await runCli(["gh", "issue", "board-row", "list", "--repo", "pikasTech/unidesk", "--board-issue", "20", "--state", "closed"], env);
|
||||
const boardRowClosedAfterMoveData = dataOf(boardRowClosedAfterMove.json ?? {});
|
||||
const boardRowClosedAfterMoveRows = boardRowClosedAfterMoveData.rows as JsonRecord[];
|
||||
assertCondition(boardRowClosedAfterMoveData.count === 4 && boardRowClosedAfterMoveRows.some((row) => row.issueNumber === 35), "board-row move should add the row to CLOSED", boardRowClosedAfterMoveData);
|
||||
const boardRowMoved = await runCli(["gh", "issue", "board-row", "get", "35", "--repo", "pikasTech/unidesk", "--board-issue", "20"], env);
|
||||
const boardRowMovedData = dataOf(boardRowMoved.json ?? {});
|
||||
const boardRowMovedRow = boardRowMovedData.row as JsonRecord;
|
||||
assertCondition(boardRowMovedRow.section === "closed" && Array.isArray(boardRowMovedRow.cells) && boardRowMovedRow.cells[1] === "CLOSED", "board-row move should preserve row fields while updating GitHub status", boardRowMovedRow);
|
||||
const boardRowMoveTargetSectionPlan = boardRowMovePlan.sectionPlan as JsonRecord;
|
||||
assertCondition(boardRowMoveTargetSectionPlan.targetHeading === "## 看板(CLOSED)", "board-row move should point to the CLOSED section heading", boardRowMoveTargetSectionPlan);
|
||||
|
||||
const badListField = await runCli(["gh", "issue", "list", "--repo", "pikasTech/unidesk", "--json", "number,body"], env);
|
||||
assertCondition(badListField.status !== 0, "issue list unsupported --json field should fail", badListField.json ?? { stdout: badListField.stdout });
|
||||
@@ -919,10 +1074,11 @@ export async function runGhCliIssueGuardContract(): Promise<JsonRecord> {
|
||||
"issue cleanup-plan remains dry-run with body/comment cleanup suggestions",
|
||||
"issue board-audit reports missing open rows, closed/open section mismatches, missing closed rows, meta ignores, and row validation warnings without writes",
|
||||
"issue board-row list/get expose parsed #20 rows without writes",
|
||||
"issue board-row add/delete without guard stay on dry-run and do not PATCH",
|
||||
"issue board-row update defaults to dry-run, reports old/new row, body SHA, guard result, and does not introduce literal backslash-n",
|
||||
"issue board-row update rejects literal backslash-n cell values",
|
||||
"issue board-row update escapes markdown table pipes and performs guarded PATCH with --expect-body-sha",
|
||||
"issue board-row move is structurally unsupported in the first phase",
|
||||
"issue board-row move is supported, defaults to dry-run, and can migrate OPEN rows into CLOSED",
|
||||
"issue create dry-run parses repeated/comma labels and exposes request plan",
|
||||
"issue create sends labels through REST and preserves GitHub validation errors for missing labels",
|
||||
"issue list unsupported fields and states fail structurally",
|
||||
|
||||
+724
-54
@@ -21,6 +21,8 @@ const ISSUE_LIST_JSON_FIELDS = ["number", "title", "state", "url", "updatedAt",
|
||||
const PR_JSON_FIELDS = ["body", "title", "state", "number", "url", "author", "head", "base", "draft", "createdAt", "updatedAt"] as const;
|
||||
const ISSUE_LIST_STATES = ["open", "closed", "all"] as const;
|
||||
const BODY_UPDATE_MODES = ["replace", "append"] as const;
|
||||
const BOARD_MUTATION_SECTIONS = ["open", "closed"] as const;
|
||||
const BOARD_GITHUB_STATUSES = ["OPEN", "CLOSED"] as const;
|
||||
const MIN_SAFE_BODY_SCAN_CHARS = MIN_SAFE_ISSUE_BODY_CHARS;
|
||||
const ISSUE_SCAN_MAX_FINDINGS = 60;
|
||||
const ISSUE_BODY_PROFILES = {
|
||||
@@ -44,6 +46,8 @@ type IssueListJsonField = typeof ISSUE_LIST_JSON_FIELDS[number];
|
||||
type PrJsonField = typeof PR_JSON_FIELDS[number];
|
||||
type IssueListState = typeof ISSUE_LIST_STATES[number];
|
||||
type BodyUpdateMode = typeof BODY_UPDATE_MODES[number];
|
||||
type BoardMutationSection = typeof BOARD_MUTATION_SECTIONS[number];
|
||||
type BoardGithubStatus = typeof BOARD_GITHUB_STATUSES[number];
|
||||
type IssueBodyProfileName = keyof typeof ISSUE_BODY_PROFILES;
|
||||
type IssueBodyProfileOption = "auto" | IssueBodyProfileName;
|
||||
type EscapeFindingClassification = "suspected-pollution" | "explanatory-mention" | "risk";
|
||||
@@ -52,7 +56,7 @@ type EscapeBodyKind = "issue-body" | "comment-body";
|
||||
type CleanupSuggestionAction = "rewrite-issue-body-with-body-file" | "review-comment-manually" | "review-body-length" | "no-cleanup-needed";
|
||||
type BoardSectionKind = "open" | "closed";
|
||||
type BoardRequiredColumn = typeof BOARD_AUDIT_REQUIRED_COLUMNS[number];
|
||||
type BoardColumnKind = BoardRequiredColumn | "focus";
|
||||
type BoardColumnKind = BoardRequiredColumn | "focus" | "githubStatus";
|
||||
type BoardRowField = typeof BOARD_ROW_FIELDS[number];
|
||||
|
||||
type GitHubDegradedReason =
|
||||
@@ -244,6 +248,12 @@ interface BoardRowUpdatePlanResult {
|
||||
newBody: string;
|
||||
}
|
||||
|
||||
interface BoardRowMutationPlanResult {
|
||||
ok: true;
|
||||
plan: Record<string, unknown>;
|
||||
newBody: string;
|
||||
}
|
||||
|
||||
interface GitHubCommandResult {
|
||||
ok: boolean;
|
||||
repo: string;
|
||||
@@ -290,6 +300,10 @@ interface GitHubOptions {
|
||||
bodyProfile: IssueBodyProfileOption;
|
||||
boardRowField?: BoardRowField;
|
||||
boardRowValue?: string;
|
||||
boardRowFile?: string;
|
||||
boardSection?: BoardMutationSection;
|
||||
boardMoveTo?: BoardMutationSection;
|
||||
boardGithubStatus?: BoardGithubStatus;
|
||||
}
|
||||
|
||||
interface IssueProfileValidationContext {
|
||||
@@ -515,6 +529,18 @@ function parseIssueBodyProfile(args: string[]): IssueBodyProfileOption {
|
||||
throw new Error(`unsupported --body-profile ${raw}; supported profiles: auto, code-queue-board, commander-brief`);
|
||||
}
|
||||
|
||||
function parseBoardMutationSection(args: string[], name: "--section" | "--to"): BoardMutationSection | undefined {
|
||||
const raw = optionValue(args, name);
|
||||
if (raw === undefined) return undefined;
|
||||
return validateEnumValue(name, raw, BOARD_MUTATION_SECTIONS);
|
||||
}
|
||||
|
||||
function parseBoardGithubStatus(args: string[]): BoardGithubStatus | undefined {
|
||||
const raw = optionValue(args, "--status");
|
||||
if (raw === undefined) return undefined;
|
||||
return validateEnumValue("--status", raw, BOARD_GITHUB_STATUSES);
|
||||
}
|
||||
|
||||
function parseBoardRowField(args: string[]): BoardRowField | undefined {
|
||||
const raw = optionValue(args, "--field");
|
||||
if (raw === undefined) return undefined;
|
||||
@@ -522,7 +548,7 @@ function parseBoardRowField(args: string[]): BoardRowField | undefined {
|
||||
}
|
||||
|
||||
function validateKnownOptions(args: string[]): void {
|
||||
const valueOptions = new Set(["--repo", "--limit", "--board-issue", "--known-meta-issue", "--ignore-issue", "--title", "--body-file", "--body", "--base", "--head", "--json", "--state", "--mode", "--expect-updated-at", "--expect-body-sha", "--body-profile", "--label", "--field", "--value"]);
|
||||
const valueOptions = new Set(["--repo", "--limit", "--board-issue", "--known-meta-issue", "--ignore-issue", "--title", "--body-file", "--body", "--base", "--head", "--json", "--state", "--mode", "--expect-updated-at", "--expect-body-sha", "--body-profile", "--label", "--field", "--value", "--section", "--to", "--status", "--row-file"]);
|
||||
const flagOptions = new Set(["--dry-run", "--draft", "--notify-claudeqq-brief-diff", "--allow-short-body"]);
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
const arg = args[index];
|
||||
@@ -566,6 +592,10 @@ function parseOptions(args: string[]): GitHubOptions {
|
||||
bodyProfile: parseIssueBodyProfile(args),
|
||||
boardRowField: parseBoardRowField(args),
|
||||
boardRowValue: optionValue(args, "--value"),
|
||||
boardRowFile: optionValue(args, "--row-file"),
|
||||
boardSection: parseBoardMutationSection(args, "--section"),
|
||||
boardMoveTo: parseBoardMutationSection(args, "--to"),
|
||||
boardGithubStatus: parseBoardGithubStatus(args),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1279,6 +1309,7 @@ function boardHeaderColumnKind(header: string): BoardColumnKind | null {
|
||||
if (["branch", "分支", "目标分支", "工作分支"].includes(normalized)) return "branch";
|
||||
if (["acceptance", "验收", "验收状态", "验收结果", "验收标准"].includes(normalized)) return "acceptance";
|
||||
if (["relatedtask", "task", "codequeue", "codequeuetask", "相关任务", "任务", "codequeue任务", "cq任务", "相关codequeue任务", "相关codequeuetask"].includes(normalized)) return "relatedTask";
|
||||
if (["githubstatus", "githubstate", "github状态", "githubissue状态", "issuestate", "issue状态", "issuegithub状态", "开闭状态", "openclosed", "openclosed状态"].includes(normalized)) return "githubStatus";
|
||||
if (["focus", "currentfocus", "关注点", "当前关注点", "当前focus"].includes(normalized)) return "focus";
|
||||
if (["progress", "进度", "状态", "当前进度"].includes(normalized)) return "progress";
|
||||
return null;
|
||||
@@ -1390,6 +1421,33 @@ function primaryBoardIssueNumberFromIssueCell(issueCell: string | undefined): nu
|
||||
return null;
|
||||
}
|
||||
|
||||
function boardRowFromCells(section: BoardTableSection, raw: string, cells: string[], lineNumber: number): BoardTableRow {
|
||||
const columnMap = boardRequiredColumnIndexMap(section.headers);
|
||||
const issueColumnIndex = boardIssueColumnIndex(section.headers);
|
||||
const issueCell = issueColumnIndex === null ? undefined : cells[issueColumnIndex];
|
||||
const primaryIssueNumber = issueColumnIndex === null ? null : primaryBoardIssueNumberFromIssueCell(issueCell);
|
||||
const issueNumbers = issueColumnIndex === null
|
||||
? extractIssueNumbers(raw)
|
||||
: (primaryIssueNumber === null ? extractIssueNumbers(issueCell ?? "") : [primaryIssueNumber]);
|
||||
const columns: Partial<Record<BoardRequiredColumn, string>> = {};
|
||||
for (const column of BOARD_AUDIT_REQUIRED_COLUMNS) {
|
||||
const cellIndex = columnMap.get(column);
|
||||
if (cellIndex !== undefined) columns[column] = cells[cellIndex] ?? "";
|
||||
}
|
||||
return {
|
||||
section: section.kind,
|
||||
lineNumber,
|
||||
raw,
|
||||
cells,
|
||||
issueNumbers,
|
||||
issueNumber: issueNumbers[0] ?? null,
|
||||
title: issueColumnIndex === null
|
||||
? (cells.find((cell) => extractIssueNumbers(cell).length > 0) ?? cells[0] ?? null)
|
||||
: (issueCell ?? cells[0] ?? null),
|
||||
columns,
|
||||
};
|
||||
}
|
||||
|
||||
function normalizedBoardCellPlaceholder(value: string): { spaced: string; compact: string } {
|
||||
const spaced = stripMarkdownInline(value).toLowerCase().replace(/\s+/g, " ").trim();
|
||||
return { spaced, compact: spaced.replace(/\s+/g, "") };
|
||||
@@ -1447,37 +1505,19 @@ function parseBoardTables(body: string): { sections: BoardTableSection[]; warnin
|
||||
const separator = lines[index + 1];
|
||||
if (separator === undefined || !separator.trim().startsWith("|") || !isMarkdownTableSeparator(separator)) continue;
|
||||
const headers = markdownCells(lines[index]);
|
||||
const columnMap = boardRequiredColumnIndexMap(headers);
|
||||
const issueColumnIndex = boardIssueColumnIndex(headers);
|
||||
const rows: BoardTableRow[] = [];
|
||||
let rowIndex = index + 2;
|
||||
while (rowIndex < lines.length && lines[rowIndex].trim().startsWith("|")) {
|
||||
if (!isMarkdownTableSeparator(lines[rowIndex])) {
|
||||
const cells = markdownCells(lines[rowIndex]);
|
||||
const issueCell = issueColumnIndex === null ? undefined : cells[issueColumnIndex];
|
||||
const primaryIssueNumber = issueColumnIndex === null ? null : primaryBoardIssueNumberFromIssueCell(issueCell);
|
||||
const issueNumbers = issueColumnIndex === null
|
||||
? extractIssueNumbers(lines[rowIndex])
|
||||
: (primaryIssueNumber === null ? extractIssueNumbers(issueCell ?? "") : [primaryIssueNumber]);
|
||||
const columns: Partial<Record<BoardRequiredColumn, string>> = {};
|
||||
for (const column of BOARD_AUDIT_REQUIRED_COLUMNS) {
|
||||
const cellIndex = columnMap.get(column);
|
||||
if (cellIndex !== undefined) columns[column] = cells[cellIndex] ?? "";
|
||||
}
|
||||
const row: BoardTableRow = {
|
||||
section: currentKind,
|
||||
lineNumber: rowIndex + 1,
|
||||
raw: lines[rowIndex],
|
||||
const row = boardRowFromCells(
|
||||
{ kind: currentKind, heading: currentHeading, headingLine: currentHeadingLine, headerLine: index + 1, headers, rows: [] },
|
||||
lines[rowIndex],
|
||||
cells,
|
||||
issueNumbers,
|
||||
issueNumber: issueNumbers[0] ?? null,
|
||||
title: issueColumnIndex === null
|
||||
? (cells.find((cell) => extractIssueNumbers(cell).length > 0) ?? cells[0] ?? null)
|
||||
: (issueCell ?? cells[0] ?? null),
|
||||
columns,
|
||||
};
|
||||
rowIndex + 1,
|
||||
);
|
||||
rows.push(row);
|
||||
if (issueNumbers.length === 0) {
|
||||
if (row.issueNumbers.length === 0) {
|
||||
warnings.push({
|
||||
issueNumber: null,
|
||||
section: currentKind,
|
||||
@@ -1487,19 +1527,19 @@ function parseBoardTables(body: string): { sections: BoardTableSection[]; warnin
|
||||
rowPreview: preview(row.raw),
|
||||
});
|
||||
}
|
||||
if (issueNumbers.length > 1) {
|
||||
if (row.issueNumbers.length > 1) {
|
||||
warnings.push({
|
||||
issueNumber: row.issueNumber,
|
||||
section: currentKind,
|
||||
lineNumber: row.lineNumber,
|
||||
kind: "multiple-issue-references",
|
||||
message: issueColumnIndex === null
|
||||
message: boardIssueColumnIndex(headers) === null
|
||||
? "Board table row contains multiple issue references; audit uses the first number as the row key."
|
||||
: "Board table row contains multiple issue references in the Issue column; audit uses the first number as the row key.",
|
||||
rowPreview: preview(row.raw),
|
||||
});
|
||||
}
|
||||
const missingColumns = BOARD_AUDIT_REQUIRED_COLUMNS.filter((column) => !cellHasMeaningfulValue(columns[column], column));
|
||||
const missingColumns = BOARD_AUDIT_REQUIRED_COLUMNS.filter((column) => !cellHasMeaningfulValue(row.columns[column], column));
|
||||
if (missingColumns.length > 0) {
|
||||
warnings.push({
|
||||
issueNumber: row.issueNumber,
|
||||
@@ -1508,7 +1548,7 @@ function parseBoardTables(body: string): { sections: BoardTableSection[]; warnin
|
||||
kind: "missing-required-columns",
|
||||
message: "Board table row is missing branch, acceptance, related task, or progress information.",
|
||||
missingColumns,
|
||||
columns,
|
||||
columns: row.columns,
|
||||
rowPreview: preview(row.raw),
|
||||
});
|
||||
}
|
||||
@@ -1577,6 +1617,35 @@ function boardRowsForState(sections: BoardTableSection[], state: IssueListState)
|
||||
.flatMap((section) => section.rows.map((row) => ({ section, row })));
|
||||
}
|
||||
|
||||
function boardDuplicateRows(
|
||||
sections: BoardTableSection[],
|
||||
issueNumber: number,
|
||||
): Array<{ section: BoardTableSection; row: BoardTableRow }> {
|
||||
return boardRowsForState(sections, "all").filter(({ row }) => row.issueNumber === issueNumber);
|
||||
}
|
||||
|
||||
function targetBoardSection(
|
||||
repo: string,
|
||||
sections: BoardTableSection[],
|
||||
kind: BoardMutationSection,
|
||||
commandName: string,
|
||||
): { ok: true; section: BoardTableSection } | GitHubCommandFailure {
|
||||
const matches = sections.filter((section) => section.kind === kind);
|
||||
if (matches.length === 0) {
|
||||
return validationError(commandName, repo, `board ${kind.toUpperCase()} table was not found`, {
|
||||
section: kind,
|
||||
availableSections: sections.map((section) => ({ kind: section.kind, heading: section.heading, headerLine: section.headerLine })),
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
if (matches.length > 1) {
|
||||
return validationError(commandName, repo, `board ${kind.toUpperCase()} table is ambiguous`, {
|
||||
section: kind,
|
||||
matches: matches.map((section) => ({ heading: section.heading, headingLine: section.headingLine, headerLine: section.headerLine })),
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
return { ok: true, section: matches[0] };
|
||||
}
|
||||
|
||||
function findBoardRow(
|
||||
repo: string,
|
||||
sections: BoardTableSection[],
|
||||
@@ -1620,6 +1689,25 @@ function renderMarkdownTableRow(cells: string[]): string {
|
||||
return `| ${cells.map(escapeMarkdownTableCell).join(" | ")} |`;
|
||||
}
|
||||
|
||||
function validateMarkdownTableRowLine(line: string): string | null {
|
||||
if (!line.trim().startsWith("|") || !line.trim().endsWith("|")) return "row-file must contain a Markdown table row starting and ending with |";
|
||||
if (isMarkdownTableSeparator(line)) return "row-file must contain a data row, not a Markdown table separator";
|
||||
return null;
|
||||
}
|
||||
|
||||
function readBoardRowFile(path: string | undefined, command: string): { path: string; raw: string; cells: string[] } {
|
||||
if (path === undefined) throw new Error(`${command} requires --row-file <markdown-row-file>`);
|
||||
if (!existsSync(path)) throw new Error(`row file not found: ${path}`);
|
||||
const normalized = normalizeNewlines(readFileSync(path, "utf8")).trim();
|
||||
if (normalized.length === 0) throw new Error("row-file must contain exactly one non-empty Markdown table row");
|
||||
const lines = normalized.split("\n");
|
||||
if (lines.length !== 1) throw new Error("row-file must contain exactly one Markdown table row");
|
||||
const line = lines[0];
|
||||
const lineError = validateMarkdownTableRowLine(line);
|
||||
if (lineError !== null) throw new Error(lineError);
|
||||
return { path, raw: line, cells: markdownCells(line) };
|
||||
}
|
||||
|
||||
function replaceBoardBodyLine(body: string, lineNumber: number, newLine: string): string {
|
||||
const normalized = normalizeNewlines(body);
|
||||
const lines = normalized.split("\n");
|
||||
@@ -1628,6 +1716,27 @@ function replaceBoardBodyLine(body: string, lineNumber: number, newLine: string)
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function removeBoardBodyLine(body: string, lineNumber: number): string {
|
||||
const normalized = normalizeNewlines(body);
|
||||
const lines = normalized.split("\n");
|
||||
if (lineNumber <= 0 || lineNumber > lines.length) throw new Error(`line ${lineNumber} is outside the board body`);
|
||||
lines.splice(lineNumber - 1, 1);
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function insertBoardBodyLineAfter(body: string, lineNumber: number, newLine: string): string {
|
||||
const normalized = normalizeNewlines(body);
|
||||
const lines = normalized.split("\n");
|
||||
if (lineNumber < 0 || lineNumber > lines.length) throw new Error(`insert line ${lineNumber} is outside the board body`);
|
||||
lines.splice(lineNumber, 0, newLine);
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function boardSectionInsertAfterLine(section: BoardTableSection): number {
|
||||
if (section.rows.length === 0) return section.headerLine + 1;
|
||||
return section.rows[section.rows.length - 1].lineNumber;
|
||||
}
|
||||
|
||||
function boardBodySafetyIssue(repo: string, boardIssueNumber: number, body: string, options: GitHubOptions): GitHubCommandResult | null {
|
||||
const guardOptions: GitHubOptions = { ...options, bodyProfile: boardIssueNumber === CODE_QUEUE_BOARD_TARGET_ISSUE ? "code-queue-board" : options.bodyProfile };
|
||||
return validateIssueBodyGuard(repo, boardIssueNumber, body, guardOptions);
|
||||
@@ -1723,6 +1832,512 @@ function boardRowUpdatePlan(
|
||||
};
|
||||
}
|
||||
|
||||
function expectedBoardGithubStatus(section: BoardMutationSection): BoardGithubStatus {
|
||||
return section === "open" ? "OPEN" : "CLOSED";
|
||||
}
|
||||
|
||||
function normalizeBoardGithubStatusCell(value: string | undefined): BoardGithubStatus | null {
|
||||
const normalized = stripMarkdownInline(value ?? "").toUpperCase().replace(/\s+/g, "");
|
||||
if (normalized === "OPEN") return "OPEN";
|
||||
if (normalized === "CLOSED") return "CLOSED";
|
||||
return null;
|
||||
}
|
||||
|
||||
function boardHeaderShape(headers: string[]): string[] {
|
||||
return headers.map((header) => normalizeBoardHeader(header));
|
||||
}
|
||||
|
||||
function sameBoardHeaderShape(a: string[], b: string[]): boolean {
|
||||
const left = boardHeaderShape(a);
|
||||
const right = boardHeaderShape(b);
|
||||
return left.length === right.length && left.every((value, index) => value === right[index]);
|
||||
}
|
||||
|
||||
function boardRowDuplicateFailure(
|
||||
repo: string,
|
||||
commandName: string,
|
||||
sections: BoardTableSection[],
|
||||
issueNumber: number,
|
||||
): GitHubCommandFailure | null {
|
||||
const duplicates = boardDuplicateRows(sections, issueNumber);
|
||||
if (duplicates.length === 0) return null;
|
||||
return validationError(commandName, repo, `board row for issue #${issueNumber} already exists; refusing duplicate row`, {
|
||||
issueNumber,
|
||||
matches: duplicates.map(({ section, row }) => ({ section: section.kind, lineNumber: row.lineNumber, rowPreview: preview(row.raw) })),
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
|
||||
function boardStatusOptionFailure(
|
||||
repo: string,
|
||||
commandName: string,
|
||||
targetSection: BoardMutationSection,
|
||||
status: BoardGithubStatus | undefined,
|
||||
): GitHubCommandFailure | null {
|
||||
if (status === undefined) return null;
|
||||
const expected = expectedBoardGithubStatus(targetSection);
|
||||
if (status === expected) return null;
|
||||
return validationError(commandName, repo, `--status ${status} conflicts with --to ${targetSection}; expected ${expected}`, {
|
||||
targetSection,
|
||||
status,
|
||||
expectedStatus: expected,
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
|
||||
function boardRowStatusConsistency(
|
||||
repo: string,
|
||||
commandName: string,
|
||||
section: BoardTableSection,
|
||||
row: BoardTableRow,
|
||||
role: "source" | "target",
|
||||
): { ok: true; githubStatusColumnIndex: number; actualStatus: BoardGithubStatus | null; expectedStatus: BoardGithubStatus } | GitHubCommandFailure {
|
||||
const columnMap = boardColumnIndexMap(section.headers);
|
||||
const githubStatusColumnIndex = columnMap.get("githubStatus");
|
||||
if (githubStatusColumnIndex === undefined) {
|
||||
return validationError(commandName, repo, `${role} board table does not contain a GitHub 状态 column`, {
|
||||
section: section.kind,
|
||||
headers: section.headers,
|
||||
lineNumber: row.lineNumber,
|
||||
rowPreview: preview(row.raw),
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
const expectedStatus = expectedBoardGithubStatus(section.kind);
|
||||
const actualStatus = normalizeBoardGithubStatusCell(row.cells[githubStatusColumnIndex]);
|
||||
if (actualStatus !== expectedStatus) {
|
||||
return validationError(commandName, repo, `${role} row GitHub 状态 ${actualStatus ?? "missing"} conflicts with ${section.kind.toUpperCase()} section; expected ${expectedStatus}`, {
|
||||
section: section.kind,
|
||||
lineNumber: row.lineNumber,
|
||||
rowPreview: preview(row.raw),
|
||||
actualStatus,
|
||||
expectedStatus,
|
||||
githubStatusColumnIndex,
|
||||
headers: section.headers,
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
return { ok: true, githubStatusColumnIndex, actualStatus, expectedStatus };
|
||||
}
|
||||
|
||||
function boardRowAddPlan(
|
||||
repo: string,
|
||||
boardIssue: GitHubIssue,
|
||||
issueNumber: number,
|
||||
sectionKind: BoardMutationSection,
|
||||
rowFile: { path: string; raw: string; cells: string[] },
|
||||
parsed: { sections: BoardTableSection[]; warnings: BoardRowValidationWarning[] },
|
||||
): BoardRowMutationPlanResult | GitHubCommandFailure {
|
||||
const commandName = "issue board-row add";
|
||||
const duplicate = boardRowDuplicateFailure(repo, commandName, parsed.sections, issueNumber);
|
||||
if (duplicate !== null) return duplicate;
|
||||
const targetLookup = targetBoardSection(repo, parsed.sections, sectionKind, commandName);
|
||||
if (targetLookup.ok === false) return targetLookup;
|
||||
const target = targetLookup.section;
|
||||
const issueColumnIndex = boardIssueColumnIndex(target.headers);
|
||||
if (issueColumnIndex === null) {
|
||||
return validationError(commandName, repo, "board table does not contain an Issue column required for row-file validation", {
|
||||
boardIssue: boardIssue.number,
|
||||
section: sectionKind,
|
||||
headers: target.headers,
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
const columnMap = boardColumnIndexMap(target.headers);
|
||||
const githubStatusColumnIndex = columnMap.get("githubStatus");
|
||||
if (githubStatusColumnIndex === undefined) {
|
||||
return validationError(commandName, repo, "board table does not contain a GitHub 状态 column required for add section validation", {
|
||||
boardIssue: boardIssue.number,
|
||||
section: sectionKind,
|
||||
headers: target.headers,
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
if (rowFile.cells.length !== target.headers.length) {
|
||||
return validationError(commandName, repo, "row-file column count does not match the target board table header", {
|
||||
boardIssue: boardIssue.number,
|
||||
section: sectionKind,
|
||||
expectedColumns: target.headers.length,
|
||||
actualColumns: rowFile.cells.length,
|
||||
headers: target.headers,
|
||||
rowFile: rowFile.path,
|
||||
rowPreview: preview(rowFile.raw),
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
const row = boardRowFromCells(target, rowFile.raw, rowFile.cells, 0);
|
||||
if (row.issueNumber !== issueNumber) {
|
||||
return validationError(commandName, repo, "row-file Issue column does not match the requested issue number", {
|
||||
issueNumber,
|
||||
issueColumnIndex,
|
||||
issueCell: rowFile.cells[issueColumnIndex] ?? "",
|
||||
detectedIssueNumber: row.issueNumber,
|
||||
rowPreview: preview(rowFile.raw),
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
const expectedStatus = expectedBoardGithubStatus(sectionKind);
|
||||
const actualStatus = normalizeBoardGithubStatusCell(rowFile.cells[githubStatusColumnIndex]);
|
||||
if (actualStatus !== expectedStatus) {
|
||||
return validationError(commandName, repo, "row-file GitHub 状态 column does not match the target section", {
|
||||
issueNumber,
|
||||
section: sectionKind,
|
||||
expectedStatus,
|
||||
actualStatus,
|
||||
statusColumnIndex: githubStatusColumnIndex,
|
||||
statusCell: rowFile.cells[githubStatusColumnIndex] ?? "",
|
||||
rowPreview: preview(rowFile.raw),
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
const oldBody = boardIssue.body ?? "";
|
||||
const insertAfterLine = boardSectionInsertAfterLine(target);
|
||||
let newBody: string;
|
||||
try {
|
||||
newBody = insertBoardBodyLineAfter(oldBody, insertAfterLine, rowFile.raw);
|
||||
} catch (error) {
|
||||
return validationError(commandName, repo, error instanceof Error ? error.message : String(error), {
|
||||
issueNumber,
|
||||
section: sectionKind,
|
||||
insertAfterLine,
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
newBody,
|
||||
plan: {
|
||||
repo,
|
||||
boardIssue: boardIssue.number,
|
||||
issueNumber,
|
||||
action: "add",
|
||||
section: sectionKind,
|
||||
insertAfterLine,
|
||||
rowFile: rowFile.path,
|
||||
newRow: rowFile.raw,
|
||||
newCells: rowFile.cells,
|
||||
row: {
|
||||
old: null,
|
||||
new: boardRowSummary(target, { ...row, lineNumber: insertAfterLine + 1 }),
|
||||
},
|
||||
linePlan: {
|
||||
action: "insert",
|
||||
section: sectionKind,
|
||||
insertAfterLine,
|
||||
newLineNumber: insertAfterLine + 1,
|
||||
},
|
||||
sectionPlan: {
|
||||
kind: sectionKind,
|
||||
heading: target.heading,
|
||||
headerLine: target.headerLine,
|
||||
rowCount: target.rows.length,
|
||||
},
|
||||
validation: {
|
||||
issueColumnIndex,
|
||||
githubStatusColumnIndex,
|
||||
expectedStatus,
|
||||
actualStatus,
|
||||
columnCount: rowFile.cells.length,
|
||||
},
|
||||
body: {
|
||||
oldBodyChars: oldBody.length,
|
||||
oldBodySha: bodySha(oldBody),
|
||||
newBodyChars: newBody.length,
|
||||
newBodySha: bodySha(newBody),
|
||||
changed: oldBody !== newBody,
|
||||
},
|
||||
tableParser: {
|
||||
reused: "parseBoardTables",
|
||||
rowValidationWarnings: parsed.warnings.length,
|
||||
},
|
||||
request: {
|
||||
method: "PATCH",
|
||||
path: `/repos/{owner}/{repo}/issues/${boardIssue.number}`,
|
||||
body: { bodyChars: newBody.length },
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function moveBoardBodyRow(body: string, sourceLineNumber: number, insertAfterLine: number, newLine: string): string {
|
||||
const normalized = normalizeNewlines(body);
|
||||
const lines = normalized.split("\n");
|
||||
if (sourceLineNumber <= 0 || sourceLineNumber > lines.length) throw new Error(`line ${sourceLineNumber} is outside the board body`);
|
||||
if (insertAfterLine < 0 || insertAfterLine > lines.length) throw new Error(`insert line ${insertAfterLine} is outside the board body`);
|
||||
lines.splice(sourceLineNumber - 1, 1);
|
||||
const adjustedInsertAfterLine = sourceLineNumber <= insertAfterLine ? insertAfterLine - 1 : insertAfterLine;
|
||||
lines.splice(adjustedInsertAfterLine, 0, newLine);
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function boardRowMovePlan(
|
||||
repo: string,
|
||||
boardIssue: GitHubIssue,
|
||||
issueNumber: number,
|
||||
targetKind: BoardMutationSection,
|
||||
status: BoardGithubStatus | undefined,
|
||||
parsed: { sections: BoardTableSection[]; warnings: BoardRowValidationWarning[] },
|
||||
): BoardRowMutationPlanResult | GitHubCommandFailure {
|
||||
const commandName = "issue board-row move";
|
||||
const statusFailure = boardStatusOptionFailure(repo, commandName, targetKind, status);
|
||||
if (statusFailure !== null) return statusFailure;
|
||||
const found = findBoardRow(repo, parsed.sections, issueNumber);
|
||||
if (found.ok === false) return { ...found, command: commandName, repo } as GitHubCommandFailure;
|
||||
const sourceConsistency = boardRowStatusConsistency(repo, commandName, found.section, found.row, "source");
|
||||
if (sourceConsistency.ok === false) return sourceConsistency;
|
||||
const targetLookup = targetBoardSection(repo, parsed.sections, targetKind, commandName);
|
||||
if (targetLookup.ok === false) return targetLookup;
|
||||
const target = targetLookup.section;
|
||||
const { section: source, row } = found;
|
||||
if (!sameBoardHeaderShape(source.headers, target.headers)) {
|
||||
return validationError(commandName, repo, "source and target board tables have different headers; refusing to move a raw row across mismatched columns", {
|
||||
issueNumber,
|
||||
source: { section: source.kind, headers: source.headers, headerLine: source.headerLine },
|
||||
target: { section: target.kind, headers: target.headers, headerLine: target.headerLine },
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
if (row.cells.length !== target.headers.length) {
|
||||
return validationError(commandName, repo, "source row column count does not match the target board table header", {
|
||||
issueNumber,
|
||||
source: { section: source.kind, lineNumber: row.lineNumber, rowPreview: preview(row.raw), cells: row.cells.length },
|
||||
target: { section: target.kind, headers: target.headers, columns: target.headers.length },
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
const columnMap = boardColumnIndexMap(target.headers);
|
||||
const githubStatusColumnIndex = columnMap.get("githubStatus");
|
||||
if (githubStatusColumnIndex === undefined) {
|
||||
return validationError(commandName, repo, "target board table does not contain a GitHub 状态 column required for section migration", {
|
||||
issueNumber,
|
||||
targetSection: targetKind,
|
||||
headers: target.headers,
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
const oldCells = row.cells.slice();
|
||||
const newCells = oldCells.slice();
|
||||
const expectedStatus = expectedBoardGithubStatus(targetKind);
|
||||
if (githubStatusColumnIndex !== undefined) newCells[githubStatusColumnIndex] = status ?? expectedStatus;
|
||||
const newRow = renderMarkdownTableRow(newCells);
|
||||
const oldBody = boardIssue.body ?? "";
|
||||
const insertAfterLine = boardSectionInsertAfterLine(target);
|
||||
let newBody: string;
|
||||
try {
|
||||
newBody = source.kind === target.kind
|
||||
? replaceBoardBodyLine(oldBody, row.lineNumber, newRow)
|
||||
: moveBoardBodyRow(oldBody, row.lineNumber, insertAfterLine, newRow);
|
||||
} catch (error) {
|
||||
return validationError(commandName, repo, error instanceof Error ? error.message : String(error), {
|
||||
issueNumber,
|
||||
sourceLineNumber: row.lineNumber,
|
||||
insertAfterLine,
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
newBody,
|
||||
plan: {
|
||||
repo,
|
||||
boardIssue: boardIssue.number,
|
||||
issueNumber,
|
||||
action: source.kind === target.kind ? "move-within-section" : "move",
|
||||
from: source.kind,
|
||||
to: target.kind,
|
||||
sourceLineNumber: row.lineNumber,
|
||||
insertAfterLine,
|
||||
oldRow: row.raw,
|
||||
newRow,
|
||||
oldCells,
|
||||
newCells,
|
||||
row: {
|
||||
old: boardRowSummary(source, row),
|
||||
new: boardRowSummary(target, { ...row, section: target.kind, raw: newRow, cells: newCells, lineNumber: source.kind === target.kind ? row.lineNumber : insertAfterLine + 1 }),
|
||||
},
|
||||
linePlan: {
|
||||
action: source.kind === target.kind ? "replace" : "move",
|
||||
sourceLineNumber: row.lineNumber,
|
||||
insertAfterLine,
|
||||
newLineNumber: source.kind === target.kind ? row.lineNumber : insertAfterLine + 1,
|
||||
},
|
||||
sectionPlan: {
|
||||
from: source.kind,
|
||||
to: target.kind,
|
||||
sourceHeading: source.heading,
|
||||
targetHeading: target.heading,
|
||||
},
|
||||
status: {
|
||||
requested: status ?? null,
|
||||
targetDefault: expectedStatus,
|
||||
githubStatusColumnIndex: githubStatusColumnIndex ?? null,
|
||||
old: oldCells[githubStatusColumnIndex] ?? "",
|
||||
new: newCells[githubStatusColumnIndex] ?? "",
|
||||
},
|
||||
body: {
|
||||
oldBodyChars: oldBody.length,
|
||||
oldBodySha: bodySha(oldBody),
|
||||
newBodyChars: newBody.length,
|
||||
newBodySha: bodySha(newBody),
|
||||
changed: oldBody !== newBody,
|
||||
},
|
||||
tableParser: {
|
||||
reused: "parseBoardTables",
|
||||
rowValidationWarnings: parsed.warnings.length,
|
||||
},
|
||||
request: {
|
||||
method: "PATCH",
|
||||
path: `/repos/{owner}/{repo}/issues/${boardIssue.number}`,
|
||||
body: { bodyChars: newBody.length },
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function boardRowDeletePlan(
|
||||
repo: string,
|
||||
boardIssue: GitHubIssue,
|
||||
issueNumber: number,
|
||||
parsed: { sections: BoardTableSection[]; warnings: BoardRowValidationWarning[] },
|
||||
): BoardRowMutationPlanResult | GitHubCommandFailure {
|
||||
const commandName = "issue board-row delete";
|
||||
const found = findBoardRow(repo, parsed.sections, issueNumber);
|
||||
if (found.ok === false) return { ...found, command: commandName, repo } as GitHubCommandFailure;
|
||||
const { section, row } = found;
|
||||
const sourceConsistency = boardRowStatusConsistency(repo, commandName, section, row, "source");
|
||||
if (sourceConsistency.ok === false) return sourceConsistency;
|
||||
const oldBody = boardIssue.body ?? "";
|
||||
let newBody: string;
|
||||
try {
|
||||
newBody = removeBoardBodyLine(oldBody, row.lineNumber);
|
||||
} catch (error) {
|
||||
return validationError(commandName, repo, error instanceof Error ? error.message : String(error), {
|
||||
issueNumber,
|
||||
lineNumber: row.lineNumber,
|
||||
}) as GitHubCommandFailure;
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
newBody,
|
||||
plan: {
|
||||
repo,
|
||||
boardIssue: boardIssue.number,
|
||||
issueNumber,
|
||||
action: "delete",
|
||||
section: section.kind,
|
||||
lineNumber: row.lineNumber,
|
||||
oldRow: row.raw,
|
||||
oldCells: row.cells,
|
||||
row: {
|
||||
old: boardRowSummary(section, row),
|
||||
new: null,
|
||||
},
|
||||
linePlan: {
|
||||
action: "remove",
|
||||
section: section.kind,
|
||||
lineNumber: row.lineNumber,
|
||||
},
|
||||
sectionPlan: {
|
||||
kind: section.kind,
|
||||
heading: section.heading,
|
||||
headerLine: section.headerLine,
|
||||
rowCount: section.rows.length,
|
||||
},
|
||||
body: {
|
||||
oldBodyChars: oldBody.length,
|
||||
oldBodySha: bodySha(oldBody),
|
||||
newBodyChars: newBody.length,
|
||||
newBodySha: bodySha(newBody),
|
||||
changed: oldBody !== newBody,
|
||||
},
|
||||
tableParser: {
|
||||
reused: "parseBoardTables",
|
||||
rowValidationWarnings: parsed.warnings.length,
|
||||
},
|
||||
request: {
|
||||
method: "PATCH",
|
||||
path: `/repos/{owner}/{repo}/issues/${boardIssue.number}`,
|
||||
body: { bodyChars: newBody.length },
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function issueBoardRowMutation(
|
||||
repo: string,
|
||||
token: string,
|
||||
issueNumber: number,
|
||||
options: GitHubOptions,
|
||||
commandName: "issue board-row add" | "issue board-row move" | "issue board-row delete",
|
||||
mutationKey: "add" | "move" | "delete",
|
||||
buildPlan: (boardIssue: GitHubIssue, parsed: { sections: BoardTableSection[]; warnings: BoardRowValidationWarning[] }) => BoardRowMutationPlanResult | GitHubCommandFailure,
|
||||
): Promise<GitHubCommandResult> {
|
||||
const concurrencyOptionError = assertConcurrencyOptions(options, commandName);
|
||||
if (concurrencyOptionError !== null) return { ...concurrencyOptionError, command: commandName, repo };
|
||||
const boardIssue = await getIssue(token, repo, options.boardIssue);
|
||||
if (isGitHubError(boardIssue)) return commandError(commandName, repo, boardIssue, { boardIssue: options.boardIssue, issueNumber });
|
||||
const parsed = parseBoardTables(boardIssue.body ?? "");
|
||||
const planned = buildPlan(boardIssue, parsed);
|
||||
if (planned.ok === false) return planned;
|
||||
const guardError = boardBodySafetyIssue(repo, options.boardIssue, planned.newBody, options);
|
||||
const guard = boardBodyGuardSummary(options.boardIssue, planned.newBody, options);
|
||||
const hasConcurrencyGuard = options.expectBodySha !== undefined || options.expectUpdatedAt !== undefined;
|
||||
const effectiveDryRun = options.dryRun || !hasConcurrencyGuard;
|
||||
const base = {
|
||||
ok: true,
|
||||
command: commandName,
|
||||
repo,
|
||||
boardIssue: {
|
||||
number: boardIssue.number,
|
||||
title: boardIssue.title,
|
||||
state: boardIssue.state,
|
||||
url: boardIssue.html_url,
|
||||
bodyChars: (boardIssue.body ?? "").length,
|
||||
bodySha: bodySha(boardIssue.body ?? ""),
|
||||
updatedAt: boardIssue.updated_at ?? null,
|
||||
},
|
||||
issueNumber,
|
||||
dryRun: effectiveDryRun,
|
||||
planned: true,
|
||||
[mutationKey]: planned.plan,
|
||||
guard,
|
||||
bodyOnlySafety: {
|
||||
oldBody: {
|
||||
fetched: true,
|
||||
bodyChars: (boardIssue.body ?? "").length,
|
||||
bodySha: bodySha(boardIssue.body ?? ""),
|
||||
updatedAt: boardIssue.updated_at ?? null,
|
||||
},
|
||||
newBody: {
|
||||
bodyChars: planned.newBody.length,
|
||||
bodySha: bodySha(planned.newBody),
|
||||
...bodySafetySignals(planned.newBody),
|
||||
},
|
||||
},
|
||||
concurrency: {
|
||||
expectUpdatedAt: options.expectUpdatedAt ?? null,
|
||||
expectBodySha: options.expectBodySha ?? null,
|
||||
note: `non-dry-run board-row ${mutationKey} requires --expect-body-sha or --expect-updated-at and checks the current board issue before PATCH`,
|
||||
},
|
||||
};
|
||||
if (guardError !== null) return { ...guardError, command: commandName, [mutationKey]: planned.plan, guard };
|
||||
if (effectiveDryRun) {
|
||||
return {
|
||||
...base,
|
||||
dryRun: true,
|
||||
wouldPatch: { issueNumber: options.boardIssue, bodySha: bodySha(planned.newBody), bodyChars: planned.newBody.length },
|
||||
note: !hasConcurrencyGuard
|
||||
? "Default dry-run because no concurrency expectation was supplied; no GitHub issue body was modified."
|
||||
: "Dry-run only; no GitHub issue body was modified.",
|
||||
};
|
||||
}
|
||||
const concurrencyError = validateIssueConcurrency(repo, options.boardIssue, boardIssue, options);
|
||||
if (concurrencyError !== null) return { ...base, ...concurrencyError, command: commandName };
|
||||
const { owner, name } = repoParts(repo);
|
||||
const issue = await githubRequest<GitHubIssue>(token, "PATCH", `/repos/${owner}/${name}/issues/${options.boardIssue}`, { body: planned.newBody });
|
||||
if (isGitHubError(issue)) return commandError(commandName, repo, issue, { issueNumber, [mutationKey]: planned.plan });
|
||||
return {
|
||||
...base,
|
||||
dryRun: false,
|
||||
planned: false,
|
||||
issue: issueSummary(issue),
|
||||
concurrency: {
|
||||
checked: true,
|
||||
oldIssueUpdatedAt: boardIssue.updated_at ?? null,
|
||||
oldBodySha: bodySha(boardIssue.body ?? ""),
|
||||
expectUpdatedAt: options.expectUpdatedAt ?? null,
|
||||
expectBodySha: options.expectBodySha ?? null,
|
||||
},
|
||||
rest: true,
|
||||
};
|
||||
}
|
||||
|
||||
async function issueBoardRowList(repo: string, token: string, options: GitHubOptions): Promise<GitHubCommandResult> {
|
||||
const commandName = "issue board-row list";
|
||||
const boardIssue = await getIssue(token, repo, options.boardIssue);
|
||||
@@ -1795,7 +2410,7 @@ async function issueBoardRowUpdate(repo: string, token: string, issueNumber: num
|
||||
shellPollution: { suspected: true, evidence: valuePollutionEvidence },
|
||||
});
|
||||
}
|
||||
const concurrencyOptionError = assertConcurrencyOptions(options);
|
||||
const concurrencyOptionError = assertConcurrencyOptions(options, commandName);
|
||||
if (concurrencyOptionError !== null) return { ...concurrencyOptionError, command: commandName, repo };
|
||||
|
||||
const boardIssue = await getIssue(token, repo, options.boardIssue);
|
||||
@@ -1855,7 +2470,7 @@ async function issueBoardRowUpdate(repo: string, token: string, issueNumber: num
|
||||
};
|
||||
}
|
||||
const concurrencyError = validateIssueConcurrency(repo, options.boardIssue, boardIssue, options);
|
||||
if (concurrencyError !== null) return { ...base, ...concurrencyError };
|
||||
if (concurrencyError !== null) return { ...base, ...concurrencyError, command: commandName };
|
||||
const { owner, name } = repoParts(repo);
|
||||
const issue = await githubRequest<GitHubIssue>(token, "PATCH", `/repos/${owner}/${name}/issues/${options.boardIssue}`, { body: planned.newBody });
|
||||
if (isGitHubError(issue)) return commandError(commandName, repo, issue, { issueNumber, update: planned.plan });
|
||||
@@ -1875,6 +2490,56 @@ async function issueBoardRowUpdate(repo: string, token: string, issueNumber: num
|
||||
};
|
||||
}
|
||||
|
||||
async function issueBoardRowAdd(repo: string, token: string, issueNumber: number, options: GitHubOptions): Promise<GitHubCommandResult> {
|
||||
const commandName = "issue board-row add";
|
||||
if (options.boardSection === undefined) return validationError(commandName, repo, "issue board-row add requires --section open|closed", { issueNumber, supportedSections: BOARD_MUTATION_SECTIONS.slice() });
|
||||
let rowFile: { path: string; raw: string; cells: string[] };
|
||||
try {
|
||||
rowFile = readBoardRowFile(options.boardRowFile, commandName);
|
||||
} catch (error) {
|
||||
return validationError(commandName, repo, error instanceof Error ? error.message : String(error), {
|
||||
issueNumber,
|
||||
rowFile: options.boardRowFile ?? null,
|
||||
});
|
||||
}
|
||||
return issueBoardRowMutation(
|
||||
repo,
|
||||
token,
|
||||
issueNumber,
|
||||
options,
|
||||
commandName,
|
||||
"add",
|
||||
(boardIssue, parsed) => boardRowAddPlan(repo, boardIssue, issueNumber, options.boardSection as BoardMutationSection, rowFile, parsed),
|
||||
);
|
||||
}
|
||||
|
||||
async function issueBoardRowMove(repo: string, token: string, issueNumber: number, options: GitHubOptions): Promise<GitHubCommandResult> {
|
||||
const commandName = "issue board-row move";
|
||||
if (options.boardMoveTo === undefined) return validationError(commandName, repo, "issue board-row move requires --to open|closed", { issueNumber, supportedTargets: BOARD_MUTATION_SECTIONS.slice() });
|
||||
return issueBoardRowMutation(
|
||||
repo,
|
||||
token,
|
||||
issueNumber,
|
||||
options,
|
||||
commandName,
|
||||
"move",
|
||||
(boardIssue, parsed) => boardRowMovePlan(repo, boardIssue, issueNumber, options.boardMoveTo as BoardMutationSection, options.boardGithubStatus, parsed),
|
||||
);
|
||||
}
|
||||
|
||||
async function issueBoardRowDelete(repo: string, token: string, issueNumber: number, options: GitHubOptions): Promise<GitHubCommandResult> {
|
||||
const commandName = "issue board-row delete";
|
||||
return issueBoardRowMutation(
|
||||
repo,
|
||||
token,
|
||||
issueNumber,
|
||||
options,
|
||||
commandName,
|
||||
"delete",
|
||||
(boardIssue, parsed) => boardRowDeletePlan(repo, boardIssue, issueNumber, parsed),
|
||||
);
|
||||
}
|
||||
|
||||
function ignoredIssueList(issues: BoardIssueEntry[], ignoreMap: Map<number, "known-meta" | "ignored">): BoardIgnoredIssue[] {
|
||||
return sortedIssueEntries(issues.filter((issue) => ignoreMap.has(issue.number))).map((issue) => ({
|
||||
number: issue.number,
|
||||
@@ -2038,13 +2703,13 @@ function issueEditGuardSummary(issueNumber: number, body: string, options: GitHu
|
||||
};
|
||||
}
|
||||
|
||||
function assertConcurrencyOptions(options: GitHubOptions): GitHubCommandResult | null {
|
||||
function assertConcurrencyOptions(options: GitHubOptions, commandName: string): GitHubCommandResult | null {
|
||||
if (options.expectBodySha === undefined) return null;
|
||||
try {
|
||||
normalizeExpectedSha(options.expectBodySha);
|
||||
return null;
|
||||
} catch (error) {
|
||||
return validationError("issue edit", options.repo, error instanceof Error ? error.message : String(error), {
|
||||
return validationError(commandName, options.repo, error instanceof Error ? error.message : String(error), {
|
||||
expectBodySha: options.expectBodySha,
|
||||
});
|
||||
}
|
||||
@@ -2702,7 +3367,7 @@ async function issueEdit(repo: string, token: string, issueNumber: number, optio
|
||||
const bodyGuard = validateIssueBodyGuard(repo, issueNumber, body, options);
|
||||
if (bodyGuard !== null) return bodyGuard;
|
||||
}
|
||||
const concurrencyOptionError = assertConcurrencyOptions(options);
|
||||
const concurrencyOptionError = assertConcurrencyOptions(options, commandName);
|
||||
if (concurrencyOptionError !== null) return concurrencyOptionError;
|
||||
let oldIssue: GitHubIssue | null = null;
|
||||
let briefDiff: CommanderBriefDiff | null = null;
|
||||
@@ -3398,7 +4063,9 @@ export function ghHelp(): unknown {
|
||||
"bun scripts/cli.ts gh issue board-row list [--repo owner/name] --board-issue 20 [--state open|closed|all] [--dry-run]",
|
||||
"bun scripts/cli.ts gh issue board-row get <issueNumber> [--repo owner/name] --board-issue 20",
|
||||
"bun scripts/cli.ts gh issue board-row update <issueNumber> [--repo owner/name] --board-issue 20 --field progress|status|validation|branch|tasks|focus --value <text> [--dry-run] [--expect-updated-at ts|--expect-body-sha sha256]",
|
||||
"bun scripts/cli.ts gh issue board-row move|delete <issueNumber> [unsupported in first phase]",
|
||||
"bun scripts/cli.ts gh issue board-row add <issueNumber> [--repo owner/name] --board-issue 20 --section open|closed --row-file <markdown-row-file> [--dry-run] [--expect-body-sha sha256]",
|
||||
"bun scripts/cli.ts gh issue board-row move <issueNumber> [--repo owner/name] --board-issue 20 --to open|closed [--status OPEN|CLOSED] [--dry-run] [--expect-body-sha sha256]",
|
||||
"bun scripts/cli.ts gh issue board-row delete <issueNumber> [--repo owner/name] --board-issue 20 [--dry-run] [--expect-body-sha sha256]",
|
||||
"bun scripts/cli.ts gh pr list [--repo owner/name] [--limit N] [--json number,title,state,url,updatedAt,createdAt,author,head,base,draft]",
|
||||
"bun scripts/cli.ts gh pr read <number> [--repo owner/name] [--json body,title,state,head,base,draft]",
|
||||
"bun scripts/cli.ts gh pr view <number> [--repo owner/name] [compatibility alias for pr read]",
|
||||
@@ -3427,7 +4094,7 @@ export function ghHelp(): unknown {
|
||||
"issue scan-escape classifies literal \\n findings as suspected-pollution, explanatory-mention, or risk, and emits cleanupSuggestions with body/comment ids plus diff-like previews. cleanup-plan is an alias that remains dry-run/read-only.",
|
||||
"issue board-audit is read-only and defaults to repo pikasTech/unidesk plus board issue #20. It compares GitHub open/closed issue lists with the board OPEN/CLOSED tables and reports missingOpenIssues, closedInOpenRows, missingClosedRows, rowValidationWarnings, ignoredIssues, and recommendedActions. When an Issue column exists, row.issueNumber is taken from that column; #20 and #24 are known meta issues by default.",
|
||||
"issue board-row list/get reuse the board-audit table parser and are read-only. board-row update changes one table cell by issue number, returns old/new row, body SHA, body guard and request plan, and defaults to dry-run unless --expect-updated-at or --expect-body-sha is supplied for the guarded PATCH. Field aliases map status and validation to the 验收状态 column, tasks to 相关 Code Queue 任务, and focus to 当前关注点.",
|
||||
"issue board-row move/delete are structured unsupported in this phase; open/closed relocation and row removal need explicit table placement and duplicate-row semantics before they write.",
|
||||
"issue board-row add/move/delete are row-scoped #20 table mutations. add validates a one-line --row-file against the target table column count, Issue column, and GitHub 状态 column; move refuses duplicate/ambiguous rows and can update GitHub 状态 via --status; delete removes only the matched row. All three default to dry-run and require --expect-body-sha or --expect-updated-at before PATCH. add/move/delete return old/new row, body SHA, and line/section plan details for the parsed table mutation.",
|
||||
"issue edit 24 --notify-claudeqq-brief-diff remains the legacy #24 notification helper: it reads the old issue body, PATCHes the new body, and sends only newly added '## 更新 ... 北京时间' sections to ClaudeQQ; ClaudeQQ failure does not roll back GitHub.",
|
||||
"Commander brief ClaudeQQ defaults to private target 645275593 through backend-core /api/microservices/claudeqq/proxy; UNIDESK_COMMANDER_BRIEF_CLAUDEQQ_* env vars can override target, base URL, timeout, and enabled state.",
|
||||
"comment delete is supported because GitHub supports deleting issue comments; issue/pr hard delete is unsupported and close is the lifecycle alternative.",
|
||||
@@ -3468,9 +4135,9 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
|
||||
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
return validationError(command, options.repo, "--mode is only supported by gh issue update/edit and gh pr update");
|
||||
}
|
||||
if ((options.allowShortBody || options.expectUpdatedAt !== undefined || options.expectBodySha !== undefined || optionWasProvided(args, "--body-profile")) && !(top === "issue" && (sub === "edit" || sub === "update" || sub === "board-row" && third === "update"))) {
|
||||
if ((options.allowShortBody || options.expectUpdatedAt !== undefined || options.expectBodySha !== undefined || optionWasProvided(args, "--body-profile")) && !(top === "issue" && (sub === "edit" || sub === "update" || sub === "board-row" && ["update", "add", "move", "delete"].includes(third ?? "")))) {
|
||||
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
return validationError(command, options.repo, "--allow-short-body, --expect-updated-at, --expect-body-sha, and --body-profile are only supported by gh issue update/edit and gh issue board-row update");
|
||||
return validationError(command, options.repo, "--allow-short-body, --expect-updated-at, --expect-body-sha, and --body-profile are only supported by gh issue update/edit and gh issue board-row update/add/move/delete");
|
||||
}
|
||||
if ((optionWasProvided(args, "--board-issue") || optionWasProvided(args, "--known-meta-issue") || optionWasProvided(args, "--ignore-issue")) && !(top === "issue" && (sub === "board-audit" || sub === "board-row"))) {
|
||||
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
@@ -3484,6 +4151,18 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
|
||||
const command = [top, sub, third].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
return validationError(command, options.repo, "--field and --value are only supported by gh issue board-row update");
|
||||
}
|
||||
if (optionWasProvided(args, "--row-file") && !(top === "issue" && sub === "board-row" && third === "add")) {
|
||||
const command = [top, sub, third].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
return validationError(command, options.repo, "--row-file is only supported by gh issue board-row add");
|
||||
}
|
||||
if (optionWasProvided(args, "--section") && !(top === "issue" && sub === "board-row" && third === "add")) {
|
||||
const command = [top, sub, third].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
return validationError(command, options.repo, "--section is only supported by gh issue board-row add");
|
||||
}
|
||||
if ((optionWasProvided(args, "--to") || optionWasProvided(args, "--status")) && !(top === "issue" && sub === "board-row" && third === "move")) {
|
||||
const command = [top, sub, third].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
return validationError(command, options.repo, "--to and --status are only supported by gh issue board-row move");
|
||||
}
|
||||
if (optionWasProvided(args, "--label") && !(top === "issue" && sub === "create")) {
|
||||
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
return validationError(command, options.repo, "--label is only supported by gh issue create");
|
||||
@@ -3527,20 +4206,8 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
|
||||
if (sub === "board-row") {
|
||||
const action = third;
|
||||
const commandName = `issue board-row ${action ?? ""}`.trim();
|
||||
if (action === "move") {
|
||||
return unsupportedCommand(commandName, options.repo, "board-row move is deferred in the first phase; open/closed row relocation needs explicit destination-section insertion rules, duplicate-row handling, and audit-safe closed/open semantics before it can write.", {
|
||||
boardIssue: options.boardIssue,
|
||||
boundary: "row list/get/update are supported; move between OPEN/CLOSED tables remains unsupported and performs no write",
|
||||
});
|
||||
}
|
||||
if (action === "delete") {
|
||||
return unsupportedCommand(commandName, options.repo, "board-row delete is deferred in the first phase; row removal needs an explicit archival/delete policy and duplicate-row guard before it can write.", {
|
||||
boardIssue: options.boardIssue,
|
||||
boundary: "row list/get/update are supported; delete remains unsupported and performs no write",
|
||||
});
|
||||
}
|
||||
if (action !== "list" && action !== "get" && action !== "update") {
|
||||
return unsupportedCommand(commandName, options.repo, "board-row supported commands are list, get, update, and structured unsupported move/delete.");
|
||||
if (action !== "list" && action !== "get" && action !== "update" && action !== "add" && action !== "move" && action !== "delete") {
|
||||
return unsupportedCommand(commandName, options.repo, "board-row supported commands are list, get, update, add, move, and delete.");
|
||||
}
|
||||
const { token, probe } = resolveToken(true);
|
||||
const missing = authRequired(options.repo, commandName, probe);
|
||||
@@ -3549,7 +4216,10 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
|
||||
const issueNumber = parseNumberForCommand(options.repo, args[3], commandName);
|
||||
if (typeof issueNumber !== "number") return issueNumber;
|
||||
if (action === "get") return issueBoardRowGet(options.repo, token, issueNumber, options);
|
||||
return issueBoardRowUpdate(options.repo, token, issueNumber, options);
|
||||
if (action === "update") return issueBoardRowUpdate(options.repo, token, issueNumber, options);
|
||||
if (action === "add") return issueBoardRowAdd(options.repo, token, issueNumber, options);
|
||||
if (action === "move") return issueBoardRowMove(options.repo, token, issueNumber, options);
|
||||
return issueBoardRowDelete(options.repo, token, issueNumber, options);
|
||||
}
|
||||
if (options.dryRun) {
|
||||
if (sub === "create") return issueCreate(options.repo, "", options);
|
||||
|
||||
Reference in New Issue
Block a user