1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-03-19 20:57:47 +02:00

Merge pull request #84 from guywithnose/getWorklogs

Add GetWorklogs
This commit is contained in:
Andy Grunwald 2017-11-01 16:39:58 +01:00 committed by GitHub
commit f238f400f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View File

@ -558,6 +558,23 @@ func (s *IssueService) PostAttachment(issueID string, r io.Reader, attachmentNam
return attachment, resp, nil
}
// GetWorklogs gets all the worklogs for an issue.
// This method is especially important if you need to read all the worklogs, not just the first page.
//
// https://docs.atlassian.com/jira/REST/cloud/#api/2/issue/{issueIdOrKey}/worklog-getIssueWorklog
func (s *IssueService) GetWorklogs(issueID string) (*Worklog, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/worklog", issueID)
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
v := new(Worklog)
resp, err := s.client.Do(req, v)
return v, resp, err
}
// Create creates an issue or a sub-task from a JSON representation.
// Creating a sub-task is similar to creating a regular issue, with two important differences:
// The issueType field must correspond to a sub-task issue type and you must provide a parent field in the issue create request containing the id or key of the parent issue.

View File

@ -1148,3 +1148,31 @@ func TestIssueService_Delete(t *testing.T) {
t.Errorf("Error given: %s", err)
}
}
func TestIssueService_GetWorklogs(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issue/10002/worklog", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, "/rest/api/2/issue/10002/worklog")
fmt.Fprint(w, `{"startAt": 1,"maxResults": 40,"total": 1,"worklogs": [{"id": "3","self": "http://kelpie9:8081/rest/api/2/issue/10002/worklog/3","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},"created":"2016-03-16T04:22:37.356+0000","updated":"2016-03-16T04:22:37.356+0000","comment":"","started":"2016-03-16T04:22:37.356+0000","timeSpent": "1h","timeSpentSeconds": 3600,"issueId":"10002"}]}`)
})
worklog, _, err := testClient.Issue.GetWorklogs("10002")
if worklog == nil {
t.Error("Expected worklog. Worklog is nil")
}
if len(worklog.Worklogs) != 1 {
t.Error("Expected 1 worklog")
}
if worklog.Worklogs[0].Author.Name != "fred" {
t.Error("Expected worklog author to be fred")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}