Skip to content

Commit 5601d2b

Browse files
authored
Feature: Implement delete issue link api (#341)
1 parent 524ede3 commit 5601d2b

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

issue.go

+23
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,29 @@ func (s *IssueService) DeleteAttachment(attachmentID string) (*Response, error)
718718
return s.DeleteAttachmentWithContext(context.Background(), attachmentID)
719719
}
720720

721+
// DeleteLinkWithContext deletes a link of a given linkID
722+
func (s *IssueService) DeleteLinkWithContext(ctx context.Context, linkID string) (*Response, error) {
723+
apiEndpoint := fmt.Sprintf("rest/api/2/issueLink/%s", linkID)
724+
725+
req, err := s.client.NewRequestWithContext(ctx, "DELETE", apiEndpoint, nil)
726+
if err != nil {
727+
return nil, err
728+
}
729+
730+
resp, err := s.client.Do(req, nil)
731+
if err != nil {
732+
jerr := NewJiraError(resp, err)
733+
return resp, jerr
734+
}
735+
736+
return resp, nil
737+
}
738+
739+
// DeleteLink wraps DeleteLinkWithContext using the background context.
740+
func (s *IssueService) DeleteLink(linkID string) (*Response, error) {
741+
return s.DeleteLinkWithContext(context.Background(), linkID)
742+
}
743+
721744
// GetWorklogsWithContext gets all the worklogs for an issue.
722745
// This method is especially important if you need to read all the worklogs, not just the first page.
723746
//

issue_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,33 @@ func TestIssueService_DeleteAttachment(t *testing.T) {
589589
}
590590
}
591591

592+
func TestIssueService_DeleteLink(t *testing.T) {
593+
setup()
594+
defer teardown()
595+
testMux.HandleFunc("/rest/api/2/issueLink/10054", func(w http.ResponseWriter, r *http.Request) {
596+
testMethod(t, r, "DELETE")
597+
testRequestURL(t, r, "/rest/api/2/issueLink/10054")
598+
599+
w.WriteHeader(http.StatusNoContent)
600+
fmt.Fprint(w, `{}`)
601+
})
602+
603+
resp, err := testClient.Issue.DeleteLink("10054")
604+
if resp.StatusCode != 204 {
605+
t.Error("Expected link not deleted.")
606+
if resp.StatusCode == 403 {
607+
t.Error("User not permitted to delete link")
608+
}
609+
if resp.StatusCode == 404 {
610+
t.Error("Link not found")
611+
}
612+
}
613+
614+
if err != nil {
615+
t.Errorf("Error given: %s", err)
616+
}
617+
}
618+
592619
func TestIssueService_Search(t *testing.T) {
593620
setup()
594621
defer teardown()

0 commit comments

Comments
 (0)