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

GitHub分支设管理员保护时遇'Resource not accessible by integration'错误

错误原因与解决步骤

你的错误源于两个核心问题:参数传递格式不符合工具要求,以及权限不足,以下是针对性解决方案:

1. 修正参数传递方式

你收到的Unexpected input(s) 'owner', 'repo', 'branch'警告明确说明,octokit/request-action v2版本不支持将路由占位符参数直接作为with的顶级输入项。正确做法是通过parameters字段以JSON格式传递所有参数:

- name: Enforce admin protection
  uses: octokit/request-action@v2.1.0
  id: enforce_admin_protection
  with:
    route: POST /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
    parameters: |
      {
        "owner": "TheOddler",
        "repo": "github-actions-tests",
        "branch": "${{ github.event.inputs.branch }}"
      }
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2. 确保权限满足要求

write-all权限虽宽泛,但设置管理员分支保护需要明确的admin:write权限。同时默认GITHUB_TOKEN可能因仓库/组织限制无法获取足够权限,可按以下方式调整:

  • 精确指定权限:

    jobs:
      disable-merging:
        name: Disable Merging
        permissions:
          admin: write  # 明确声明管理员写入权限
        runs-on: ubuntu-latest
        # 后续步骤...
    
  • 若默认token仍报错,改用个人访问令牌(PAT):

    1. 生成PAT并勾选repo和admin:repo_hook权限
    2. 将PAT添加到仓库Secrets,命名为ADMIN_PAT
    3. 在Action中替换token:
      env:
        GITHUB_TOKEN: ${{ secrets.ADMIN_PAT }}
      

3. 完整修正后的Action示例

name: Disable merging

on:
  workflow_dispatch:
    inputs:
      branch:
        description: What branch to protect
        default: main
        required: true

jobs:
  disable-merging:
    name: Disable Merging
    permissions:
      admin: write
    runs-on: ubuntu-latest
    steps:
    - name: Enforce admin protection
      uses: octokit/request-action@v2.1.0
      id: enforce_admin_protection
      with:
        route: POST /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
        parameters: |
          {
            "owner": "TheOddler",
            "repo": "github-actions-tests",
            "branch": "${{ github.event.inputs.branch }}"
          }
      env:
        GITHUB_TOKEN: ${{ secrets.ADMIN_PAT }}

# 后续等待并重新启用的任务...

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 16:53:08