Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New issue method: update remote issue link by ID #411

Merged
merged 1 commit into from Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions issue.go
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
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