Skip to content

Commit 261889a

Browse files
johanmeiringghostsquad
authored andcommitted
feat: Add IssueLinkTypeService with GetList and test
1 parent 40a1df2 commit 261889a

File tree

5 files changed

+183
-0
lines changed

5 files changed

+183
-0
lines changed

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
1111
github.com/trivago/tgo v1.0.1 h1:bxatjJIXNIpV18bucU4Uk/LaoxvxuOlp/oowRHyncLQ=
1212
github.com/trivago/tgo v1.0.1/go.mod h1:w4dpD+3tzNIIiIfkWWa85w5/B77tlvdZckQ+6PkFnhc=
1313
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
14+
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 h1:p/H982KKEjUnLJkM3tt/LemDnOc1GiZL5FCVlORJ5zo=
1415
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
1516
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
1617
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
18+
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
1719
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1820
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

issuelinktype.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package jira
2+
3+
// IssueLinkTypeService handles issue link types for the JIRA instance / API.
4+
//
5+
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-group-Issue-link-types
6+
type IssueLinkTypeService struct {
7+
client *Client
8+
}
9+
10+
// GetList gets all of the issue link types from JIRA.
11+
//
12+
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-get
13+
func (s *IssueLinkTypeService) GetList() ([]IssueLinkType, *Response, error) {
14+
apiEndpoint := "rest/api/2/issueLinkType"
15+
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
16+
if err != nil {
17+
return nil, nil, err
18+
}
19+
20+
linkTypeList := []IssueLinkType{}
21+
resp, err := s.client.Do(req, &linkTypeList)
22+
if err != nil {
23+
return nil, resp, NewJiraError(resp, err)
24+
}
25+
return linkTypeList, resp, nil
26+
}

issuelinktype_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package jira
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"net/http"
7+
"testing"
8+
)
9+
10+
func TestIssueLinkTypeService_GetList(t *testing.T) {
11+
setup()
12+
defer teardown()
13+
testAPIEndpoint := "/rest/api/2/issueLinkType"
14+
15+
raw, err := ioutil.ReadFile("./mocks/all_issuelinktypes.json")
16+
if err != nil {
17+
t.Error(err.Error())
18+
}
19+
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
20+
testMethod(t, r, "GET")
21+
testRequestURL(t, r, testAPIEndpoint)
22+
fmt.Fprint(w, string(raw))
23+
})
24+
25+
linkTypes, _, err := testClient.IssueLinkType.GetList()
26+
if linkTypes == nil {
27+
t.Error("Expected issueLinkType list. LinkTypes is nil")
28+
}
29+
if err != nil {
30+
t.Errorf("Error give: %s", err)
31+
}
32+
}

jira.go

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type Client struct {
5454
Role *RoleService
5555
PermissionScheme *PermissionSchemeService
5656
Status *StatusService
57+
IssueLinkType *IssueLinkTypeService
5758
}
5859

5960
// NewClient returns a new JIRA API client.
@@ -99,6 +100,7 @@ func NewClient(httpClient httpClient, baseURL string) (*Client, error) {
99100
c.Role = &RoleService{client: c}
100101
c.PermissionScheme = &PermissionSchemeService{client: c}
101102
c.Status = &StatusService{client: c}
103+
c.IssueLinkType = &IssueLinkTypeService{client: c}
102104

103105
return c, nil
104106
}

mocks/all_issuelinktypes.json

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
[
2+
{
3+
"id": "12310361",
4+
"name": "Blocked",
5+
"inward": "Blocked",
6+
"outward": "Blocked",
7+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310361"
8+
},
9+
{
10+
"id": "10032",
11+
"name": "Blocker",
12+
"inward": "is blocked by",
13+
"outward": "blocks",
14+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10032"
15+
},
16+
{
17+
"id": "12310460",
18+
"name": "Child-Issue",
19+
"inward": "is a child of",
20+
"outward": "is a parent of",
21+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310460"
22+
},
23+
{
24+
"id": "10020",
25+
"name": "Cloners",
26+
"inward": "is cloned by",
27+
"outward": "is a clone of",
28+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10020"
29+
},
30+
{
31+
"id": "12310060",
32+
"name": "Container",
33+
"inward": "Is contained by",
34+
"outward": "contains",
35+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310060"
36+
},
37+
{
38+
"id": "12310461",
39+
"name": "Dependency",
40+
"inward": "Dependency",
41+
"outward": "Dependency",
42+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310461"
43+
},
44+
{
45+
"id": "12310360",
46+
"name": "Dependent",
47+
"inward": "Dependent",
48+
"outward": "Dependent",
49+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310360"
50+
},
51+
{
52+
"id": "12310000",
53+
"name": "Duplicate",
54+
"inward": "is duplicated by",
55+
"outward": "duplicates",
56+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310000"
57+
},
58+
{
59+
"id": "12310010",
60+
"name": "Incorporates",
61+
"inward": "is part of",
62+
"outward": "incorporates",
63+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310010"
64+
},
65+
{
66+
"id": "12310462",
67+
"name": "Parent Feature",
68+
"inward": "Parent Feature",
69+
"outward": "Parent Feature",
70+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310462"
71+
},
72+
{
73+
"id": "12310560",
74+
"name": "Problem/Incident",
75+
"inward": "is caused by",
76+
"outward": "causes",
77+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310560"
78+
},
79+
{
80+
"id": "10030",
81+
"name": "Reference",
82+
"inward": "is related to",
83+
"outward": "relates to",
84+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10030"
85+
},
86+
{
87+
"id": "12310050",
88+
"name": "Regression",
89+
"inward": "is broken by",
90+
"outward": "breaks",
91+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310050"
92+
},
93+
{
94+
"id": "12310260",
95+
"name": "Related",
96+
"inward": "is related to",
97+
"outward": "relates to",
98+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310260"
99+
},
100+
{
101+
"id": "12310040",
102+
"name": "Required",
103+
"inward": "is required by",
104+
"outward": "requires",
105+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310040"
106+
},
107+
{
108+
"id": "12310051",
109+
"name": "Supercedes",
110+
"inward": "is superceded by",
111+
"outward": "supercedes",
112+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310051"
113+
},
114+
{
115+
"id": "10001",
116+
"name": "dependent",
117+
"inward": "is depended upon by",
118+
"outward": "depends upon",
119+
"self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10001"
120+
}
121+
]

0 commit comments

Comments
 (0)