mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
27f57b2bbe
There should be no reason to use gopkg.in versioned imports now that we're using go modules. I think, IANAE. gopkg.in kind of gets in the way of modules, as it only pulls over tagged releases from github.com -- this then means that you need to use go modules 'replace' syntax in the go.mod to use a non-versioned commit or branch. This is feasible, but kind of ugly. go modules defaults to pulling the latest version, so the default behavior is the same as when pulling go-jira.v1 from gopkg.in.
38 lines
938 B
Go
38 lines
938 B
Go
package jira
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
|
|
"github.com/go-jira/jira/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)
|
|
}
|