forked from ctreminiom/go-atlassian
/
link_impl_rich_text.go
129 lines (101 loc) · 3.76 KB
/
link_impl_rich_text.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
package internal
import (
"context"
"fmt"
model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service"
"github.com/ctreminiom/go-atlassian/service/jira"
"net/http"
)
type LinkRichTextService struct {
internalClient jira.LinkRichTextConnector
Type *LinkTypeService
Remote *RemoteLinkService
}
type internalLinkRichTextServiceImpl struct {
c service.Connector
version string
}
// Get returns an issue link.
//
// GET /rest/api/{2-3}/issueLink/{linkId}
//
// https://docs.go-atlassian.io/jira-software-cloud/issues/link#get-issue-link
func (l *LinkRichTextService) Get(ctx context.Context, linkId string) (*model.IssueLinkScheme, *model.ResponseScheme, error) {
return l.internalClient.Get(ctx, linkId)
}
// Gets get the issue links ID's associated with a Jira Issue
//
// https://docs.go-atlassian.io/jira-software-cloud/issues/link#get-issue-links
func (l *LinkRichTextService) Gets(ctx context.Context, issueKeyOrId string) (*model.IssueLinkPageScheme, *model.ResponseScheme, error) {
return l.internalClient.Gets(ctx, issueKeyOrId)
}
// Delete deletes an issue link.
//
// DELETE /rest/api/{2-3}/issueLink/{linkId}
//
// https://docs.go-atlassian.io/jira-software-cloud/issues/link#delete-issue-link
func (l *LinkRichTextService) Delete(ctx context.Context, linkId string) (*model.ResponseScheme, error) {
return l.internalClient.Delete(ctx, linkId)
}
// Create creates a link between two issues. Use this operation to indicate a relationship between two issues
//
// and optionally add a comment to the from (outward) issue.
//
// To use this resource the site must have Issue Linking enabled.
//
// https://docs.go-atlassian.io/jira-software-cloud/issues/link#create-issue-link
func (l *LinkRichTextService) Create(ctx context.Context, payload *model.LinkPayloadSchemeV2) (*model.ResponseScheme, error) {
return l.internalClient.Create(ctx, payload)
}
func (i *internalLinkRichTextServiceImpl) Get(ctx context.Context, linkId string) (*model.IssueLinkScheme, *model.ResponseScheme, error) {
if linkId == "" {
return nil, nil, model.ErrNoTypeIDError
}
endpoint := fmt.Sprintf("rest/api/%v/issueLink/%v", i.version, linkId)
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil)
if err != nil {
return nil, nil, err
}
link := new(model.IssueLinkScheme)
response, err := i.c.Call(request, link)
if err != nil {
return nil, response, err
}
return link, response, nil
}
func (i *internalLinkRichTextServiceImpl) Gets(ctx context.Context, issueKeyOrId string) (*model.IssueLinkPageScheme, *model.ResponseScheme, error) {
if len(issueKeyOrId) == 0 {
return nil, nil, model.ErrNoIssueKeyOrIDError
}
endpoint := fmt.Sprintf("rest/api/%v/issue/%v?fields=issuelinks", i.version, issueKeyOrId)
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil)
if err != nil {
return nil, nil, err
}
links := new(model.IssueLinkPageScheme)
response, err := i.c.Call(request, links)
if err != nil {
return nil, response, err
}
return links, response, nil
}
func (i *internalLinkRichTextServiceImpl) Delete(ctx context.Context, linkId string) (*model.ResponseScheme, error) {
if linkId == "" {
return nil, model.ErrNoTypeIDError
}
endpoint := fmt.Sprintf("rest/api/%v/issueLink/%v", i.version, linkId)
request, err := i.c.NewRequest(ctx, http.MethodDelete, endpoint, "", nil)
if err != nil {
return nil, err
}
return i.c.Call(request, nil)
}
func (i *internalLinkRichTextServiceImpl) Create(ctx context.Context, payload *model.LinkPayloadSchemeV2) (*model.ResponseScheme, error) {
endpoint := fmt.Sprintf("rest/api/%v/issueLink", i.version)
request, err := i.c.NewRequest(ctx, http.MethodPost, endpoint, "", payload)
if err != nil {
return nil, err
}
return i.c.Call(request, nil)
}