woodpecker/client/commits.go

53 lines
1.8 KiB
Go
Raw Normal View History

2014-08-09 23:51:08 +00:00
package client
import (
"fmt"
"io"
"github.com/drone/drone/shared/model"
)
type CommitService struct {
*Client
}
2014-09-29 01:38:21 +00:00
// GET /api/repos/{host}/{owner}/{name}/branch/{branch}/commit/{commit}
2014-08-09 23:51:08 +00:00
func (s *CommitService) Get(host, owner, name, branch, sha string) (*model.Commit, error) {
2014-09-29 01:38:21 +00:00
var path = fmt.Sprintf("/api/repos/%s/%s/%s/branches/%s/commits/%s", host, owner, name, branch, sha)
2014-08-09 23:51:08 +00:00
var commit = model.Commit{}
var err = s.run("GET", path, nil, &commit)
return &commit, err
}
2014-09-29 01:38:21 +00:00
// GET /api/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}/console
2014-08-09 23:51:08 +00:00
func (s *CommitService) GetOutput(host, owner, name, branch, sha string) (io.ReadCloser, error) {
2014-09-29 01:38:21 +00:00
var path = fmt.Sprintf("/api/repos/%s/%s/%s/branches/%s/commits/%s/console", host, owner, name, branch, sha)
2014-08-09 23:51:08 +00:00
resp, err := s.do("GET", path)
if err != nil {
return nil, nil
}
return resp.Body, nil
}
2014-09-29 01:38:21 +00:00
// POST /api/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}?action=rebuild
2014-08-09 23:51:08 +00:00
func (s *CommitService) Rebuild(host, owner, name, branch, sha string) error {
2014-09-29 01:38:21 +00:00
var path = fmt.Sprintf("/api/repos/%s/%s/%s/branches/%s/commits/%s?action=rebuild", host, owner, name, branch, sha)
2014-08-09 23:51:08 +00:00
return s.run("POST", path, nil, nil)
}
2014-09-29 01:38:21 +00:00
// GET /api/repos/{host}/{owner}/{name}/feed
2014-08-09 23:51:08 +00:00
func (s *CommitService) List(host, owner, name string) ([]*model.Commit, error) {
2014-09-29 01:38:21 +00:00
var path = fmt.Sprintf("/api/repos/%s/%s/%s/feed", host, owner, name)
2014-08-09 23:51:08 +00:00
var list []*model.Commit
var err = s.run("GET", path, nil, &list)
return list, err
}
2014-09-29 01:38:21 +00:00
// GET /api/repos/{host}/{owner}/{name}/branch/{branch}
2014-08-09 23:51:08 +00:00
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)
2014-08-09 23:51:08 +00:00
var list []*model.Commit
var err = s.run("GET", path, nil, &list)
return list, err
}