From f200e158b997a303db081cbbc5a9d8ad5d89566d Mon Sep 17 00:00:00 2001 From: mehanizm Date: Mon, 16 Mar 2020 11:10:28 +0300 Subject: [PATCH] feat: add AddRemoteLink method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit – 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 --- issue.go | 20 ++++++++++++++++++++ issue_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/issue.go b/issue.go index f53cb136..46ad8494 100644 --- a/issue.go +++ b/issue.go @@ -1343,3 +1343,23 @@ func (s *IssueService) GetRemoteLinks(id string) (*[]RemoteLink, *Response, erro } return result, resp, err } + +// AddRemoteLink adds a remote link to issueID. +// +// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-remotelink-post +func (s *IssueService) AddRemoteLink(issueID string, remotelink *RemoteLink) (*RemoteLink, *Response, error) { + apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/remotelink", issueID) + req, err := s.client.NewRequest("POST", apiEndpoint, remotelink) + if err != nil { + return nil, nil, err + } + + responseRemotelink := new(RemoteLink) + resp, err := s.client.Do(req, responseRemotelink) + if err != nil { + jerr := NewJiraError(resp, err) + return nil, resp, jerr + } + + return responseRemotelink, resp, nil +} diff --git a/issue_test.go b/issue_test.go index 83f720fe..a7c15655 100644 --- a/issue_test.go +++ b/issue_test.go @@ -1755,3 +1755,47 @@ func TestIssueService_GetRemoteLinks(t *testing.T) { t.Errorf("First remote link object status should be resolved") } } + +func TestIssueService_AddRemoteLink(t *testing.T) { + setup() + defer teardown() + testMux.HandleFunc("/rest/api/2/issue/10000/remotelink", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testRequestURL(t, r, "/rest/api/2/issue/10000/remotelink") + + w.WriteHeader(http.StatusCreated) + fmt.Fprint(w, `{"id": 10000, "self": "https://your-domain.atlassian.net/rest/api/issue/MKY-1/remotelink/10000"}`) + }) + r := &RemoteLink{ + Application: &RemoteLinkApplication{ + Name: "My Acme Tracker", + Type: "com.acme.tracker", + }, + GlobalID: "system=http://www.mycompany.com/support&id=1", + Relationship: "causes", + Object: &RemoteLinkObject{ + Summary: "Customer support issue", + Icon: &RemoteLinkIcon{ + Url16x16: "http://www.mycompany.com/support/ticket.png", + Title: "Support Ticket", + }, + Title: "TSTSUP-111", + URL: "http://www.mycompany.com/support?id=1", + Status: &RemoteLinkStatus{ + Icon: &RemoteLinkIcon{ + Url16x16: "http://www.mycompany.com/support/resolved.png", + Title: "Case Closed", + Link: "http://www.mycompany.com/support?id=1&details=closed", + }, + Resolved: true, + }, + }, + } + record, _, err := testClient.Issue.AddRemoteLink("10000", r) + if record == nil { + t.Error("Expected Record. Record is nil") + } + if err != nil { + t.Errorf("Error given: %s", err) + } +}