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

feat: Add IssueService.DeleteWorklogRecord #683

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions cloud/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,36 @@ func (s *IssueService) DeleteComment(ctx context.Context, issueID, commentID str
return nil
}

// DeleteWorklogRecord Deletes a work log from an issueID.
//
// Jira API docs:https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-issue-issueidorkey-worklog-id-delete
//
// TODO Double check this method if this works as expected, is using the latest API and the response is complete
// This double check effort is done for v2 - Remove this two lines if this is completed.
func (s *IssueService) DeleteWorklogRecord(ctx context.Context, issueID, worklogID string, options ...func(*http.Request) error) error {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/worklog/%s", issueID, worklogID)
req, err := s.client.NewRequest(ctx, http.MethodDelete, apiEndpoint, nil)
if err != nil {
return err
}

for _, option := range options {
err = option(req)
if err != nil {
return err
}
}

resp, err := s.client.Do(req, nil)
if err != nil {
jerr := NewJiraError(resp, err)
return jerr
}
defer resp.Body.Close()

return nil
}

// AddWorklogRecord adds a new worklog record to issueID.
//
// https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-worklog-post
Expand Down
17 changes: 17 additions & 0 deletions cloud/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ func TestIssueService_DeleteComment(t *testing.T) {
}
}

func TestIssueService_DeleteWorklogRecord(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issue/10000/worklog/10001", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
testRequestURL(t, r, "/rest/api/2/issue/10000/worklog/10001")

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

err := testClient.Issue.DeleteWorklogRecord(context.Background(), "10000", "10001")
if err != nil {
t.Errorf("Error given: %s", err)
}
}

func TestIssueService_AddWorklogRecord(t *testing.T) {
setup()
defer teardown()
Expand Down
30 changes: 30 additions & 0 deletions onpremise/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,36 @@ func (s *IssueService) DeleteComment(ctx context.Context, issueID, commentID str
return nil
}

// DeleteWorklogRecord Deletes a work log from an issueID.
//
// Jira API docs:https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-issue-issueidorkey-worklog-id-delete
//
// TODO Double check this method if this works as expected, is using the latest API and the response is complete
// This double check effort is done for v2 - Remove this two lines if this is completed.
func (s *IssueService) DeleteWorklogRecord(ctx context.Context, issueID, worklogID string, options ...func(*http.Request) error) error {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/worklog/%s", issueID, worklogID)
req, err := s.client.NewRequest(ctx, http.MethodDelete, apiEndpoint, nil)
if err != nil {
return err
}

for _, option := range options {
err = option(req)
if err != nil {
return err
}
}

resp, err := s.client.Do(req, nil)
if err != nil {
jerr := NewJiraError(resp, err)
return jerr
}
defer resp.Body.Close()

return nil
}

// AddWorklogRecord adds a new worklog record to issueID.
//
// https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-worklog-post
Expand Down
17 changes: 17 additions & 0 deletions onpremise/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ func TestIssueService_DeleteComment(t *testing.T) {
}
}

func TestIssueService_DeleteWorklogRecord(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issue/10000/worklog/10001", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
testRequestURL(t, r, "/rest/api/2/issue/10000/worklog/10001")

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

err := testClient.Issue.DeleteWorklogRecord(context.Background(), "10000", "10001")
if err != nil {
t.Errorf("Error given: %s", err)
}
}

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