mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-09-16 09:06:19 +02:00
feat: add AddRemoteLink method
– 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
This commit is contained in:
20
issue.go
20
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
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user