forked from harness/gitness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commits.go
52 lines (44 loc) · 1.76 KB
/
commits.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
package client
import (
"fmt"
"io"
"github.com/drone/drone/shared/model"
)
type CommitService struct {
*Client
}
// GET /api/repos/{host}/{owner}/{name}/branch/{branch}/commit/{commit}
func (s *CommitService) Get(host, owner, name, branch, sha string) (*model.Commit, error) {
var path = fmt.Sprintf("/api/repos/%s/%s/%s/branches/%s/commits/%s", host, owner, name, branch, sha)
var commit = model.Commit{}
var err = s.run("GET", path, nil, &commit)
return &commit, err
}
// GET /api/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}/console
func (s *CommitService) GetOutput(host, owner, name, branch, sha string) (io.ReadCloser, error) {
var path = fmt.Sprintf("/api/repos/%s/%s/%s/branches/%s/commits/%s/console", host, owner, name, branch, sha)
resp, err := s.do("GET", path)
if err != nil {
return nil, nil
}
return resp.Body, nil
}
// POST /api/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}?action=rebuild
func (s *CommitService) Rebuild(host, owner, name, branch, sha string) error {
var path = fmt.Sprintf("/api/repos/%s/%s/%s/branches/%s/commits/%s?action=rebuild", host, owner, name, branch, sha)
return s.run("POST", path, nil, nil)
}
// GET /api/repos/{host}/{owner}/{name}/feed
func (s *CommitService) List(host, owner, name string) ([]*model.Commit, error) {
var path = fmt.Sprintf("/api/repos/%s/%s/%s/feed", host, owner, name)
var list []*model.Commit
var err = s.run("GET", path, nil, &list)
return list, err
}
// GET /api/repos/{host}/{owner}/{name}/branch/{branch}
func (s *CommitService) ListBranch(host, owner, name, branch string) ([]*model.Commit, error) {
var path = fmt.Sprintf("/api/repos/%s/%s/%s/commits", host, owner, name)
var list []*model.Commit
var err = s.run("GET", path, nil, &list)
return list, err
}