Skip to content

Commit f200e15

Browse files
mehanizmghostsquad
authored andcommitted
feat: add AddRemoteLink method
– add method AddRemoteLink to add remote links to issue - add test for the method See docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-remotelink-post
1 parent 19d3fc0 commit f200e15

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

issue.go

+20
Original file line numberDiff line numberDiff line change
@@ -1343,3 +1343,23 @@ func (s *IssueService) GetRemoteLinks(id string) (*[]RemoteLink, *Response, erro
13431343
}
13441344
return result, resp, err
13451345
}
1346+
1347+
// AddRemoteLink adds a remote link to issueID.
1348+
//
1349+
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-remotelink-post
1350+
func (s *IssueService) AddRemoteLink(issueID string, remotelink *RemoteLink) (*RemoteLink, *Response, error) {
1351+
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/remotelink", issueID)
1352+
req, err := s.client.NewRequest("POST", apiEndpoint, remotelink)
1353+
if err != nil {
1354+
return nil, nil, err
1355+
}
1356+
1357+
responseRemotelink := new(RemoteLink)
1358+
resp, err := s.client.Do(req, responseRemotelink)
1359+
if err != nil {
1360+
jerr := NewJiraError(resp, err)
1361+
return nil, resp, jerr
1362+
}
1363+
1364+
return responseRemotelink, resp, nil
1365+
}

issue_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -1755,3 +1755,47 @@ func TestIssueService_GetRemoteLinks(t *testing.T) {
17551755
t.Errorf("First remote link object status should be resolved")
17561756
}
17571757
}
1758+
1759+
func TestIssueService_AddRemoteLink(t *testing.T) {
1760+
setup()
1761+
defer teardown()
1762+
testMux.HandleFunc("/rest/api/2/issue/10000/remotelink", func(w http.ResponseWriter, r *http.Request) {
1763+
testMethod(t, r, "POST")
1764+
testRequestURL(t, r, "/rest/api/2/issue/10000/remotelink")
1765+
1766+
w.WriteHeader(http.StatusCreated)
1767+
fmt.Fprint(w, `{"id": 10000, "self": "https://your-domain.atlassian.net/rest/api/issue/MKY-1/remotelink/10000"}`)
1768+
})
1769+
r := &RemoteLink{
1770+
Application: &RemoteLinkApplication{
1771+
Name: "My Acme Tracker",
1772+
Type: "com.acme.tracker",
1773+
},
1774+
GlobalID: "system=http://www.mycompany.com/support&id=1",
1775+
Relationship: "causes",
1776+
Object: &RemoteLinkObject{
1777+
Summary: "Customer support issue",
1778+
Icon: &RemoteLinkIcon{
1779+
Url16x16: "http://www.mycompany.com/support/ticket.png",
1780+
Title: "Support Ticket",
1781+
},
1782+
Title: "TSTSUP-111",
1783+
URL: "http://www.mycompany.com/support?id=1",
1784+
Status: &RemoteLinkStatus{
1785+
Icon: &RemoteLinkIcon{
1786+
Url16x16: "http://www.mycompany.com/support/resolved.png",
1787+
Title: "Case Closed",
1788+
Link: "http://www.mycompany.com/support?id=1&details=closed",
1789+
},
1790+
Resolved: true,
1791+
},
1792+
},
1793+
}
1794+
record, _, err := testClient.Issue.AddRemoteLink("10000", r)
1795+
if record == nil {
1796+
t.Error("Expected Record. Record is nil")
1797+
}
1798+
if err != nil {
1799+
t.Errorf("Error given: %s", err)
1800+
}
1801+
}

0 commit comments

Comments
 (0)