fix(skill): board-sync 清掉失效的继承优先级(PR 的优先级来源关闭后留空)

首次在 2026-10-11 的分诊里跑全量同步时,verify() 报了 23 条 mismatched,全部是 PR
的 优先级:脚本只在「有新值」时写字段,而 PR 的优先级是从它引用的仍开着的 issue
继承的——那批 issue 一关闭,期望值变成「留空」,旧值却留在板上,于是脚本自己算出的
期望与看板永远对不上。

- 期望值为空时改为清空字段:value:{singleSelectOptionId:null}(value:null 被 schema
  拒,ProjectV2FieldValue! 非空)。
- gh-gotchas.md 记下这条坑。
This commit is contained in:
Menghuan1918 committed 2026-10-11 22:39:18 +08:00
1 parent 0c3e5e9279
commit c1bea9047e
2 files changed
+9 -2

No files matched your search

@@ -16,6 +16,7 @@
## 字段与选项
- **`updateProjectV2Field(singleSelectOptions: [...])` 是整体替换**:被替换掉的选项 id 失效、`Status` 值会掉;想改选项就把**全部**目标选项一次列全(name/color/description 三个字段都是必填),改完**重新给条目写一遍值**。
- **清空某个单选字段的值:传 `value:{singleSelectOptionId:null}`**,不要传 `value:null`——`UpdateProjectV2ItemFieldValueInput.value` 的类型是 `ProjectV2FieldValue!`(非空),传 null 会被 schema 拒(`argumentLiteralsIncompatible`)。`board-sync.mjs` 依赖这条来清掉「继承来源已关闭」的 PR 优先级:只在有新值时才写的实现会让 `verify()` 永远报 `mismatched`(2026-10-11 实测 23 条)。
- option id 会随替换变化 → 脚本每次运行都按**名字**重新解析 id,不要硬编码。
- `ProjectV2SingleSelectFieldOptionInput` 三个字段全 `NON_NULL`:`name` / `color`(枚举 `GRAY BLUE GREEN YELLOW ORANGE RED PINK PURPLE`)/ `description`(可空串)。
@@ -174,7 +174,13 @@ for (const [key, want] of desired) {
}
const wantValues = { '优先级': want.prio, '批次': want.batch, 'Status': want.status };
for (const [name, value] of Object.entries(wantValues)) {
if (!value || item.current[name] === value) continue;
if ((item.current[name] ?? undefined) === (value ?? undefined)) continue;
// A value that is no longer desired must be CLEARED, not left behind: a PR
// inherits its priority from the issues it cites, so when the last of those
// issues closes the inherited value has to go (otherwise verify() fails on
// exactly this mismatch). `value: null` is rejected — ProjectV2FieldValue!
// is non-null; the null option id is what clears a single-select.
if (!value) { mutations.push({ itemId: item.id, fieldId: fieldId[name], clear: true }); continue; }
const oid = optionId[`${name}:${value}`];
if (!oid) { console.log(`! ${key} no option ${name}:${value}`); continue; }
mutations.push({ itemId: item.id, fieldId: fieldId[name], optionId: oid });
@@ -182,7 +188,7 @@ for (const [key, want] of desired) {
}
for (let i = 0; i < mutations.length; i += 16) {
const chunk = mutations.slice(i, i + 16);
gql('mutation{' + chunk.map((m, k) => `m${k}:updateProjectV2ItemFieldValue(input:{projectId:"${PROJECT}",itemId:"${m.itemId}",fieldId:"${m.fieldId}",value:{singleSelectOptionId:"${m.optionId}"}}){projectV2Item{id}}`).join(' ') + '}');
gql('mutation{' + chunk.map((m, k) => `m${k}:updateProjectV2ItemFieldValue(input:{projectId:"${PROJECT}",itemId:"${m.itemId}",fieldId:"${m.fieldId}",value:${m.clear ? '{singleSelectOptionId:null}' : `{singleSelectOptionId:"${m.optionId}"}`}}){projectV2Item{id}}`).join(' ') + '}');
}
console.log(`items: ${items.size} on board | field writes: ${mutations.length}`);
verify();