forked from go-jira/jira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.go
37 lines (31 loc) · 953 Bytes
/
component.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
package jira
import (
"bytes"
"encoding/json"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
)
type ComponentProvider interface {
ProvideComponent() *jiradata.Component
}
// https://docs.atlassian.com/jira/REST/cloud/#api/2/component-createComponent
func (j *Jira) CreateComponent(cp ComponentProvider) (*jiradata.Component, error) {
return CreateComponent(j.UA, j.Endpoint, cp)
}
func CreateComponent(ua HttpClient, endpoint string, cp ComponentProvider) (*jiradata.Component, error) {
req := cp.ProvideComponent()
encoded, err := json.Marshal(req)
if err != nil {
return nil, err
}
uri := URLJoin(endpoint, "rest/api/2/component")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode == 201 {
results := &jiradata.Component{}
return results, json.NewDecoder(resp.Body).Decode(results)
}
return nil, responseError(resp)
}