/
issue_impl.go
171 lines (136 loc) · 5.04 KB
/
issue_impl.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
170
171
package internal
import (
"context"
"fmt"
model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service"
"net/http"
"net/url"
)
type IssueServices struct {
Attachment *IssueAttachmentService
CommentRT *CommentRichTextService
CommentADF *CommentADFService
Field *IssueFieldService
Label *LabelService
LinkRT *LinkRichTextService
LinkADF *LinkADFService
Metadata *MetadataService
Priority *PriorityService
Resolution *ResolutionService
SearchRT *SearchRichTextService
SearchADF *SearchADFService
Type *TypeService
Vote *VoteService
Watcher *WatcherService
WorklogAdf *WorklogADFService
WorklogRichText *WorklogRichTextService
Property *IssuePropertyService
}
func NewIssueService(client service.Connector, version string, services *IssueServices) (*IssueRichTextService, *IssueADFService, error) {
if version == "" {
return nil, nil, model.ErrNoVersionProvided
}
richTextService := &IssueRichTextService{
internalClient: &internalRichTextServiceImpl{
c: client,
version: version,
},
}
adfService := &IssueADFService{
internalClient: &internalIssueADFServiceImpl{
c: client,
version: version,
},
}
if services != nil {
adfService.Attachment = services.Attachment
adfService.Comment = services.CommentADF
adfService.Field = services.Field
adfService.Label = services.Label
adfService.Link = services.LinkADF
adfService.Metadata = services.Metadata
adfService.Priority = services.Priority
adfService.Resolution = services.Resolution
adfService.Search = services.SearchADF
adfService.Type = services.Type
adfService.Vote = services.Vote
adfService.Watcher = services.Watcher
adfService.Worklog = services.WorklogAdf
adfService.Property = services.Property
richTextService.Comment = services.CommentRT
richTextService.Attachment = services.Attachment
richTextService.Field = services.Field
richTextService.Label = services.Label
richTextService.Link = services.LinkRT
richTextService.Metadata = services.Metadata
richTextService.Priority = services.Priority
richTextService.Resolution = services.Resolution
richTextService.Search = services.SearchRT
richTextService.Type = services.Type
richTextService.Vote = services.Vote
richTextService.Watcher = services.Watcher
richTextService.Worklog = services.WorklogRichText
richTextService.Property = services.Property
}
return richTextService, adfService, nil
}
// -------------------------------------------
// These private functions are used on the Issue Services implementation, as that services is segmented in the ADF and Rich Text
// format, in order to avoid duplication, those function are injected on the ADF/Rich Text implementations.
// -------------------------------------------
func deleteIssue(ctx context.Context, client service.Connector, version, issueKeyOrId string, deleteSubTasks bool) (*model.ResponseScheme, error) {
if issueKeyOrId == "" {
return nil, model.ErrNoIssueKeyOrIDError
}
params := url.Values{}
params.Add("deleteSubtasks", fmt.Sprintf("%v", deleteSubTasks))
endpoint := fmt.Sprintf("rest/api/%v/issue/%v?%v", version, issueKeyOrId, params.Encode())
request, err := client.NewRequest(ctx, http.MethodDelete, endpoint, "", nil)
if err != nil {
return nil, err
}
return client.Call(request, nil)
}
func assignIssue(ctx context.Context, client service.Connector, version, issueKeyOrID, accountID string) (*model.ResponseScheme, error) {
if issueKeyOrID == "" {
return nil, model.ErrNoIssueKeyOrIDError
}
if accountID == "" {
return nil, model.ErrNoAccountIDError
}
endpoint := fmt.Sprintf("/rest/api/%v/issue/%v/assignee", version, issueKeyOrID)
request, err := client.NewRequest(ctx, http.MethodPut, endpoint, "", map[string]interface{}{"accountId": accountID})
if err != nil {
return nil, err
}
return client.Call(request, nil)
}
func sendNotification(ctx context.Context, client service.Connector, version, issueKeyOrId string, options *model.IssueNotifyOptionsScheme) (
*model.ResponseScheme, error) {
if issueKeyOrId == "" {
return nil, model.ErrNoIssueKeyOrIDError
}
endpoint := fmt.Sprintf("rest/api/%v/issue/%v/notify", version, issueKeyOrId)
request, err := client.NewRequest(ctx, http.MethodPost, endpoint, "", options)
if err != nil {
return nil, err
}
return client.Call(request, nil)
}
func getTransitions(ctx context.Context, client service.Connector, version, issueKeyOrId string) (*model.IssueTransitionsScheme, *model.ResponseScheme, error) {
if issueKeyOrId == "" {
return nil, nil, model.ErrNoIssueKeyOrIDError
}
endpoint := fmt.Sprintf("rest/api/%v/issue/%v/transitions", version, issueKeyOrId)
request, err := client.NewRequest(ctx, http.MethodGet, endpoint, "", nil)
if err != nil {
return nil, nil, err
}
transitions := new(model.IssueTransitionsScheme)
response, err := client.Call(request, transitions)
if err != nil {
return nil, response, err
}
return transitions, response, nil
}