Skip to content

Commit bb64ef0

Browse files
committed
feat: Add IssueService.DeleteWorklogRecord
1 parent 2aa3adf commit bb64ef0

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

cloud/issue.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,29 @@ func (s *IssueService) DeleteComment(ctx context.Context, issueID, commentID str
956956
return nil
957957
}
958958

959+
// DeleteWorklogRecord Deletes a work log from an issueID.
960+
//
961+
// 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
962+
//
963+
// TODO Double check this method if this works as expected, is using the latest API and the response is complete
964+
// This double check effort is done for v2 - Remove this two lines if this is completed.
965+
func (s *IssueService) DeleteWorklogRecord(ctx context.Context, issueID, worklogID string) error {
966+
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/worklog/%s", issueID, worklogID)
967+
req, err := s.client.NewRequest(ctx, http.MethodDelete, apiEndpoint, nil)
968+
if err != nil {
969+
return err
970+
}
971+
972+
resp, err := s.client.Do(req, nil)
973+
if err != nil {
974+
jerr := NewJiraError(resp, err)
975+
return jerr
976+
}
977+
defer resp.Body.Close()
978+
979+
return nil
980+
}
981+
959982
// AddWorklogRecord adds a new worklog record to issueID.
960983
//
961984
// https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-worklog-post

cloud/issue_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,23 @@ func TestIssueService_DeleteComment(t *testing.T) {
250250
}
251251
}
252252

253+
func TestIssueService_DeleteWorklogRecord(t *testing.T) {
254+
setup()
255+
defer teardown()
256+
testMux.HandleFunc("/rest/api/2/issue/10000/worklog/10001", func(w http.ResponseWriter, r *http.Request) {
257+
testMethod(t, r, http.MethodDelete)
258+
testRequestURL(t, r, "/rest/api/2/issue/10000/worklog/10001")
259+
260+
w.WriteHeader(http.StatusNoContent)
261+
fmt.Fprint(w, `{}`)
262+
})
263+
264+
err := testClient.Issue.DeleteWorklogRecord(context.Background(), "10000", "10001")
265+
if err != nil {
266+
t.Errorf("Error given: %s", err)
267+
}
268+
}
269+
253270
func TestIssueService_AddWorklogRecord(t *testing.T) {
254271
setup()
255272
defer teardown()

onpremise/issue.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,29 @@ func (s *IssueService) DeleteComment(ctx context.Context, issueID, commentID str
955955
return nil
956956
}
957957

958+
// DeleteWorklogRecord Deletes a work log from an issueID.
959+
//
960+
// 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
961+
//
962+
// TODO Double check this method if this works as expected, is using the latest API and the response is complete
963+
// This double check effort is done for v2 - Remove this two lines if this is completed.
964+
func (s *IssueService) DeleteWorklogRecord(ctx context.Context, issueID, worklogID string) error {
965+
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/worklog/%s", issueID, worklogID)
966+
req, err := s.client.NewRequest(ctx, http.MethodDelete, apiEndpoint, nil)
967+
if err != nil {
968+
return err
969+
}
970+
971+
resp, err := s.client.Do(req, nil)
972+
if err != nil {
973+
jerr := NewJiraError(resp, err)
974+
return jerr
975+
}
976+
defer resp.Body.Close()
977+
978+
return nil
979+
}
980+
958981
// AddWorklogRecord adds a new worklog record to issueID.
959982
//
960983
// https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-worklog-post

onpremise/issue_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,23 @@ func TestIssueService_DeleteComment(t *testing.T) {
250250
}
251251
}
252252

253+
func TestIssueService_DeleteWorklogRecord(t *testing.T) {
254+
setup()
255+
defer teardown()
256+
testMux.HandleFunc("/rest/api/2/issue/10000/worklog/10001", func(w http.ResponseWriter, r *http.Request) {
257+
testMethod(t, r, http.MethodDelete)
258+
testRequestURL(t, r, "/rest/api/2/issue/10000/worklog/10001")
259+
260+
w.WriteHeader(http.StatusNoContent)
261+
fmt.Fprint(w, `{}`)
262+
})
263+
264+
err := testClient.Issue.DeleteWorklogRecord(context.Background(), "10000", "10001")
265+
if err != nil {
266+
t.Errorf("Error given: %s", err)
267+
}
268+
}
269+
253270
func TestIssueService_AddWorklogRecord(t *testing.T) {
254271
setup()
255272
defer teardown()

0 commit comments

Comments
 (0)