Skip to content

Commit

Permalink
feat: Add IssueService.DeleteWorklogRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Aug 27, 2024
1 parent 2aa3adf commit b2766e3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
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

0 comments on commit b2766e3

Please sign in to comment.