跳转至

更新保护分支规则

PUT /api/v5/repos/{owner}/{repo}/branches/{wildcard}/setting

该接口用于更新指定仓库中特定保护分支的规则,通过设置可推送代码的成员与可合并请求的成员,来控制代码推送和合并的权限。

访问令牌支持说明

  • AtomGit 用户访问令牌(AtomGit user access tokens)

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
owner path string 是 仓库所属空间地址(组织或个人的地址path)
repo path string 是 仓库路径(path)
wildcard path string 是 保护分支名
access_token query string 是 用户授权码

Request Body:

请求体为 JSON 对象,包含需要更新的保护分支规则。pusher 与 merger 均为必填字段。

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "pusher": {
      "description": "可推送代码成员。develop:仓库管理员和开发者;admin:仓库管理员;maintainer:维护者;多个角色使用英文分号相隔;指定用户传入用户名,多个用户使用英文分号隔开;空字符串表示不允许任何人推送",
      "type": "string"
    },
    "merger": {
      "description": "可合并 Pull Request 成员。develop:仓库管理员和开发者;admin:仓库管理员;maintainer:维护者;多个角色使用英文分号相隔;指定用户传入用户名,多个用户使用英文分号隔开;空字符串表示不允许任何人合并",
      "type": "string"
    }
  },
  "required": ["pusher", "merger"]
}

响应参数

成功时响应体为空对象 {},无任何响应字段。

失败响应

调用方需要知道失败响应的形态以编写错误处理。以下示例的字段名以后端实际返回为准。

400 参数错误

{
  "error": "invalid_request",
  "message": "参数 pusher 不能为空"
}

401 未认证

{
  "error": "unauthorized",
  "message": "缺少或无效的访问令牌"
}

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 参数错误(Bad request)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 资源不存在(Not found)
500 系统内部错误(Internal server error)

请求示例

参数说明

示例与本文档其余部分自洽,照抄即可调用成功。各占位符含义如下:

<owner> 替换为仓库所属空间地址(组织或个人的地址 path); <repo> 替换为仓库路径(path); <wildcard> 替换为保护分支名; <token> 替换为你的 AtomGit 用户访问令牌。

cURL

curl -X PUT 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/<wildcard>/setting?access_token=<token>' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "pusher": "admin",
    "merger": "develop"
  }'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/<wildcard>/setting?access_token=<token>", {
  method: "PUT",
  headers: {
    "Accept": "application/json",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    pusher: "admin",
    merger: "develop",
  }),
});

if (!response.ok) {
  throw new Error(`请求失败: ${response.status}`);
}

const data = await response.json();
console.log(data);

Python

import requests

resp = requests.put(
    "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/<wildcard>/setting?access_token=<token>",
    headers={
        "Accept": "application/json",
        "Content-Type": "application/json",
    },
    json={
        "pusher": "admin",
        "merger": "develop",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{}

错误码

错误码 说明
400 参数错误或请求无法解析
401 未认证或凭证无效(缺少/无效的访问凭证)
403 禁止访问(无权限执行该操作)
404 请求的资源(仓库或分支)不存在
500 系统内部错误

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc