-
Notifications
You must be signed in to change notification settings - Fork 29
/
issueLinkType.go
169 lines (127 loc) · 4.88 KB
/
issueLinkType.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package jira
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
type IssueLinkTypeService struct{ client *Client }
type IssueLinkTypeSearchScheme struct {
IssueLinkTypes []*LinkTypeScheme `json:"issueLinkTypes,omitempty"`
}
type IssueLinkTypeScheme struct {
ID string `json:"id"`
Name string `json:"name"`
Inward string `json:"inward"`
Outward string `json:"outward"`
Self string `json:"self"`
}
// Returns a list of all issue link types.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/link/types#get-issue-link-types
func (i *IssueLinkTypeService) Gets(ctx context.Context) (result *IssueLinkTypeSearchScheme, response *Response, err error) {
var endpoint = "rest/api/3/issueLinkType"
request, err := i.client.newRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
response, err = i.client.Do(request)
if err != nil {
return
}
result = new(IssueLinkTypeSearchScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return nil, response, fmt.Errorf("unable to marshall the response body, error: %v", err.Error())
}
return
}
// Returns an issue link type.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/link/types#get-issue-link-type
func (i *IssueLinkTypeService) Get(ctx context.Context, issueLinkTypeID string) (result *LinkTypeScheme, response *Response, err error) {
if len(issueLinkTypeID) == 0 {
return nil, nil, fmt.Errorf("error!, please provide a valid issueLinkTypeID value")
}
var endpoint = fmt.Sprintf("rest/api/3/issueLinkType/%v", issueLinkTypeID)
request, err := i.client.newRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
response, err = i.client.Do(request)
if err != nil {
return
}
result = new(LinkTypeScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return nil, response, fmt.Errorf("unable to marshall the response body, error: %v", err.Error())
}
return
}
// Creates an issue link type.
// Use this operation to create descriptions of the reasons why issues are linked.
// The issue link type consists of a name and descriptions for a link's inward and outward relationships.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/link/types#create-issue-link-type
func (i *IssueLinkTypeService) Create(ctx context.Context, payload *LinkTypeScheme) (result *LinkTypeScheme, response *Response, err error) {
if payload == nil {
return nil, nil, fmt.Errorf("error, payload value is nil, please provide a valid IssueLinkTypePayloadScheme pointer")
}
var endpoint = "rest/api/3/issueLinkType"
request, err := i.client.newRequest(ctx, http.MethodPost, endpoint, &payload)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json")
response, err = i.client.Do(request)
if err != nil {
return
}
result = new(LinkTypeScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return nil, response, fmt.Errorf("unable to marshall the response body, error: %v", err.Error())
}
return
}
// Updates an issue link type.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/link/types#update-issue-link-type
func (i *IssueLinkTypeService) Update(ctx context.Context, issueLinkTypeID string, payload *LinkTypeScheme) (result *LinkTypeScheme, response *Response, err error) {
if len(issueLinkTypeID) == 0 {
return nil, nil, fmt.Errorf("error!, please provide a valid issueLinkTypeID value")
}
if payload == nil {
return nil, nil, fmt.Errorf("error, payload value is nil, please provide a valid IssueLinkTypePayloadScheme pointer")
}
var endpoint = fmt.Sprintf("rest/api/3/issueLinkType/%v", issueLinkTypeID)
request, err := i.client.newRequest(ctx, http.MethodPut, endpoint, &payload)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json")
response, err = i.client.Do(request)
if err != nil {
return
}
result = new(LinkTypeScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return nil, response, fmt.Errorf("unable to marshall the response body, error: %v", err.Error())
}
return
}
// Deletes an issue link type.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/issues/link/types#delete-issue-link-type
func (i *IssueLinkTypeService) Delete(ctx context.Context, issueLinkTypeID string) (response *Response, err error) {
if len(issueLinkTypeID) == 0 {
return nil, fmt.Errorf("error!, please provide a valid issueLinkTypeID value")
}
var endpoint = fmt.Sprintf("rest/api/3/issueLinkType/%v", issueLinkTypeID)
request, err := i.client.newRequest(ctx, http.MethodDelete, endpoint, nil)
if err != nil {
return
}
response, err = i.client.Do(request)
if err != nil {
return
}
return
}