触发条件

想用 gh CLI / 脚本自动化管理个人 profile 上 "Pinned repositories"(置顶 / 取消置顶 / 排序)。

症状

  • gh repo 无 pin / unpin 子命令
  • REST / GraphQL 公开 API 均无相关端点

已核实的事实(2026-08 实测)

  1. GraphQL 公开 schema:__schema.mutationType.fields 中只有 pinIssue / pinIssueComment / pinEnvironment / unpinIssue / unpinIssueComment,与仓库 pin 无关;queryType 无任何含 pin 的查询
  2. REST:无 pins 相关端点(/me/pins、/users/<u>/pins 均 404)
  3. 网页内部端点:github.com/pins 实际是 PINS 组织的主页(同名撞车,别被误导);真正的 reorder/pin 管理表单只在本人带浏览器会话访问 profile 时才渲染,且提交需 CSRF token
  4. 内部 GraphQL github.com/_graphql:拒绝 bearer token(Couldn't authenticate you),必须会话 cookie
  5. gh-pins 类社区扩展均为只读获取 pinned 列表,不能改
  6. gh CLI 的 OAuth token(gho_...)无法充当 github.com 网页会话

根因

Profile 仓库 pin 是纯前端功能,后端只有网页会话端点,从未暴露到公开 API。

解决方案

  • 手动(推荐,30 秒):profile 页 → "Customize your pins" → 勾选/取消 → Save
  • 脚本:只能浏览器自动化(Playwright/Selenium)复用已登录会话,无纯 API 路径

下次如何识别

  • 想要自动化 GitHub 网页功能时,先查 GraphQL mutation 列表:gh api graphql -f query='query { __schema { mutationType { fields { name } } } }'
  • 查 REST:gh api /<候选端点> 看是否 404
  • 网页内部端点几乎都要 _gh_sess cookie + authenticity_token,CLI token 无效

相关概念

  • 本地工具脱敏后发布到 GitHub Public (Sanitized Public Release)

本文归档于个人知识库 · 领域:CS & AI · 模块:04 Project_CS_AI/General