Skip to content

Commit

Permalink
Feature: Implement delete issue link api (andygrunwald#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadsalimi authored Feb 6, 2021
1 parent 524ede3 commit 5601d2b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
23 changes: 23 additions & 0 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,29 @@ func (s *IssueService) DeleteAttachment(attachmentID string) (*Response, error)
return s.DeleteAttachmentWithContext(context.Background(), attachmentID)
}

// DeleteLinkWithContext deletes a link of a given linkID
func (s *IssueService) DeleteLinkWithContext(ctx context.Context, linkID string) (*Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issueLink/%s", linkID)

req, err := s.client.NewRequestWithContext(ctx, "DELETE", apiEndpoint, nil)
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
}

// DeleteLink wraps DeleteLinkWithContext using the background context.
func (s *IssueService) DeleteLink(linkID string) (*Response, error) {
return s.DeleteLinkWithContext(context.Background(), linkID)
}

// GetWorklogsWithContext gets all the worklogs for an issue.
// This method is especially important if you need to read all the worklogs, not just the first page.
//
Expand Down
27 changes: 27 additions & 0 deletions issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,33 @@ func TestIssueService_DeleteAttachment(t *testing.T) {
}
}

func TestIssueService_DeleteLink(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issueLink/10054", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testRequestURL(t, r, "/rest/api/2/issueLink/10054")

w.WriteHeader(http.StatusNoContent)
fmt.Fprint(w, `{}`)
})

resp, err := testClient.Issue.DeleteLink("10054")
if resp.StatusCode != 204 {
t.Error("Expected link not deleted.")
if resp.StatusCode == 403 {
t.Error("User not permitted to delete link")
}
if resp.StatusCode == 404 {
t.Error("Link not found")
}
}

if err != nil {
t.Errorf("Error given: %s", err)
}
}

func TestIssueService_Search(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 5601d2b

Please sign in to comment.