woodpecker/client/repos.go

57 lines
1.6 KiB
Go
Raw Normal View History

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}
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{}
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)
2014-08-09 23:51:08 +00:00
return s.run("DELETE", path, nil, nil)
}
// 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
}