forked from go-jira/jira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.go
38 lines (32 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
38
package jira
import (
"bytes"
"encoding/json"
"fmt"
"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 := fmt.Sprintf("%s/rest/api/2/component", endpoint)
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, readJSON(resp.Body, results)
}
return nil, responseError(resp)
}