2014-08-09 23:51:08 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/drone/drone/shared/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RepoService struct {
|
|
|
|
*Client
|
|
|
|
}
|
|
|
|
|
2014-09-29 01:38:21 +00:00
|
|
|
// GET /api/repos/{host}/{owner}/{name}
|
2014-08-09 23:55:51 +00:00
|
|
|
func (s *RepoService) Get(host, owner, name string) (*model.Repo, error) {
|
2014-09-29 01:38:21 +00:00
|
|
|
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
|
2014-08-09 23:51:08 +00:00
|
|
|
var repo = model.Repo{}
|
2015-01-15 08:22:33 +00:00
|
|
|
var err = s.run("GET", path, nil, &repo)
|
2014-08-09 23:51:08 +00:00
|
|
|
return &repo, err
|
|
|
|
}
|
|
|
|
|
2014-09-29 01:38:21 +00:00
|
|
|
// PUT /api/repos/{host}/{owner}/{name}
|
2014-08-09 23:51:08 +00:00
|
|
|
func (s *RepoService) Update(repo *model.Repo) (*model.Repo, error) {
|
2014-09-29 01:38:21 +00:00
|
|
|
var path = fmt.Sprintf("/api/repos/%s/%s/%s", repo.Host, repo.Owner, repo.Name)
|
2014-08-09 23:51:08 +00:00
|
|
|
var result = model.Repo{}
|
|
|
|
var err = s.run("PUT", path, &repo, &result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2014-09-29 01:38:21 +00:00
|
|
|
// POST /api/repos/{host}/{owner}/{name}
|
2014-08-09 23:51:08 +00:00
|
|
|
func (s *RepoService) Enable(host, owner, name string) error {
|
2014-09-29 01:38:21 +00:00
|
|
|
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
|
2014-08-09 23:51:08 +00:00
|
|
|
return s.run("POST", path, nil, nil)
|
|
|
|
}
|
|
|
|
|
2014-09-29 01:38:21 +00:00
|
|
|
// DELETE /api/repos/{host}/{owner}/{name}
|
2014-08-09 23:51:08 +00:00
|
|
|
func (s *RepoService) Disable(host, owner, name string) error {
|
2014-09-29 01:38:21 +00:00
|
|
|
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
|
2015-02-05 14:27:26 +00:00
|
|
|
return s.run("PATCH", path, nil, nil)
|
2014-08-09 23:51:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-04 13:42:24 +00:00
|
|
|
// DELETE /api/repos/{host}/{owner}/{name}?remove=true
|
|
|
|
func (s *RepoService) Delete(host, owner, name string) error {
|
2015-02-05 14:27:26 +00:00
|
|
|
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
|
2015-02-04 13:42:24 +00:00
|
|
|
return s.run("DELETE", path, nil, nil)
|
|
|
|
}
|
|
|
|
|
2015-01-04 23:21:35 +00:00
|
|
|
// PUT /api/repos/{host}/{owner}/{name}
|
|
|
|
func (s *RepoService) SetKey(host, owner, name, pub, priv string) error {
|
|
|
|
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
|
|
|
|
var in = struct {
|
|
|
|
PublicKey string `json:"public_key"`
|
|
|
|
PrivateKey string `json:"private_key"`
|
|
|
|
}{pub, priv}
|
|
|
|
return s.run("PUT", path, &in, nil)
|
|
|
|
}
|
|
|
|
|
2014-09-29 01:38:21 +00:00
|
|
|
// GET /api/user/repos
|
2014-08-09 23:51:08 +00:00
|
|
|
func (s *RepoService) List() ([]*model.Repo, error) {
|
|
|
|
var repos []*model.Repo
|
2014-09-29 01:38:21 +00:00
|
|
|
var err = s.run("GET", "/api/user/repos", nil, &repos)
|
2014-08-09 23:51:08 +00:00
|
|
|
return repos, err
|
|
|
|
}
|