概述
- 注册应用无需审核即可使用授权。
- 采用 OAuth 2.0 协议认证。
接入
1.1 开发者注册
在账户 -> 应用管理页面添加应用,注册要接入 Coding 的应用。
其中回调地址是用户授权后,Coding 回调到应用,并且回传授权码的地址。
保存后,会返回到应用列表。
此时再查看应用,会生成 client id
和 client secret
。
保存 client id
和 client secret
,以便后续认证使用。
1.2 授权流程
- 将用户引导到 Coding 第三方登录页面上。如右侧:
https://coding.net/oauth_authorize.html?client_id={client_id}
&redirect_uri={redirect_uri}&response_type=code[&scope={scope}]
如用户未登录 Coding,跳转到登录页面
用户登录,并对应用请求的
scope
进行授权。授权通过,Coding 会将授权码回传给应用在 Coding 注册的回调地址
(http://xxx.com/callback?code=xxx)
,应用直接获取授权码code
即可。应用向 Coding 的 Token Endpoint 发送请求:
https://coding.net/api/oauth/access_token?client_id={client_id}&client_secret=
{client_secret}&grant_type=authorization_code&code={code}
返回值 :
{ "expires_in": "271645", "refresh_token": "xxxxxx", "access_token":"xxxxxx" }
使用
access_token
访问受保护的资源https://coding.net/api/current_user?access_token={access_token}
Response body 中的
code
为 0,表示正常接收请求。如果code
为 1,表示请求异常,请参照msg
中的返回信息进行处理。
参数
scope 名称 | 说明 | 授权 |
---|---|---|
user | 授权获取用户信息(用户名称,头像,tag,email,动态 ) | 读 |
user:email | 授权获取用户的email ) | 读 |
notification | 授权读取通知信息,包含email通知 | 读写 |
social | 授权读取冒泡列表,好友列表 | 读 |
social:tweet | 授权发送冒泡,冒泡操作(点赞、评论、删除) | 读写 |
social:message | 授权读取、发送私信、私信语音 | 读写 |
project | 授权项目信息、项目列表,仓库信息,公钥列表、成员,任务列表 | 读 |
project:members | 授权项目管理者增、删、改项目成员,退出项目 | 读写 |
project:task | 授权任务操作,包含增、删、改 | 读写 |
project:file | 授权文件,包含增、删、改 | 读写 |
project:depot | 获取 commit 信息,分支操作,MR/PR, LineNotes, fork, webhook 等操作 | 读写 |
project:key | 授权操作部署公钥、个人公钥 | 读写 |
2.1.0 用户信息
GET /api/account/current_user
Response:
{
"code": 0,
"data": {
"tags_str": "云计算追随者, 技术风向标",
"tags": "19,32",
"job_str": "产品",
"job": 2,
"sex": 0,
"phone": "18600000000",
"birthday": "2014-07-16",
"location": "广东 深圳 ",
"company": "Coding.net",
"slogan": "让开发更简单",
"website": "",
"introduction": "",
"avatar": "https://dn-coding-net-avatar.qbox.me/89628160-f594-4e52-8c77-fda089fcc7dd.jpg",
"gravatar": "https://dn-coding-net-avatar.qbox.me/89628160-f594-4e52-8c77-fda089fcc7dd.jpg",
"lavatar": "https://dn-coding-net-avatar.qbox.me/89628160-f594-4e52-8c77-fda089fcc7dd.jpg",
"created_at": 1399045779000,
"last_logined_at": 1502121619000,
"last_activity_at": 1502173432514,
"global_key": "coding",
"name": "coding",
"name_pinyin": "coding",
"updated_at": 1502121621000,
"path": "/u/coding",
"status": 1,
"email": "coding@coding.net",
"is_member": 0,
"id": 93,
"points_left": 0.44,
"vip": 4,
"vip_expired_at": 1502467200000,
"skills": [
{
"skillName": "Java",
"skillId": 1,
"level": 4
},
{
"skillName": "Ruby",
"skillId": 3,
"level": 3
},
{
"skillName": "JavaScript",
"skillId": 11,
"level": 3
}
],
"degree": 3,
"school": "",
"follows_count": 83,
"fans_count": 191,
"tweets_count": 110,
"phone_country_code": "+86",
"country": "cn",
"followed": false,
"follow": false,
"is_phone_validated": true,
"email_validation": 1,
"phone_validation": 1,
"twofa_enabled": 1
}
}
2.2.0 发冒泡
POST /api/social/tweet
表单字段 | 数据类型 | 说明 |
---|---|---|
content | string | 冒泡内容,必填 |
device | string | 冒泡来源设备,选填 |
location | string | 地点,选填 |
coord | string | 坐标,选填 |
address | address | 地址,选填 |
Response:
{
"code": 0,
"data": {
"id": 27020,
"owner_id": 84337,
"created_at": 1426585007031,
"likes": 0,
"comments": 0,
"device": "",
"location": "",
"coord": "",
"content": "<p>testing<img class=\"emotion emoji\" src=\"https://coding.net/static/emojis/grin.png\" title=\"grin\"><br> <a href=\"https://dn-coding-net-production-pp.qbox.me/f8338ca1-890c-4be2-bfda-a9eb890ab1b1.jpg\" target=\"_blank\" class=\"bubble-markdown-image-link\" rel=\"nofollow\"><img src=\"https://dn-coding-net-production-pp.qbox.me/f8338ca1-890c-4be2-bfda-a9eb890ab1b1.jpg\" alt=\"图片\" class=\" bubble-markdown-image\"></a></p>",
"path": "/u/baoti/pp/27020",
"activity_id": 0,
"liked": false
}
}
2.3.0 用户的项目列表
GET /api/user/projects
Response:
{
"code": 0,
"data": {
"page": 1,
"pageSize": 100,
"totalPage": 1,
"totalRow": 2,
"list": [
{
"created_at": 1426246044000,
"backend_project_path": "/user/baoti/project/Coding-API",
"description": "Coding 的 API 是啥样呢?瞧一瞧,看一看。\n注意:由于官方未提供 API 文档,此处 API 整理自 Coding-Android 项目源码。\n尚未对照 IOS 客户端源码。请前往演示, 或转至 http://coding-api.coding.io/ 以查看当前整理的 API.",
"git_url": "git://coding.net/baoti/Coding-API.git",
"ssh_url": "git@coding.net:baoti/Coding-API.git",
"is_public": true,
"https_url": "https://coding.net/baoti/Coding-API.git",
"id": 67965,
"name": "Coding-API",
"owner_id": 84337,
"owner_user_name": "baoti",
"owner_user_picture": "/static/fruit_avatar/Fruit-2.png",
"owner_user_home": "<a href=\"https://coding.net/u/baoti\">baoti</a>",
"project_path": "/u/baoti/p/Coding-API",
"status": 1,
"type": 1,
"updated_at": 1426576642885,
"last_updated": 1426576630625,
"fork_count": 0,
"star_count": 2,
"watch_count": 5,
"pin": false,
"depot_path": "/u/baoti/p/Coding-API/git",
"forked": false,
"un_read_activities_count": 0,
"icon": "/static/project_icon/scenery-23.png",
"current_user_role_id": 100,
"current_user_role": "owner",
"stared": false,
"watched": false,
"recommended": 1,
"max_member": 10,
"groupId": 0
},
{
"created_at": 1426171134000,
"backend_project_path": "/user/baoti/project/Coding-Android",
"description": "Fork 自官方仓库,并添加了自己的修改分支",
"git_url": "git://coding.net/baoti/Coding-Android.git",
"ssh_url": "git@coding.net:baoti/Coding-Android.git",
"is_public": true,
"https_url": "https://coding.net/baoti/Coding-Android.git",
"id": 67604,
"name": "Coding-Android",
"owner_id": 84337,
"owner_user_name": "baoti",
"owner_user_picture": "/static/fruit_avatar/Fruit-2.png",
"owner_user_home": "<a href=\"https://coding.net/u/baoti\">baoti</a>",
"project_path": "/u/baoti/p/Coding-Android",
"status": 1,
"type": 1,
"updated_at": 1426485162000,
"last_updated": 1426485163000,
"fork_count": 307,
"star_count": 0,
"watch_count": 0,
"pin": false,
"depot_path": "/u/baoti/p/Coding-Android/git",
"forked": true,
"un_read_activities_count": 0,
"icon": "/static/project_icon/scenery-17.png",
"current_user_role_id": 100,
"current_user_role": "owner",
"stared": false,
"watched": false,
"recommended": 0,
"max_member": 10,
"groupId": 0,
"parent_depot_path": "coding/Coding-Android"
}
]
}
}
2.4.0 创建任务
POST /api/user/{user_name}/project/{project_name}/task
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
表单字段 | 数据类型 | 说明 |
---|---|---|
owner_id | string | 当前任务执行人的 id |
priority | int | 任务优先级, 默认值为 1, 0 - 有空再看, 1 - 正常处理, 2 - 优先处理, 3 - 十万火急 |
deadline | string | 任务完成期限, 选填 |
description | string | 任务描述, 选填 |
content | string | 任务内容, 选填 |
Response:
{
"code": 0
}
2.4.1 根据 id 获取任务
GET /api/user/{user_name}/project/{project_name}/task/{task_id}
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
task_id | int | 任务 id |
Response:
{
"code": 0,
"data": {
"id": 123,
"priority": 2,
"comments": 0,
"content": "",
"created_at": 1426579942000,
"creator": {
"avatar": "/static/fruit_avatar/Fruit-15.png",
"gravatar": "https://dn-coding-net-avatar.qbox.me/89628160-f594-4e52-8c77-fda089fcc7dd.jpg",
"lavatar": "/static/fruit_avatar/Fruit-15.png",
"global_key": "baoti",
"name": "baoti",
"id": 85544
},
"creator_id": 85544,
"current_user_role_id": "2",
"owner": {
"avatar": "/static/fruit_avatar/Fruit-15.png",
"gravatar": "https://dn-coding-net-avatar.qbox.me/89628160-f594-4e52-8c77-fda089fcc7dd.jpg",
"lavatar": "/static/fruit_avatar/Fruit-15.png",
"global_key": "baoti",
"name": "baoti",
"id": 85544
},
"owner_id": 85544,
"project": {
"id": 67965,
"name": "Coding-API",
"owner_id": 84337
},
"project_id": 67965,
"status": 1,
"updated_at": 1426579942000,
"deadline": "",
"has_description": true
}
}
2.4.2 根据 id 删除任务
DELETE /api/user/{user_name}/project/{project_name}/task/{task_id}
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
task_id | int | 任务 id |
Response:
{
"code": 0
}
2.4.3 更新任务
PUT /api/user/{user_name}/project/{project_name}/task/{task_id}
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
task_id | int | 任务 id |
表单字段 | 数据类型 | 说明 |
---|---|---|
content | string | 任务内容, 可不填 |
status | short | 任务内容, 1 - 进行中, 2 - 已完成, 可不填 |
owner_id | int | 任务新执行者的 id, 可不填 |
description | string | 任务描述, 可不填 |
priority | int | 任务优先级, 默认值为 1, 0 - 有空再看, 1 - 正常处理, 2 - 优先处理, 3 - 十万火急, 可不填 |
deadline | string | 任务完成期限, 格式 "yyyy-MM-dd" |
Response:
{
"code": 0
}
2.4.4 获取用户某项目的任务列表
GET /api/user/{user_name}/project/{project_name}/tasks/my/{task_status}
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
task_status | string | 任务状态, "all" - 获取所有任务, "processing" - 获取进行中的任务, "done" - 获取已完成的任务, "watch" - 获取关注的任务 |
Response:
{
"code": 0,
"data": {
"page": 1,
"pageSize": 100,
"totalPage": 1,
"totalRow": 2,
"list": [
{
"id": 123,
"priority": 2,
"comments": 0,
"content": "",
"created_at": 1426579942000,
"creator": {
"avatar": "/static/fruit_avatar/Fruit-15.png",
"gravatar": "https://dn-coding-net-avatar.qbox.me/89628160-f594-4e52-8c77-fda089fcc7dd.jpg",
"lavatar": "/static/fruit_avatar/Fruit-15.png",
"global_key": "baoti",
"name": "baoti",
"id": 85544
},
"creator_id": 85544,
"current_user_role_id": "2",
"owner": {
"avatar": "/static/fruit_avatar/Fruit-15.png",
"gravatar": "https://dn-coding-net-avatar.qbox.me/89628160-f594-4e52-8c77-fda089fcc7dd.jpg",
"lavatar": "/static/fruit_avatar/Fruit-15.png",
"global_key": "baoti",
"name": "baoti",
"id": 85544
},
"owner_id": 85544,
"project": {
"id": 67965,
"name": "Coding-API",
"owner_id": 84337
},
"project_id": 67965,
"status": 1,
"updated_at": 1426579942000,
"deadline": "",
"has_description": true
},
{
"id": 125,
"priority": 2,
"comments": 0,
"content": "",
"created_at": 1426579942000,
"creator": {
"avatar": "/static/fruit_avatar/Fruit-15.png",
"gravatar": "https://dn-coding-net-avatar.qbox.me/89628160-f594-4e52-8c77-fda089fcc7dd.jpg",
"lavatar": "/static/fruit_avatar/Fruit-15.png",
"global_key": "baoti",
"name": "baoti",
"id": 85544
},
"creator_id": 85544,
"current_user_role_id": "2",
"owner": {
"avatar": "/static/fruit_avatar/Fruit-15.png",
"gravatar": "https://dn-coding-net-avatar.qbox.me/89628160-f594-4e52-8c77-fda089fcc7dd.jpg",
"lavatar": "/static/fruit_avatar/Fruit-15.png",
"global_key": "baoti",
"name": "baoti",
"id": 85544
},
"owner_id": 85544,
"project": {
"id": 67965,
"name": "Coding-API",
"owner_id": 84337
},
"project_id": 67965,
"status": 1,
"updated_at": 1426579942000,
"deadline": "",
"has_description": true
}
]
}
}
2.5.0 webhook 列表
GET /api/user/{user_name}/project/{project_name}/git/hooks
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
Response:
{
"code": 0,
"data": [
{
"depot_id": 20658,
"hook_url": "http://abc.coding.net",
"type": 1,
"token": "",
"status": 0,
"created_at": 1431511538877,
"updated_at": 1431511538877,
"send_type": 3,
"id": 174
},
{
"depot_id": 20658,
"hook_url": "https://api-doc.coding.io",
"type": 1,
"token": "hjklzxcqaw3422345",
"status": 0,
"created_at": 1431511574722,
"updated_at": 1431511574722,
"send_type": 3,
"id": 175
}
]
}
2.5.1 增加 webhook
POST /api/user/{user_name}/project/{project_name}/git/hook/{hook_id}
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
表单字段 | 数据类型 | 说明 |
---|---|---|
hook_url | string | webhook 链接 |
token | string | 自定义 webhook 秘钥 |
type_push | boolean | push代码 通知开关 |
type_mr_pr | boolean | MR/PR 通知开关 |
type_topic | boolean | 发布讨论 通知开关 |
type_member | boolean | 成员变动 通知开关 |
type_comment | boolean | 发表评论 通知开关 |
type_document | boolean | 文档 通知开关 |
type_watch | boolean | 项目被关注 通知开关 |
type_star | boolean | 项目被加星 通知开关 |
type_task | boolean | 项目任务 通知开关 |
Response:
{
"code": 0
}
2.5.2 获取 webhook
GET /api/user/{user_name}/project/{project_name}/git/hook/{hook_id}
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
hook_id | int | webhook id |
Response:
{
"code": 0,
"data": {
"depot_id": 20658,
"hook_url": "http://abc.coding.net",
"type": 1,
"token": "",
"status": 0,
"created_at": 1431511538877,
"updated_at": 1431511538877,
"send_type": 3,
"id": 174
}
}
2.5.3 编辑 webhook
PUT /api/user/{user_name}/project/{project_name}/git/hook/{hook_id}
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
hook_id | int | webhook id |
表单字段 | 数据类型 | 说明 |
---|---|---|
hook_url | string | webhook 链接 |
token | string | 自定义 webhook 秘钥 |
type_push | boolean | push代码 通知开关 |
type_mr_pr | boolean | MR/PR 通知开关 |
type_topic | boolean | 发布讨论 通知开关 |
type_member | boolean | 成员变动 通知开关 |
type_comment | boolean | 发表评论 通知开关 |
type_document | boolean | 文档 通知开关 |
type_watch | boolean | 项目被关注 通知开关 |
type_star | boolean | 项目被加星 通知开关 |
type_task | boolean | 项目任务 通知开关 |
Response:
{
"code": 0
}
2.5.4 删除 webhook
DELETE /api/user/{user_name}/project/{project_name}/git/hook/{hook_id}
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
hook_id | int | webhook id |
Response:
{
"code": 0
}
2.6.0 从 branch 名称查询 commit sha
GET /api/user/{user_name}/project/{project_name}/git/tree/{branch_name}
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
branch_name | string | 分支名称 |
Response:
{
"code": 0,
"data": {
"ref": "master",
"lastCommitter": {
"name": "ZXX_ABC",
"email": "kcccss111@gmail.com",
"avatar": "https://dn-coding-net-production-static.qbox.me/0174e523-963b-4cfb-a2ef-d4f0efea3465.jpg?imageMogr2/auto-orient/format/jpeg/crop/!128x128a0a0",
"link": "/u/zxx_sse"
},
"files": [
{
"mode": "file",
"path": "README.md",
"name": "README.md",
"flatten_path": "README.md"
}
],
"can_edit": true,
"isHead": true,
"headCommit": {
"fullMessage": "new file abc.md",
"shortMessage": "new file abc.md\n",
"allMessage": "",
"commitId": "8a305b5304a0eab0c58ea861dbb1b760a72ea9a8",
"commitTime": 1431057342000,
"committer": {
"name": "ZXX_ABC",
"email": "kcccss111@gmail.com",
"avatar": "https://dn-coding-net-production-static.qbox.me/0174e523-963b-4cfb-a2ef-d4f0efea3465.jpg?imageMogr2/auto-orient/format/jpeg/crop/!128x128a0a0",
"link": "/u/zxx_sse"
},
"notesCount": 0
},
"readme": {
"data": "#abcawerq\n",
"lang": "markdown",
"size": 10,
"previewed": true,
"preview": "<h1>abcawerq</h1>",
"lastCommitMessage": "Initial commit\n",
"lastCommitDate": 1431057300000,
"lastCommitId": "48b65a3b85ab65974f4d64da0f27d7e757561198",
"lastCommitter": {
"name": "ZXX_ABC",
"email": "kcccss111@gmail.com",
"avatar": "https://dn-coding-net-production-static.qbox.me/0174e523-963b-4cfb-a2ef-d4f0efea3465.jpg?imageMogr2/auto-orient/format/jpeg/crop/!128x128a0a0",
"link": "/u/zxx_sse"
},
"mode": "file",
"path": "README.md",
"name": "README.md",
"flatten_path": "README.md"
},
"lastCommit": {
"fullMessage": "new file abc.md",
"shortMessage": "new file abc.md\n",
"allMessage": "",
"commitId": "8a305b5304a0eab0c58ea861dbb1b760a72ea9a8",
"commitTime": 1431057342000,
"committer": {
"name": "ZXX_ABC",
"email": "kcccss111@gmail.com",
"avatar": "https://dn-coding-net-production-static.qbox.me/0174e523-963b-4cfb-a2ef-d4f0efea3465.jpg?imageMogr2/auto-orient/format/jpeg/crop/!128x128a0a0",
"link": "/u/zxx_sse"
},
"notesCount": 0
}
}
}
2.7.0 添加部署公钥
POST /api/user/{user_name}/project/{project_name}/git/deploy_key
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
表单字段 | 数据类型 | 说明 |
---|---|---|
title | string | 公钥名 |
content | string | 公钥内容 |
Response:
{
"code": 0,
"data": {
"id": 2781,
"owner_id": 31828,
"content": "ssh-rsa qwertyuiopas...... qwertyuiopasdfghjkl",
"finger_print": "ef:03:d4:9d:d3:7d:bb:6d:ac:c3:99:9a:10:a9:32:4d",
"type": "deploy",
"title": "coding-abc",
"created_at": 1431509572347
}
}
2.8.0 读取 repo 某个文件
GET /api/user/{user_name}/project/{project_name}/git/blob/{branch_name}/{file_path}
参数 | 数据类型 | 说明 |
---|---|---|
user_name | string | 项目所有者在 Coding 的用户名,即 global_key |
project_name | string | 项目名称 |
branch_name | string | 分支名称 |
file_path | string | 文件在 repo 中的路径 ( 包含文件名 ) |
Response:
{
"code": 0,
"data": {
"ref": "master",
"file": {
"data": "hello world!!!", //文件内容
"lang": "",
"size": 14,
"previewed": false,
"lastCommitMessage": "new hello file\n",
"lastCommitDate": 1500350251000,
"lastCommitId": "899c1a848a1eaa8e925fa1aeaef084447f4e7673",
"lastCommitter": {
"name": "Coding",
"email": "coding@coding.net",
"avatar": "https://dn-coding-net-production-static.qbox.me/512b2a62-956b-4ef8-8e84-b3c66e71468f.png?imageMogr2/auto-orient/format/png/crop/!300x300a0a0",
"link": "/u/coding"
},
"mode": "file",
"path": "hello",
"name": "hello"
},
"isHead": true,
"can_edit": false,
"headCommit": {
"fullMessage": "new hello file",
"shortMessage": "new hello file\n",
"allMessage": "",
"commitId": "52545e0a252f79b62a46f54dc087b0719ffa641b",
"commitTime": 1502101718000,
"committer": {
"name": "Coding",
"email": "coding@coding.net",
"avatar": "https://dn-coding-net-production-static.qbox.me/512b2a62-956b-4ef8-8e84-b3c66e71468f.png?imageMogr2/auto-orient/format/png/crop/!300x300a0a0",
"link": "/u/coding"
},
"notesCount": 0
}
}
}
当前内容版权归 coding.net 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 coding.net .