forked from ktrysmt/go-bitbucket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commits.go
77 lines (62 loc) · 2.63 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package bitbucket
import (
"encoding/json"
"net/url"
)
type Commits struct {
c *Client
}
func (cm *Commits) GetCommits(cmo *CommitsOptions) (interface{}, error) {
urlStr := cm.c.requestUrl("/repositories/%s/%s/commits/%s", cmo.Owner, cmo.RepoSlug, cmo.Branchortag)
urlStr += cm.buildCommitsQuery(cmo.Include, cmo.Exclude)
return cm.c.executePaginated("GET", urlStr, "", cmo.Page)
}
func (cm *Commits) GetCommit(cmo *CommitsOptions) (interface{}, error) {
urlStr := cm.c.requestUrl("/repositories/%s/%s/commit/%s", cmo.Owner, cmo.RepoSlug, cmo.Revision)
return cm.c.execute("GET", urlStr, "")
}
func (cm *Commits) GetCommitComments(cmo *CommitsOptions) (interface{}, error) {
urlStr := cm.c.requestUrl("/repositories/%s/%s/commit/%s/comments", cmo.Owner, cmo.RepoSlug, cmo.Revision)
return cm.c.executePaginated("GET", urlStr, "", nil)
}
func (cm *Commits) GetCommitComment(cmo *CommitsOptions) (interface{}, error) {
urlStr := cm.c.requestUrl("/repositories/%s/%s/commit/%s/comments/%s", cmo.Owner, cmo.RepoSlug, cmo.Revision, cmo.CommentID)
return cm.c.execute("GET", urlStr, "")
}
func (cm *Commits) GetCommitStatuses(cmo *CommitsOptions) (interface{}, error) {
urlStr := cm.c.requestUrl("/repositories/%s/%s/commit/%s/statuses", cmo.Owner, cmo.RepoSlug, cmo.Revision)
return cm.c.executePaginated("GET", urlStr, "", nil)
}
func (cm *Commits) GetCommitStatus(cmo *CommitsOptions, commitStatusKey string) (interface{}, error) {
urlStr := cm.c.requestUrl("/repositories/%s/%s/commit/%s/statuses/build/%s", cmo.Owner, cmo.RepoSlug, cmo.Revision, commitStatusKey)
return cm.c.execute("GET", urlStr, "")
}
func (cm *Commits) GiveApprove(cmo *CommitsOptions) (interface{}, error) {
urlStr := cm.c.requestUrl("/repositories/%s/%s/commit/%s/approve", cmo.Owner, cmo.RepoSlug, cmo.Revision)
return cm.c.execute("POST", urlStr, "")
}
func (cm *Commits) RemoveApprove(cmo *CommitsOptions) (interface{}, error) {
urlStr := cm.c.requestUrl("/repositories/%s/%s/commit/%s/approve", cmo.Owner, cmo.RepoSlug, cmo.Revision)
return cm.c.execute("DELETE", urlStr, "")
}
func (cm *Commits) CreateCommitStatus(cmo *CommitsOptions, cso *CommitStatusOptions) (interface{}, error) {
urlStr := cm.c.requestUrl("/repositories/%s/%s/commit/%s/statuses/build", cmo.Owner, cmo.RepoSlug, cmo.Revision)
data, err := json.Marshal(cso)
if err != nil {
return nil, err
}
return cm.c.execute("POST", urlStr, string(data))
}
func (cm *Commits) buildCommitsQuery(include, exclude string) string {
p := url.Values{}
if include != "" {
p.Add("include", include)
}
if exclude != "" {
p.Add("exclude", exclude)
}
if res := p.Encode(); len(res) > 0 {
return "?" + res
}
return ""
}