Skip to content

Commit b2766e3

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

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

cloud/issue.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,36 @@ 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, options ...func(*http.Request) error) 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+
for _, option := range options {
973+
err = option(req)
974+
if err != nil {
975+
return err
976+
}
977+
}
978+
979+
resp, err := s.client.Do(req, nil)
980+
if err != nil {
981+
jerr := NewJiraError(resp, err)
982+
return jerr
983+
}
984+
defer resp.Body.Close()
985+
986+
return nil
987+
}
988+
959989
// AddWorklogRecord adds a new worklog record to issueID.
960990
//
961991
// 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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,36 @@ 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, options ...func(*http.Request) error) 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+
for _, option := range options {
972+
err = option(req)
973+
if err != nil {
974+
return err
975+
}
976+
}
977+
978+
resp, err := s.client.Do(req, nil)
979+
if err != nil {
980+
jerr := NewJiraError(resp, err)
981+
return jerr
982+
}
983+
defer resp.Body.Close()
984+
985+
return nil
986+
}
987+
958988
// AddWorklogRecord adds a new worklog record to issueID.
959989
//
960990
// 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)