mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-02-07 13:31:38 +02:00
feat: Implement issue link type POST
This commit is contained in:
parent
57538b926c
commit
75b9df8b01
@ -1,6 +1,10 @@
|
||||
package jira
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// IssueLinkTypeService handles issue link types for the JIRA instance / API.
|
||||
//
|
||||
@ -44,3 +48,33 @@ func (s *IssueLinkTypeService) Get(ID string) (*IssueLinkType, *Response, error)
|
||||
}
|
||||
return linkType, resp, nil
|
||||
}
|
||||
|
||||
// Create creates an issue link type in JIRA.
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-post
|
||||
func (s *IssueLinkTypeService) Create(linkType *IssueLinkType) (*IssueLinkType, *Response, error) {
|
||||
apiEndpoint := "/rest/api/2/issueLinkType"
|
||||
req, err := s.client.NewRequest("POST", apiEndpoint, linkType)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
resp, err := s.client.Do(req, nil)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
responseLinkType := new(IssueLinkType)
|
||||
defer resp.Body.Close()
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
e := fmt.Errorf("Could not read the returned data")
|
||||
return nil, resp, NewJiraError(resp, e)
|
||||
}
|
||||
err = json.Unmarshal(data, responseLinkType)
|
||||
if err != nil {
|
||||
e := fmt.Errorf("Could no unmarshal the data into struct")
|
||||
return nil, resp, NewJiraError(resp, e)
|
||||
}
|
||||
return linkType, resp, nil
|
||||
}
|
||||
|
@ -48,3 +48,28 @@ func TestIssueLinkTypeService_Get(t *testing.T) {
|
||||
t.Error("Expected linkType. LinkType is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueLinkTypeService_Create(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testMux.HandleFunc("/rest/api/2/issueLinkType", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "POST")
|
||||
testRequestURL(t, r, "/rest/api/2/issueLinkType")
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
fmt.Fprint(w, `{"id":"10021","name":"Problem/Incident","inward":"is caused by",
|
||||
"outward":"causes","self":"https://www.example.com/jira/rest/api/2/issueLinkType/10021"}`)
|
||||
})
|
||||
|
||||
lt := &IssueLinkType{
|
||||
Name: "Problem/Incident",
|
||||
Inward: "is caused by",
|
||||
Outward: "causes",
|
||||
}
|
||||
|
||||
if linkType, _, err := testClient.IssueLinkType.Create(lt); err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
} else if linkType == nil {
|
||||
t.Error("Expected linkType. LinkType is nil")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user