Skip to content

Commit

Permalink
feat: add AddRemoteLink method
Browse files Browse the repository at this point in the history
  – 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
  • Loading branch information
mehanizm authored and ghostsquad committed Apr 10, 2020
1 parent 19d3fc0 commit f200e15
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
20 changes: 20 additions & 0 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
44 changes: 44 additions & 0 deletions issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit f200e15

Please sign in to comment.