diff --git a/issue.go b/issue.go index 3e898d70..5c6c8822 100644 --- a/issue.go +++ b/issue.go @@ -1531,3 +1531,27 @@ func (s *IssueService) AddRemoteLinkWithContext(ctx context.Context, issueID str func (s *IssueService) AddRemoteLink(issueID string, remotelink *RemoteLink) (*RemoteLink, *Response, error) { return s.AddRemoteLinkWithContext(context.Background(), issueID, remotelink) } + +// UpdateRemoteLinkWithContext updates a remote issue link by linkID. +// +// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-remote-links/#api-rest-api-2-issue-issueidorkey-remotelink-linkid-put +func (s *IssueService) UpdateRemoteLinkWithContext(ctx context.Context, issueID string, linkID int, remotelink *RemoteLink) (*Response, error) { + apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/remotelink/%d", issueID, linkID) + req, err := s.client.NewRequestWithContext(ctx, "PUT", apiEndpoint, remotelink) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req, nil) + if err != nil { + jerr := NewJiraError(resp, err) + return resp, jerr + } + + return resp, nil +} + +// UpdateRemoteLink wraps UpdateRemoteLinkWithContext using the background context. +func (s *IssueService) UpdateRemoteLink(issueID string, linkID int, remotelink *RemoteLink) (*Response, error) { + return s.UpdateRemoteLinkWithContext(context.Background(), issueID, linkID, remotelink) +} diff --git a/issue_test.go b/issue_test.go index 6664478f..64f4fa29 100644 --- a/issue_test.go +++ b/issue_test.go @@ -1855,6 +1855,46 @@ func TestIssueService_AddRemoteLink(t *testing.T) { } } +func TestIssueService_UpdateRemoteLink(t *testing.T) { + setup() + defer teardown() + testMux.HandleFunc("/rest/api/2/issue/100/remotelink/200", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + testRequestURL(t, r, "/rest/api/2/issue/100/remotelink/200") + + w.WriteHeader(http.StatusNoContent) + }) + 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, + }, + }, + } + _, err := testClient.Issue.UpdateRemoteLink("100", 200, r) + if err != nil { + t.Errorf("Error given: %s", err) + } +} + func TestTime_MarshalJSON(t *testing.T) { timeFormatParseFrom := "2006-01-02T15:04:05.999Z" testCases := []struct {