Skip to content

Commit 9ff562a

Browse files
prugalaghostsquad
authored andcommitted
feat: add worklog update method
Allows updating work log entries API reference url: https://docs.atlassian.com/software/jira/docs/api/REST/7.1.2/#api/2/issue-updateWorklog
1 parent 7530b7c commit 9ff562a

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

issue.go

+27
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,33 @@ func (s *IssueService) AddWorklogRecord(issueID string, record *WorklogRecord, o
868868
return responseRecord, resp, nil
869869
}
870870

871+
// UpdateWorklogRecord updates a worklog record.
872+
//
873+
// https://docs.atlassian.com/software/jira/docs/api/REST/7.1.2/#api/2/issue-updateWorklog
874+
func (s *IssueService) UpdateWorklogRecord(issueID, worklogID string, record *WorklogRecord, options ...func(*http.Request) error) (*WorklogRecord, *Response, error) {
875+
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/worklog/%s", issueID, worklogID)
876+
req, err := s.client.NewRequest("PUT", apiEndpoint, record)
877+
if err != nil {
878+
return nil, nil, err
879+
}
880+
881+
for _, option := range options {
882+
err = option(req)
883+
if err != nil {
884+
return nil, nil, err
885+
}
886+
}
887+
888+
responseRecord := new(WorklogRecord)
889+
resp, err := s.client.Do(req, responseRecord)
890+
if err != nil {
891+
jerr := NewJiraError(resp, err)
892+
return nil, resp, jerr
893+
}
894+
895+
return responseRecord, resp, nil
896+
}
897+
871898
// AddLink adds a link between two issues.
872899
//
873900
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/issueLink

issue_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,28 @@ func TestIssueService_AddWorklogRecord(t *testing.T) {
272272
}
273273
}
274274

275+
func TestIssueService_UpdateWorklogRecord(t *testing.T) {
276+
setup()
277+
defer teardown()
278+
testMux.HandleFunc("/rest/api/2/issue/10000/worklog/1", func(w http.ResponseWriter, r *http.Request) {
279+
testMethod(t, r, "PUT")
280+
testRequestURL(t, r, "/rest/api/2/issue/10000/worklog/1")
281+
282+
w.WriteHeader(http.StatusOK)
283+
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"}`)
284+
})
285+
r := &WorklogRecord{
286+
TimeSpent: "1h",
287+
}
288+
record, _, err := testClient.Issue.UpdateWorklogRecord("10000", "1", r)
289+
if record == nil {
290+
t.Error("Expected Record. Record is nil")
291+
}
292+
if err != nil {
293+
t.Errorf("Error given: %s", err)
294+
}
295+
}
296+
275297
func TestIssueService_AddLink(t *testing.T) {
276298
setup()
277299
defer teardown()

0 commit comments

Comments
 (0)