Documentation ¶
Index ¶
- Constants
- func CheckReponse(r *http.Response, data []byte) error
- type Client
- type Commit
- type Committer
- type ErrorResponse
- type File
- type Hook
- type HookForm
- type HookService
- func (s *HookService) CreateHook(owner, project string, hook *HookForm) error
- func (s *HookService) DeleteHook(owner, project string, hookID int) error
- func (s *HookService) EditHook(owner, project string, hookID int, hook *HookForm) error
- func (s *HookService) GetHook(owner, project string, hookID int) (*Hook, error)
- func (s *HookService) ListHooks(owner, project string) ([]*Hook, error)
- type Key
- type Project
- type ProjectService
- func (s *ProjectService) CreateDeployKey(owner, project string, key *Key) error
- func (s *ProjectService) DeleteKey(owner string, keyID int) error
- func (s *ProjectService) GetCommit(owner, project string, branch string) (*Commit, error)
- func (s *ProjectService) GetProject(owner, project string) (*Project, error)
- func (s *ProjectService) GetProjectRaw(owner, project, path, branch string) ([]byte, error)
- func (s *ProjectService) GetUserProjects() ([]*Project, error)
- func (s *ProjectService) ListDeployKeys(owner, project string) ([]*Key, error)
Constants ¶
const ( DefaultTimeout = 30 * time.Second DafaultApiPath = "https://coding.net/api" )
Variables ¶
This section is empty.
Functions ¶
func CheckReponse ¶
CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.
Types ¶
type Client ¶
type Client struct { Client *http.Client AccessToken string APIPath string ProjectService *ProjectService HookService *HookService }
Client is a local Client client.
func NewClientTimeout ¶
NewClientTimeout acts like NewClient but takes a timeout.
func (*Client) Do ¶
Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.
func (*Client) NewRequest ¶
NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.
type Commit ¶
type Commit struct { FullMessage string `json:"fullMessage"` // "fullMessage":"new file abs.client.md", ShortMessage string `json:"shortMessage"` // "shortMessage":"new file abs.client.md\n", AllMessage string `json:"allMessage"` // "allMessage":"", CommitID string `json:"commitId"` // "commitId":"8a305b5304a0eab0c58ea861dbb1b760a72ea9a8", CommitTime int64 `json:"commitTime"` // "commitTime":1431057342000, Committer *Committer `json:"committer"` // "committer": NotesCount int `json:"notesCount"` // "notesCount":0 }
type Committer ¶
type Committer struct { Name string `json:"name"` // "name":"ZXX_ABC", Email string `json:"email"` // "email":"kcccss111@gmail.com", Avatar string `json:"avatar"` // "avatar":"https://dn-coding-net-production-statis.client.qbox.me/0174e523-963b-4cfb-a2ef-d4f0efea3465.jpg?imageMogr2/auto-orient/format/jpeg/crop/!128x128a0a0", Link string `json:"link"` // "link":"/u/zxx_sse" }
type ErrorResponse ¶
type ErrorResponse struct { Response *http.Response Code int `json:"code"` Msg map[string]string `json:"msg"` }
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type Hook ¶
type Hook struct { DepotID int `json:"depot_id"` HookURL string `json:"hook_url"` Type int `json:"type"` // "type":1, Token string `json:"token"` // "token":"", Status int `json:"status"` // "status":0, CreatedAt int64 `json:"created_at"` // "created_at":1431511538877, UpdatedAt int64 `json:"updated_at"` // "updated_at":1431511538877, SendType int `json:"send_type"` // "send_type":3, ID int `json:"id"` // "id":174 }
type HookForm ¶
type HookForm struct { HookURL string `url:"hook_url"` // hook_url string webhook 链接 Token string `url:"token"` // token string 自定义 webhook 秘钥 TypePush bool `url:"type_push"` // type_push boolean push代码 通知开关 TypeMR_PR bool `url:"type_mr_pr"` // type_mr_pr boolean MR/PR 通知开关 TypeTopic bool `url:"type_topic"` // type_topic boolean 发布讨论 通知开关 TypeMember bool `url:"type_member"` // type_member boolean 成员变动 通知开关 TypeComment bool `url:"type_comment"` // type_comment boolean 发表评论 通知开关 TypeDocument bool `url:"type_document"` // type_document boolean 文档 通知开关 TypeWatch bool `url:"type_watch"` // type_watch boolean 项目被关注 通知开关 TypeStar bool `url:"type_star"` // type_star boolean 项目被加星 通知开关 TypeTask bool `url:"type_task"` // type_task boolean 项目任务 通知开关 }
type HookService ¶
type HookService struct {
// contains filtered or unexported fields
}
func (*HookService) CreateHook ¶
func (s *HookService) CreateHook(owner, project string, hook *HookForm) error
增加 webhook ( scope=project, project:depot ) API: POST /api/user/{user_name}/project/{project_name}/git/hook/{hook_id}
func (*HookService) DeleteHook ¶
func (s *HookService) DeleteHook(owner, project string, hookID int) error
删除 webhook ( scope=project, project:depot ) API: DELETE /api/user/{user_name}/project/{project_name}/git/hook
func (*HookService) EditHook ¶
func (s *HookService) EditHook(owner, project string, hookID int, hook *HookForm) error
编辑 webhook ( scope=project, project:depot ) API: PUT /api/user/{user_name}/project/{project_name}/git/hook/{hook_id}
type Key ¶
type Key struct { Title string `url:"title" json:"title"` Content string `url:"content" json:"content"` ID int `url:"-" json:"id"` // "id":2781, OwnerID int `url:"-" json:"owner_id"` // "owner_id":31828, FingerPrint string `url:"-" json:"finger_print"` // "finger_print":"ef:03:d4:9d:d3:7d:bb:6d:ac:c3:99:9a:10:a9:32:4d", Type string `url:"-" json:"type"` // "type":"deploy", CreatedAt int64 `url:"-" json:"created_at"` // "created_at":1431509572347 }
type Project ¶
type Project struct { CreatedAt int64 `json:"created_at"` // "created_at": 1426246044000 BackendProjectPath string `json:"backend_project_path"` // "backend_project_path": "/user/baoti/project/Coding-API", Description string `json:"description"` // "description": "Coding 的 API 是啥样呢?瞧一瞧,看一看。\n注意:由于官方未提供 API 文档,此处 API 整理自 Coding-Android 项目源码。\n尚未对照 IOS 客户端源码。请前往演示, 或转至 http://coding-api.coding.io/ 以查看当前整理的 API.", GitURL string `json:"git_url"` // "git_url": "git://coding.net/baoti/Coding-API.git", SshURL string `json:"ssh_url"` // "ssh_url": "git@coding.net:baoti/Coding-API.git", IsPublic bool `json:"is_public"` // "is_public": true, HttpsURL string `json:"https_url"` // "https_url": "https://coding.net/baoti/Coding-API.git", ID int64 `json:"id"` // "id": 67965, Name string `json:"name"` // "name": "Coding-API", OwnerID int64 `json:"owner_id"` // "owner_id": 84337, OwnerUserName string `json:"owner_user_name"` // "owner_user_name": "baoti", OwnerUserPicture string `json:"owner_user_picture"` // "owner_user_picture": "/static/fruit_avatar/Fruit-2.png", OwnerUserHome string `json:"owner_user_home"` // "owner_user_home": "<a href=\"https://coding.net/u/baoti\">baoti</a>", ProjectPath string `json:"project_path"` // "project_path": "/u/baoti/p/Coding-API", Status int `json:"status"` // "status": 1, Type int `json:"type"` // "type": 1, UpdatedAt int64 `json:"updated_at"` // "updated_at": 1426576642885, LastUpdated int64 `json:"last_updated"` // "last_updated": 1426576630625, ForkCount int `json:"fork_count"` // "fork_count": 0, StarCount int `json:"star_count"` // "star_count": 2, WatchCount int `json:"watch_count"` // "watch_count": 5, Pin bool `json:"pin"` // "pin": false, DepotPath string `json:"depot_path"` // "depot_path": "/u/baoti/p/Coding-API/git", Forked bool `json:"forked"` // "forked": false, UnReadActivitiesCount int `json:"un_read_activities_count"` // "un_read_activities_count": 0, Icon string `json:"icon"` // "icon": "/static/project_icon/scenery-23.png", CurrentUserRoleID int `json:"current_user_role_id"` // "current_user_role_id": 100, CurrentUserRole string `json:"current_user_role"` // "current_user_role": "owner", Stared bool `json:"stared"` // "stared": false, Watched bool `json:"watched"` // "watched": false, Recommended int `json:"recommended"` // "recommended": 1, MaxMember int `json:"max_member"` // "max_member": 10, GroupID int `json:"groupId"` // "groupId": 0 }
type ProjectService ¶
type ProjectService struct {
// contains filtered or unexported fields
}
func (*ProjectService) CreateDeployKey ¶
func (s *ProjectService) CreateDeployKey(owner, project string, key *Key) error
生成部署公钥 ( scope=project, project:depot ) API: POST /api/user/{user_name}/project/{project_name}/git/deploy_key
func (*ProjectService) DeleteKey ¶
func (s *ProjectService) DeleteKey(owner string, keyID int) error
删除部署公钥 ( scope=project, project:depot ) API: DELETE /api/user/{user_name}/key/{id}
func (*ProjectService) GetCommit ¶
func (s *ProjectService) GetCommit(owner, project string, branch string) (*Commit, error)
从 branch 名称查询 commit ( scope=project, project:depot ) API: GET /api/user/{user_name}/project/{project_name}/git/tree/{branch_name}
func (*ProjectService) GetProject ¶
func (s *ProjectService) GetProject(owner, project string) (*Project, error)
API: GET /api/user/{user_name}/project/{project_name}
func (*ProjectService) GetProjectRaw ¶
func (s *ProjectService) GetProjectRaw(owner, project, path, branch string) ([]byte, error)
读取 repo 某个文件 ( scope=project, project:depot ) API: GET /api/user/{user_name}/project/{project_name}/git/bolb/{branch_name}/{file_path}
func (*ProjectService) GetUserProjects ¶
func (s *ProjectService) GetUserProjects() ([]*Project, error)
用户的项目列表 ( scope=project ) API: GET /api/user/projects
func (*ProjectService) ListDeployKeys ¶
func (s *ProjectService) ListDeployKeys(owner, project string) ([]*Key, error)
API: GET /user/{user_name}/project/{project_name}/git/deploy_keys