Watch 12 Star 5 Fork 4

码云 / extension-docs

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
码云扩展需求文档与公开 API spread retract

Clone or download
RequiredAPI.md 8.74 KB
Copy Edit Web IDE Raw Blame History
Charlie authored 2017-02-22 14:51 . update API document

Extension Required API

目前码云扩展需要的 API 有以下几种,分别支持用户登陆,查看项目列表,查看项目信息,创建项目。 在开发扩展的过程中请认真阅读此文档,建议开发者在使用 API 时,使用 Restful 工具认真测试。

调试工具

| 名称 | 平台 | -------|---------|--------| | curl | 跨平台命令,git-for-windows 自带 | | DHC | Chrome Extension | | ARC | Chrome Extension | | Postman | Chrome Extension |

API 基础:

名称 参数
主机 git.oschina.net
协议 https
标识路径 api
版本 v3
URL https://git.oschina.net/api/v3

登陆 API:

规格 参数
Method POST
URL /session
Param email
pssword
Content-Type application/x-www-form-urlencoded
Example POST /session
body: email=example@ex.com&password=123456
curl --data-urlencode "email=exmaple@ex.com" --data-urlencode "password=123456" https://git.oschina.net/api/v3/session

返回值

{
    "id": 6168, 
    "username": "example", 
    "name": "example", 
    "bio": "someone", 
    "weibo": "don't knwon", 
    "blog": "https://example.com/", 
    "theme_id": 1, 
    "state": "active", 
    "created_at": "2013-06-05T22:40:38+08:00", 
    "portrait": "uploads/123455.jpg", 
    "email": "example@example.com", 
    "new_portrait": "http://git.oschina.net/uploads/xx.jpg", 
    "follow": {
        "followers": 34, 
        "starred": 5, 
        "following": 2, 
        "watched": 5
    }, 
    "private_token": "private_tokenXX", 
    "is_admin": true, 
    "can_create_group": true, 
    "can_create_project": true, 
    "can_create_team": true
}

项目列表 API:

规格 参数
Method GET
URL /projects
Param private_token (required)
page (optional)
Example GET /projects?page=1&private_token=n5Ex6

注意 Token 由 登陆 API 获得

curl -i "https://git.oschina.net/api/v3/projects?page=1&private_token=n5Ex6"

返回值

[
    {
        "id": 185064, 
        "name": "CurePHP", 
        "description": "", 
        "default_branch": "master", 
        "owner": {
            "id": 61340, 
            "username": "xsilen", 
            "email": "xsilen@163.com", 
            "name": "xsilen", 
            "state": "active", 
            "created_at": "2013-12-25T18:03:20.000+08:00", 
            "portrait": "uploads/40/61340_xsilen.png?1436280956", 
            "new_portrait": "http://git.oschina.net/uploads/40/61340_xsilen.png?1436280956"
        }, 
        "public": false, 
        "path": "CurePHP", 
        "path_with_namespace": "xsilen/CurePHP", 
        "issues_enabled": true, 
        "pull_requests_enabled": true, 
        "wiki_enabled": true, 
        "created_at": "2014-08-10T22:46:22.000+08:00", 
        "namespace": {
            "id": 57303, 
            "name": "xsilen", 
            "path": "xsilen", 
            "owner_id": 61340, 
            "created_at": "2013-12-25T18:03:20.000+08:00", 
            "updated_at": "2013-12-25T18:03:20.000+08:00", 
            "description": ""
        }, 
        "last_push_at": "2014-11-26T16:32:37.000+08:00", 
        "parent_id": null, 
        "fork?": false, 
        "forks_count": 2, 
        "stars_count": 5, 
        "watches_count": 3, 
        "language": "PHP", 
        "paas": "xsilen.oschina.mopaas.com", 
        "stared": null, 
        "watched": null, 
        "relation": null, 
        "recomm": 0, 
        "parent_path_with_namespace": null
    }, 
    {
        "id": 159511, 
        "name": "sims", 
        "description": "", 
        "default_branch": "master", 
        "owner": {
            "id": 832, 
            "username": "duguying2008", 
            "email": "duguying2008@gmail.com", 
            "name": "独孤影", 
            "state": "active", 
            "created_at": "2013-05-16T22:41:14.000+08:00", 
            "portrait": "uploads/32/832_duguying2008.png?1407111985", 
            "new_portrait": "http://git.oschina.net/uploads/32/832_duguying2008.png?1407111985"
        }, 
        "public": true, 
        "path": "sims", 
        "path_with_namespace": "duguying2008/sims", 
        "issues_enabled": true, 
        "pull_requests_enabled": false, 
        "wiki_enabled": true, 
        "created_at": "2014-06-21T11:32:11.000+08:00", 
        "namespace": {
            "id": 828, 
            "name": "duguying2008", 
            "path": "duguying2008", 
            "owner_id": 832, 
            "created_at": "2013-05-16T22:41:14.000+08:00", 
            "updated_at": "2013-05-16T22:41:14.000+08:00", 
            "description": ""
        }, 
        "last_push_at": "2014-06-22T16:26:10.000+08:00", 
        "parent_id": null, 
        "fork?": false, 
        "forks_count": 0, 
        "stars_count": 0, 
        "watches_count": 1, 
        "language": "C++", 
        "paas": null, 
        "stared": null, 
        "watched": null, 
        "relation": null, 
        "recomm": 0, 
        "parent_path_with_namespace": null
    }
]

项目信息 API:

规格 参数
Method GET
URL /projects/:project_path_with_namespace
/projects/:project_id
Param private_token (required)
project_path_with_namespace(project_id) (required)
Example GET /projects/example%2FHelloWorld?private_token=n5Ex6
curl -i  "https://git.oschina.net/api/v3/projects/example%2FHelloWorld?private_token=n5Ex6"
curl -i "https://git.oschina.net/api/v3/projects/12345?private_token=n5Ex6"

返回结果:

{
  "id": 123456,
  "name": "HelloWorld",
  "description": "HelloWorld",
  "default_branch": "master",
  "owner": {
    "id": 12345,
    "username": "example",
    "email": "example@example.net",
    "name": "example",
    "state": "active",
    "created_at": "2015-03-20T18:29:04+08:00",
    "portrait": null,
    "new_portrait": "http://secure.gravatar.com/avatar/9fca7a3200ded050cb581e4e2df18b26?s=40&d=mm"
  },
  "public": false,
  "path": "HelloWorld",
  "path_with_namespace": "example/HelloWorld",
  "issues_enabled": true,
  "pull_requests_enabled": true,
  "wiki_enabled": true,
  "created_at": "2016-05-13T12:06:36+08:00",
  "namespace": {
    "address": "192.168.1.12",
    "avatar": null,
    "created_at": "2015-03-20T18:29:05+08:00",
    "description": "",
    "email": null,
    "id": 342584,
    "location": null,
    "name": "example",
    "owner_id": 349252,
    "path": "example",
    "public": null,
    "updated_at": "2016-01-07T00:49:59+08:00",
    "url": null
  },
  "last_push_at": "2016-05-13T12:12:16+08:00",
  "parent_id": null,
  "fork?": false,
  "forks_count": 0,
  "stars_count": 0,
  "watches_count": 1,
  "language": null,
  "paas": null,
  "stared": false,
  "watched": true,
  "relation": "master",
  "recomm": 0,
  "parent_path_with_namespace": null
}

创建项目 API:

规格 参数
Method POST
URL /projects
Param private_token (required) in URL
name (required)
description (optional)
private (optional -1/0) - public by default
Example POST /projects?private_token=Axz
body: name=helloworld&description=helloworld
curl -d "name=helloworld&description=helloworld-project&private=1" "https://git.oschina.net/api/v3/projects?private_token=Axz"

如果创建成功,返回值为项目的具体信息,和上文中项目信息接口一致。

如果项目已经存在:

{
  "status": 0,
  "message": "该项目名已存在!"
}

此项目创建的是一个空仓库,开发者的初始化 ignore 文件等,需在本地操作。

注意事项

  1. 可以保存用户密码,但必须使用系统平台支持的凭据管理机制,如 Windows,需要使用 Windows 凭据管理
  2. 保存 private_token 必须加密,扩展必须考虑到 private_token 会失效,当 private_token 失效时,请重新验证。
  3. 扩展的 User-Agent 需要设置为 CC/1.0-$ExtensionValue ExtensionValue 值在附注中有标明,CC 即 Code Cloud 的缩写。

附注

ExtensionValue

扩展 参数 其他
Visual Studio VS.$Version $Version 即 VS 版本,14 或 15
IntelliJ 家族 JB.$Tools $Tools 为 Intellij Rubymine WebStorm 以及 AndroidStudio
Eclipse EC
Visual Studio Code VSC

Help Search

183227_9af5e6a8_1826025 111910_4d91f001_1826025