更新项目成员角色¶
PUT /api/v5/repos/{owner}/{repo}/members/{username}
该接口用于更新指定仓库中指定成员的角色权限,通过设置参与者、开发者、维护者或自定义角色等权限级别来调整成员在仓库中的操作权限,操作成功后返回该成员的用户信息及更新后的权限配置。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口不允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(企业、组织或个人的地址path) |
repo |
path | string | 是 | 仓库路径(path) |
username |
path | string | 是 | 项目成员用户名 |
access_token |
query | string | 是 | 用户授权码 |
Request Body:
请求体为 JSON 对象,用于指定成员的新角色。
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"permission": {
"description": "成员权限:参与者(pull),开发者(push),维护者(admin),customized(自定义角色);默认 push",
"type": "string",
"enum": ["pull", "push", "admin", "customized"],
"default": "push"
},
"role_id": {
"description": "角色ID,当 permission 为 customized 时需传入",
"type": "string"
}
}
}
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
followers_url |
string | 是 | 否 | 用户粉丝列表地址 |
html_url |
string | 是 | 否 | 用户主页地址 |
id |
string | 是 | 否 | 用户 ID |
login |
string | 是 | 否 | 用户名(登录名) |
name |
string | 是 | 否 | 用户昵称 |
type |
string | 是 | 否 | 用户类型 |
url |
string | 是 | 否 | 用户 API 地址 |
permissions |
object | 是 | 否 | 成员权限信息 |
permissions 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
permissions.admin |
boolean | 是 | 否 | 是否具有维护者(admin)权限 |
permissions.push |
boolean | 是 | 否 | 是否具有开发者(push)权限 |
permissions.customized |
boolean | 是 | 否 | 是否具有自定义角色(customized)权限 |
permissions.pull |
boolean | 是 | 否 | 是否具有参与者(pull)权限 |
Note: 参考文档的 Schema 中 permissions 各字段标注为 integer,实际返回示例值为 boolean(true/false)。
失败响应¶
只有成功响应是不够的:调用方需要知道失败长什么样才能写错误处理。
401 未认证
400 参数错误
Note: 上述失败响应的错误字段名以后端实际返回为准。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误(Bad request) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
请求路径不存在(Not found) |
请求示例¶
参数说明¶
<owner>替换为仓库所属空间地址(企业、组织或个人的地址 path);<repo>替换为仓库路径(path);<username>替换为项目成员用户名;<token>替换为你的 AtomGit 用户访问令牌;<role_id>替换为自定义角色 ID(当permission传入customized时必须提供)。
cURL¶
curl -X PUT 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/members/<username>?access_token=<token>' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"permission": "customized", "role_id": "<role_id>"}'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/members/<username>?access_token=<token>", {
method: "PUT",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
permission: "customized",
role_id: "<role_id>",
}),
});
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>/members/<username>?access_token=<token>",
headers={
"Accept": "application/json",
"Content-Type": "application/json",
},
json={
"permission": "customized",
"role_id": "<role_id>",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"followers_url": "https://api.atomgit.com/api/v5/users/xiaogang2/followers",
"html_url": "https://api.atomgit.com/xiaogang2",
"id": "65ffca965079ba0d1c00f6f2",
"login": "xiaogang2",
"name": "肖刚2",
"type": "User",
"url": "https://api.atomgit.com/api/v5/xiaogang2",
"permissions": {
"admin": false,
"push": false,
"customized": true,
"pull": false
}
}
错误码¶
| 错误码 | 说明 |
|---|---|
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
400 |
参数错误或请求无法解析 |
403 |
禁止访问 |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc