Skip to content

Commit

Permalink
Merge pull request #411 from madest92/update-remotelink
Browse files Browse the repository at this point in the history
  • Loading branch information
benjivesterby committed Jan 20, 2022
2 parents f558a51 + 81ff215 commit 4b63320
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
24 changes: 24 additions & 0 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
40 changes: 40 additions & 0 deletions issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4b63320

Please sign in to comment.