Skip to content

Commit

Permalink
feat: add worklog update method
Browse files Browse the repository at this point in the history
  • Loading branch information
prugala authored and ghostsquad committed Dec 7, 2019
1 parent 7530b7c commit 9ff562a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions issue.go
Expand Up @@ -868,6 +868,33 @@ func (s *IssueService) AddWorklogRecord(issueID string, record *WorklogRecord, o
return responseRecord, resp, nil
}

// UpdateWorklogRecord updates a worklog record.
//
// https://docs.atlassian.com/software/jira/docs/api/REST/7.1.2/#api/2/issue-updateWorklog
func (s *IssueService) UpdateWorklogRecord(issueID, worklogID string, record *WorklogRecord, options ...func(*http.Request) error) (*WorklogRecord, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/worklog/%s", issueID, worklogID)
req, err := s.client.NewRequest("PUT", apiEndpoint, record)
if err != nil {
return nil, nil, err
}

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

responseRecord := new(WorklogRecord)
resp, err := s.client.Do(req, responseRecord)
if err != nil {
jerr := NewJiraError(resp, err)
return nil, resp, jerr
}

return responseRecord, resp, nil
}

// AddLink adds a link between two issues.
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/issueLink
Expand Down
22 changes: 22 additions & 0 deletions issue_test.go
Expand Up @@ -272,6 +272,28 @@ func TestIssueService_AddWorklogRecord(t *testing.T) {
}
}

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

w.WriteHeader(http.StatusOK)
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/issue/10000/worklog/1","author":{"self":"http://www.example.com/jira/rest/api/2/user?username=fred","name":"fred","displayName":"Fred F. User","active":false},"updateAuthor":{"self":"http://www.example.com/jira/rest/api/2/user?username=fred","name":"fred","displayName":"Fred F. User","active":false},"comment":"I did some work here.","updated":"2018-02-14T22:14:46.003+0000","visibility":{"type":"group","value":"jira-developers"},"started":"2018-02-14T22:14:46.003+0000","timeSpent":"3h 20m","timeSpentSeconds":12000,"id":"100028","issueId":"10002"}`)
})
r := &WorklogRecord{
TimeSpent: "1h",
}
record, _, err := testClient.Issue.UpdateWorklogRecord("10000", "1", r)
if record == nil {
t.Error("Expected Record. Record is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}

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

0 comments on commit 9ff562a

Please sign in to comment.