|
| 1 | +package bitbucket |
| 2 | + |
| 3 | +import ( |
| 4 | + "io/ioutil" |
| 5 | + "net/url" |
| 6 | +) |
| 7 | + |
| 8 | +type Pipelines struct { |
| 9 | + c *Client |
| 10 | +} |
| 11 | + |
| 12 | +func (p *Pipelines) List(po *PipelinesOptions) (interface{}, error) { |
| 13 | + urlStr := p.c.requestUrl("/repositories/%s/%s/pipelines/", po.Owner, po.RepoSlug) |
| 14 | + |
| 15 | + if po.Query != "" { |
| 16 | + parsed, err := url.Parse(urlStr) |
| 17 | + if err != nil { |
| 18 | + return nil, err |
| 19 | + } |
| 20 | + query := parsed.Query() |
| 21 | + query.Set("q", po.Query) |
| 22 | + parsed.RawQuery = query.Encode() |
| 23 | + urlStr = parsed.String() |
| 24 | + } |
| 25 | + |
| 26 | + if po.Sort != "" { |
| 27 | + parsed, err := url.Parse(urlStr) |
| 28 | + if err != nil { |
| 29 | + return nil, err |
| 30 | + } |
| 31 | + query := parsed.Query() |
| 32 | + query.Set("sort", po.Sort) |
| 33 | + parsed.RawQuery = query.Encode() |
| 34 | + urlStr = parsed.String() |
| 35 | + } |
| 36 | + |
| 37 | + return p.c.execute("GET", urlStr, "") |
| 38 | +} |
| 39 | + |
| 40 | +func (p *Pipelines) Get(po *PipelinesOptions) (interface{}, error) { |
| 41 | + urlStr := p.c.requestUrl("/repositories/%s/%s/pipelines/%s", po.Owner, po.RepoSlug, po.IDOrUuid) |
| 42 | + return p.c.execute("GET", urlStr, "") |
| 43 | +} |
| 44 | + |
| 45 | +func (p *Pipelines) ListSteps(po *PipelinesOptions) (interface{}, error) { |
| 46 | + urlStr := p.c.requestUrl("/repositories/%s/%s/pipelines/%s/steps/", po.Owner, po.RepoSlug, po.IDOrUuid) |
| 47 | + |
| 48 | + if po.Query != "" { |
| 49 | + parsed, err := url.Parse(urlStr) |
| 50 | + if err != nil { |
| 51 | + return nil, err |
| 52 | + } |
| 53 | + query := parsed.Query() |
| 54 | + query.Set("q", po.Query) |
| 55 | + parsed.RawQuery = query.Encode() |
| 56 | + urlStr = parsed.String() |
| 57 | + } |
| 58 | + |
| 59 | + if po.Sort != "" { |
| 60 | + parsed, err := url.Parse(urlStr) |
| 61 | + if err != nil { |
| 62 | + return nil, err |
| 63 | + } |
| 64 | + query := parsed.Query() |
| 65 | + query.Set("sort", po.Sort) |
| 66 | + parsed.RawQuery = query.Encode() |
| 67 | + urlStr = parsed.String() |
| 68 | + } |
| 69 | + |
| 70 | + return p.c.execute("GET", urlStr, "") |
| 71 | +} |
| 72 | + |
| 73 | +func (p *Pipelines) GetStep(po *PipelinesOptions) (interface{}, error) { |
| 74 | + urlStr := p.c.requestUrl("/repositories/%s/%s/pipelines/%s/steps/%s", po.Owner, po.RepoSlug, po.IDOrUuid, po.StepUuid) |
| 75 | + return p.c.execute("GET", urlStr, "") |
| 76 | +} |
| 77 | + |
| 78 | +func (p *Pipelines) GetLog(po *PipelinesOptions) (string, error) { |
| 79 | + urlStr := p.c.requestUrl("/repositories/%s/%s/pipelines/%s/steps/%s/log", po.Owner, po.RepoSlug, po.IDOrUuid, po.StepUuid) |
| 80 | + responseBody, err := p.c.executeRaw("GET", urlStr, "") |
| 81 | + if err != nil { |
| 82 | + return "", err |
| 83 | + } |
| 84 | + defer responseBody.Close() |
| 85 | + |
| 86 | + rawBody, err := ioutil.ReadAll(responseBody) |
| 87 | + if err != nil { |
| 88 | + return "", err |
| 89 | + } |
| 90 | + |
| 91 | + return string(rawBody), nil |
| 92 | +} |
0 commit comments