forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repos.go
62 lines (52 loc) · 1.81 KB
/
repos.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package client
import (
"fmt"
"github.com/drone/drone/shared/model"
)
type RepoService struct {
*Client
}
// GET /api/repos/{host}/{owner}/{name}
func (s *RepoService) Get(host, owner, name string) (*model.Repo, error) {
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
var repo = model.Repo{}
var err = s.run("GET", path, nil, &repo)
return &repo, err
}
// PUT /api/repos/{host}/{owner}/{name}
func (s *RepoService) Update(repo *model.Repo) (*model.Repo, error) {
var path = fmt.Sprintf("/api/repos/%s/%s/%s", repo.Host, repo.Owner, repo.Name)
var result = model.Repo{}
var err = s.run("PUT", path, &repo, &result)
return &result, err
}
// POST /api/repos/{host}/{owner}/{name}
func (s *RepoService) Enable(host, owner, name string) error {
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
return s.run("POST", path, nil, nil)
}
// POST /api/repos/{host}/{owner}/{name}/deactivate
func (s *RepoService) Disable(host, owner, name string) error {
var path = fmt.Sprintf("/api/repos/%s/%s/%s/deactivate", host, owner, name)
return s.run("POST", path, nil, nil)
}
// DELETE /api/repos/{host}/{owner}/{name}?remove=true
func (s *RepoService) Delete(host, owner, name string) error {
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
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)
}
// GET /api/user/repos
func (s *RepoService) List() ([]*model.Repo, error) {
var repos []*model.Repo
var err = s.run("GET", "/api/user/repos", nil, &repos)
return repos, err
}