跳转至

配置项目 CLA

PUT /api/v5/repos/{owner}/{repo}/cla

该接口用于配置项目 CLA:传入 cla_id 可启用并选择指定的 CLA,不传则关闭项目 CLA 配置;同时支持设置是否禁止合入未完成 CLA 签署检查的 Pull Request。

访问令牌支持说明

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

是否允许匿名访问

此接口不允许匿名访问

请求参数

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

Request Body:

请求体为 JSON 对象,用于配置项目 CLA。两个字段均可选;cla_id 不传(或为空)时表示关闭项目 CLA 配置。

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "cla_id": {
      "description": "要启用的 CLA ID(来自 CLA 列表接口)。传 cla_id 表示启用并选择该 CLA;不传表示关闭项目 CLA 配置",
      "type": "string"
    },
    "enforce_check": {
      "description": "是否禁止合入未完成 CLA 签署检查的 Pull Request(true 禁止 / false 不禁止)。仅当启用 CLA 时有意义",
      "type": "boolean"
    }
  }
}

响应参数

该接口无响应体:成功时返回 200,响应体为空。

失败响应

接口可能返回以下失败响应(响应体为 ApiErrorResp 结构,字段按 snake_case 命名)。

401 未认证

{
  "error_code": 401,
  "error_code_name": "UNAUTHORIZED",
  "error_message": "缺少或无效的访问令牌"
}

403 禁止访问

{
  "error_code": 403,
  "error_code_name": "FORBIDDEN",
  "error_message": "no permission"
}

404 仓库不存在

{
  "error_code": 404,
  "error_code_name": "NOT_PATH",
  "error_message": "project not found"
}

429 请求过于频繁

{
  "error_code": 429,
  "error_code_name": "TOO_MANY_REQUESTS",
  "error_message": "请求过于频繁,触发限流"
}

HTTP 响应状态码

状态码 说明
200 成功(OK),响应体为空
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 仓库不存在(Not found)
429 请求过于频繁(Too many requests)

请求示例

参数说明

示例中的占位符:<owner> 替换为仓库所属空间地址(企业、组织或个人的地址 path);<repo> 替换为仓库路径(path);<token> 替换为你的 AtomGit 用户访问令牌;<cla_id> 替换为要启用的 CLA ID(来自 CLA 列表接口)。

cURL

curl -X PUT 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/cla?access_token=<token>' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{"cla_id": "<cla_id>", "enforce_check": true}'

JavaScript

const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/cla?access_token=<token>", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
  },
  body: JSON.stringify({
    cla_id: "<cla_id>",
    enforce_check: true,
  }),
});

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

console.log(`配置成功: ${response.status}`);

Python

import requests

resp = requests.put(
    "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/cla",
    params={"access_token": "<token>"},
    json={"cla_id": "<cla_id>", "enforce_check": True},
    headers={"Accept": "application/json"},
    timeout=10,
)
resp.raise_for_status()

print(resp.status_code)

响应示例

状态码: 200

该接口成功时返回空响应体(无内容)。

错误码

错误码 说明
401 未认证或凭证无效(缺少/无效的访问凭证)
403 禁止访问(无操作权限)
404 仓库不存在
429 请求过于频繁,触发限流
500 系统内部错误

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