跳转至

更新仓库设置

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

用户调用此接口,进行更新仓库设置操作。请求体中的字段均为可选,未传的字段保持原设置不变。

访问令牌支持说明

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

是否允许匿名访问

此接口不允许匿名访问

请求参数

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

Request Body:

请求体为 JSON 对象,所有字段均可选;未传的字段保持原设置不变。

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "disable_fork": {
      "description": "禁止派生项目(禁止 Fork 项目)",
      "type": "boolean"
    },
    "forbidden_developer_create_branch": {
      "description": "禁止开发者创建分支",
      "type": "boolean"
    },
    "forbidden_developer_create_tag": {
      "description": "禁止开发者创建标签",
      "type": "boolean"
    },
    "forbidden_committer_create_branch": {
      "description": "禁止提交者创建分支",
      "type": "boolean"
    },
    "forbidden_developer_create_branch_user_ids": {
      "description": "禁止开发者创建分支的白名单用户 ID",
      "type": "string"
    },
    "branch_name_regex": {
      "description": "分支名称正则表达式",
      "type": "string"
    },
    "tag_name_regex": {
      "description": "标签名称正则表达式",
      "type": "string"
    },
    "generate_pre_merge_ref": {
      "description": "生成 MergeRequest 的 Pre-Merge 引用",
      "type": "boolean"
    },
    "rebase_disable_trigger_webhook": {
      "description": "MR rebase 不触发 Webhook 事件",
      "type": "boolean"
    },
    "open_gpg_verified": {
      "description": "公开 GPG 公钥验证",
      "type": "boolean"
    },
    "include_lfs_objects": {
      "description": "压缩包下载包含 LFS 对象",
      "type": "boolean"
    },
    "action_pipeline_enabled": {
      "description": "是否开启 Action 流水线",
      "type": "boolean"
    },
    "block_cross_repo_pr_trigger": {
      "description": "阻止跨仓 PR 触发 Actions",
      "type": "boolean"
    },
    "show_branch_creator": {
      "description": "是否显示分支创建者信息,与页面上「显示分支创建者信息」复选框对应;不传时保持不变",
      "type": "boolean"
    }
  },
  "required": []
}

响应参数

字段 类型 必返 可为空 说明
forbidden_developer_create_branch boolean 是 否 禁止开发者创建分支
forbidden_developer_create_tag boolean 是 否 禁止开发者创建标签
forbidden_committer_create_branch boolean 是 否 禁止提交者创建分支
generate_pre_merge_ref boolean 是 否 生成 MergeRequest 的 Pre-Merge 引用
forbidden_gitlab_access boolean 是 否 禁止 GitLab 访问
rebase_disable_trigger_webhook boolean 是 否 禁止 MR rebase 触发 Webhook 事件
action_pipeline_enabled boolean 是 否 是否开启 Action 流水线
block_cross_repo_pr_trigger boolean 是 否 阻止跨仓 PR 触发 Actions
show_branch_creator boolean 是 否 是否显示分支创建者信息,与页面上「显示分支创建者信息」复选框对应
disable_fork boolean 否 是 禁止派生项目
forbidden_developer_create_branch_users array 否 是 当禁止开发者创建分支时的白名单
branch_name_regex string 否 是 分支名称正则表达式
tag_name_regex string 否 是 标签名称正则表达式
open_gpg_verified boolean 否 是 开启 GPG 公钥验证
include_lfs_objects boolean 否 是 压缩包下载包含 LFS 对象

forbidden_developer_create_branch_users 对象

字段 类型 必返 可为空 说明
forbidden_developer_create_branch_users.id integer 否 是 ID
forbidden_developer_create_branch_users.push_rule_id integer 否 是 推送规则 ID
forbidden_developer_create_branch_users.user_id integer 否 是 用户 ID
forbidden_developer_create_branch_users.user_name string 否 是 用户名

失败响应

调用失败时返回统一的错误响应体,字段包括 error_code(错误码)、error_code_name(错误名称)、error_message(错误信息)、trace_id(追踪 ID)。错误字段名以后端实际返回为准。

400 参数错误

{
  "error_code": 400,
  "error_code_name": "PARAMETER_ERROR",
  "error_message": "参数错误",
  "trace_id": "9f8c1a2b..."
}

401 未认证

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

403 禁止访问

{
  "error_code": 403,
  "error_code_name": "FORBIDDEN",
  "error_message": "没有权限执行此操作",
  "trace_id": "9f8c1a2b..."
}

404 仓库不存在

{
  "error_code": 404,
  "error_code_name": "NOT_FOUND",
  "error_message": "仓库不存在",
  "trace_id": "9f8c1a2b..."
}

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 参数错误(Bad Request)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 仓库不存在(Not Found)
429 请求过于频繁(Rate Limited)
500 系统内部错误(Internal Server Error)

请求示例

参数说明

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

cURL

curl -X PUT 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/repo_settings?access_token=<token>' \
  -H 'Content-Type: application/json' \
  -d '{
    "disable_fork": true,
    "forbidden_developer_create_branch": false,
    "forbidden_developer_create_tag": false,
    "show_branch_creator": true
  }'

JavaScript

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

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>/repo_settings",
    params={"access_token": "<token>"},
    headers={"Content-Type": "application/json"},
    json={
        "disable_fork": True,
        "forbidden_developer_create_branch": False,
        "forbidden_developer_create_tag": False,
        "show_branch_creator": True,
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "forbidden_developer_create_branch": true,
  "forbidden_developer_create_tag": true,
  "forbidden_committer_create_branch": true,
  "generate_pre_merge_ref": true,
  "forbidden_gitlab_access": true,
  "rebase_disable_trigger_webhook": true,
  "action_pipeline_enabled": true,
  "block_cross_repo_pr_trigger": true,
  "show_branch_creator": true
}

错误码

错误码 说明
400 参数错误或请求无法解析
401 未认证或凭证无效
403 禁止访问,无权限执行此操作
404 仓库不存在或请求路径不存在
429 请求过于频繁,触发限流
500 系统内部错误

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