跳转至

设置项目模块

PUT /api/v5/repos/{owner}/{repo}/module/setting

该接口用于设置指定仓库的项目模块,可分别开启或关闭 wiki、issue、安全配置、merge request、fork、分析与讨论等模块,请求体中未涉及的模块保持原有设置不变。

访问令牌支持说明

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

是否允许匿名访问

此接口不允许匿名访问

请求参数

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

Request Body:

请求体用于设置需要启用的项目模块,未在请求体中出现的字段保持其原有设置不变;每个字段均为布尔开关,传 true 表示启用该模块,传 false 表示关闭该模块。

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "has_wiki": {
      "description": "是否设置 wiki",
      "type": "boolean"
    },
    "has_issue": {
      "description": "是否设置 issue",
      "type": "boolean"
    },
    "has_security": {
      "description": "是否设置安全配置",
      "type": "boolean"
    },
    "has_merge_request": {
      "description": "是否设置 merge request",
      "type": "boolean"
    },
    "has_fork": {
      "description": "是否设置 fork",
      "type": "boolean"
    },
    "has_analysis": {
      "description": "是否设置分析",
      "type": "boolean"
    },
    "has_discussion": {
      "description": "是否设置讨论",
      "type": "boolean"
    }
  }
}

响应参数

字段 类型 必返 可为空 说明
msg string 是 否 响应消息,成功时为 success
code integer 是 否 响应状态码,成功时为 1

失败响应

401 未认证

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

403 无权限

{
  "error": "forbidden",
  "message": "无权执行仓库设置操作"
}

404 仓库不存在

{
  "error": "not_found",
  "message": "仓库不存在或已被删除"
}

HTTP 响应状态码

状态码 说明
200 成功(OK)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 未找到(Not found)

请求示例

参数说明

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

cURL

curl -X PUT 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/module/setting?access_token=<token>' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "has_wiki": true,
    "has_issue": true,
    "has_security": true,
    "has_merge_request": true,
    "has_fork": true,
    "has_analysis": true,
    "has_discussion": true
  }'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
  "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/module/setting?access_token=<token>",
  {
    method: "PUT",
    headers: {
      "Content-Type": "application/json",
      "Accept": "application/json",
    },
    body: JSON.stringify({
      has_wiki: true,
      has_issue: true,
      has_security: true,
      has_merge_request: true,
      has_fork: true,
      has_analysis: true,
      has_discussion: 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>/module/setting",
    params={"access_token": "<token>"},
    headers={
        "Content-Type": "application/json",
        "Accept": "application/json",
    },
    json={
        "has_wiki": True,
        "has_issue": True,
        "has_security": True,
        "has_merge_request": True,
        "has_fork": True,
        "has_analysis": True,
        "has_discussion": True,
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "msg": "success",
  "code": 1
}

错误码

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

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