You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub REST API:分支保护中「指定可强制推送人员」对应JSON属性查询

关于GitHub REST API设置「指定谁可以强制推送」的问题

我希望通过GitHub REST API(使用curl)更新分支保护设置中的「指定谁可以强制推送」部分。当前使用GitHub Enterprise Server 3.12.4,该功能已在GitHub UI中上线,但REST API及文档可能未同步更新。请问下方PUT请求体中的哪个JSON属性,对应GitHub UI里的「指定谁可以强制推送」设置?

相关curl命令

curl -L \
  -X PUT \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/branches/BRANCH/protection \
  -d ...

文档示例JSON

// 文档示例JSON
{
  "required_status_checks": {
    "strict": true,
    "contexts": [
      "continuous-integration/travis-ci"
    ]
  },
  "enforce_admins": true,
  "required_pull_request_reviews": {
    "dismissal_restrictions": {
      "users": [
        "octocat"
      ],
      "teams": [
        "justice-league"
      ]
    },
    "dismiss_stale_reviews": true,
    "require_code_owner_reviews": true,
    "required_approving_review_count": 2,
    "require_last_push_approval": true,
    "bypass_pull_request_allowances": {
      "users": [
        "octocat"
      ],
      "teams": [
        "justice-league"
      ]
    }
  },
  "restrictions": {
    "users": [
      "octocat"
    ],
    "teams": [
      "justice-league"
    ],
    "apps": [
      "super-ci"
    ]
  },
  "required_linear_history": true,
  "allow_force_pushes": true, // 对应GitHub UI中的「允许强制推送」设置
  // 问题:哪个JSON属性对应GitHub UI中的「指定谁可以强制推送」设置?
  "allow_deletions": true,
  "block_creations": true,
  "required_conversation_resolution": true,
  "lock_branch": true,
  "allow_fork_syncing": true
}

答案

在GitHub Enterprise Server 3.12.4的分支保护API中,「指定谁可以强制推送」对应的是allow_force_pushes的对象形式,而非单纯的布尔值。完整结构如下:

"allow_force_pushes": {
  "enabled": true, // 控制是否开启允许强制推送功能
  "users": ["octocat"], // 指定允许强制推送的用户
  "teams": ["justice-league"], // 指定允许强制推送的团队
  "apps": ["super-ci"] // 指定允许强制推送的应用
}

原来的"allow_force_pushes": true仅用于全局开启所有用户/团队的强制推送权限,而要指定特定主体,需要将该属性改为包含enabled、users、teams、apps的对象结构,以此精准控制哪些对象拥有强制推送权限。


内容的提问来源于stack exchange,提问作者hIpPy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 20:25:55