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

Feature: Implement delete issue link api #341

Merged
merged 1 commit into from
Feb 6, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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