-
Notifications
You must be signed in to change notification settings - Fork 146
/
pipelines.go
115 lines (98 loc) · 2.68 KB
/
pipelines.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package bitbucket
import (
"fmt"
"io/ioutil"
"net/url"
)
type Pipelines struct {
c *Client
}
func (p *Pipelines) List(po *PipelinesOptions) (interface{}, error) {
urlStr := p.c.requestUrl("/repositories/%s/%s/pipelines/", po.Owner, po.RepoSlug)
if po.Query != "" {
parsed, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
query := parsed.Query()
query.Set("q", po.Query)
parsed.RawQuery = query.Encode()
urlStr = parsed.String()
}
if po.Sort != "" {
parsed, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
query := parsed.Query()
query.Set("sort", po.Sort)
parsed.RawQuery = query.Encode()
urlStr = parsed.String()
}
if po.Page != 0 {
parsed, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
query := parsed.Query()
query.Set("page", fmt.Sprint(po.Page))
parsed.RawQuery = query.Encode()
urlStr = parsed.String()
}
return p.c.executePaginated("GET", urlStr, "", nil)
}
func (p *Pipelines) Get(po *PipelinesOptions) (interface{}, error) {
urlStr := p.c.requestUrl("/repositories/%s/%s/pipelines/%s", po.Owner, po.RepoSlug, po.IDOrUuid)
return p.c.execute("GET", urlStr, "")
}
func (p *Pipelines) ListSteps(po *PipelinesOptions) (interface{}, error) {
urlStr := p.c.requestUrl("/repositories/%s/%s/pipelines/%s/steps/", po.Owner, po.RepoSlug, po.IDOrUuid)
if po.Query != "" {
parsed, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
query := parsed.Query()
query.Set("q", po.Query)
parsed.RawQuery = query.Encode()
urlStr = parsed.String()
}
if po.Sort != "" {
parsed, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
query := parsed.Query()
query.Set("sort", po.Sort)
parsed.RawQuery = query.Encode()
urlStr = parsed.String()
}
if po.Page != 0 {
parsed, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
query := parsed.Query()
query.Set("page", fmt.Sprint(po.Page))
parsed.RawQuery = query.Encode()
urlStr = parsed.String()
}
return p.c.executePaginated("GET", urlStr, "", nil)
}
func (p *Pipelines) GetStep(po *PipelinesOptions) (interface{}, error) {
urlStr := p.c.requestUrl("/repositories/%s/%s/pipelines/%s/steps/%s", po.Owner, po.RepoSlug, po.IDOrUuid, po.StepUuid)
return p.c.execute("GET", urlStr, "")
}
func (p *Pipelines) GetLog(po *PipelinesOptions) (string, error) {
urlStr := p.c.requestUrl("/repositories/%s/%s/pipelines/%s/steps/%s/log", po.Owner, po.RepoSlug, po.IDOrUuid, po.StepUuid)
responseBody, err := p.c.executeRaw("GET", urlStr, "")
if err != nil {
return "", err
}
defer responseBody.Close()
rawBody, err := ioutil.ReadAll(responseBody)
if err != nil {
return "", err
}
return string(rawBody), nil
}